main
Yorick van Pelt 2024-02-25 09:26:15 +01:00
parent d71eb1ec02
commit 0b72623f39
Signed by: yorick
GPG Key ID: D8D3CC6D951384DE
4 changed files with 37 additions and 33 deletions

View File

@ -7,11 +7,11 @@
]
},
"locked": {
"lastModified": 1670813451,
"narHash": "sha256-v0IvQ35CMKtPreGlxWb1FvFUraJNZd144+MbiDwGoAA=",
"lastModified": 1686315622,
"narHash": "sha256-ccqZqY6wUFot0ewyNKQUrMR6IEliGza+pjKoSVMXIeM=",
"owner": "serokell",
"repo": "nix-npm-buildpackage",
"rev": "ec0365cd14a3359a23b80a9e2531a09afc3488fc",
"rev": "991a792bccd611842f6bc1aa99fe80380ad68d44",
"type": "github"
},
"original": {
@ -22,10 +22,10 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1673796341,
"narHash": "sha256-1kZi9OkukpNmOaPY7S5/+SlCDOuYnP3HkXHvNDyLQcc=",
"path": "/nix/store/lzgxbh8c61phbh074y2707l2yw6vvaa1-source",
"rev": "6dccdc458512abce8d19f74195bb20fdb067df50",
"lastModified": 1707978831,
"narHash": "sha256-UblFdWQ2MMZNzD9C/w8+7RjAJ2QIbebbzHUniQ/a44o=",
"path": "/nix/store/y9g7wyciqipzhay576bqdc5fr20kgi78-source",
"rev": "c68a9fc85c2cb3a313be6ff40511635544dde8da",
"type": "path"
},
"original": {

View File

@ -11,30 +11,33 @@ import { jsonOut, csvOut, sum, runCommands, getXdgConfigHome } from "./util.js"
import path from "node:path"
import repl from "node:repl"
namespace PicnicExt {
export type PromoDecorator = {
type: "PROMO";
text: string
};
export type ExtendedDecorator = Decorator | PromoDecorator
export interface Decorated {
decorators?: Decorator[]
}
}
function getDecorator(thing: PicnicExt.Decorated, name: "PROMO"): string | undefined
function getDecorator(thing: PicnicExt.Decorated, name: "QUANTITY"): number | undefined
function getDecorator(thing: PicnicExt.Decorated, name: "PRICE"): number | undefined
function getDecorator(thing: PicnicExt.Decorated, name: "PROMO", fallback: string): string
function getDecorator(thing: PicnicExt.Decorated, name: "QUANTITY", fallback: number): number
function getDecorator(thing: PicnicExt.Decorated, name: "PRICE", fallback: number): number
function getDecorator(
thing: { decorators?: Decorator[] },
name: "PROMO",
fallback?: string
): string
function getDecorator(
thing: { decorators?: Decorator[] },
name: "QUANTITY",
fallback?: number
): number
function getDecorator(
thing: { decorators?: Decorator[] },
name: "PRICE",
fallback?: number
): number
function getDecorator<R>(
thing: { decorators?: Decorator[] },
thing: PicnicExt.Decorated,
name: string,
fallback?: R
): R | undefined {
fallback?: number | string
): number | string | undefined {
if (!thing.decorators) return fallback
const l = thing.decorators.filter(x => x.type == name)
if (l.length) {
switch (name) {
const j = thing.decorators as PicnicExt.ExtendedDecorator[]
const l = j.filter(x => x.type == name)
if (l.length > 0 && l[0].type == name) {
switch (l[0].type) {
case "QUANTITY":
return l[0].quantity
case "PRICE":
@ -62,7 +65,7 @@ function deliveryToCSV(delv: Delivery) {
csvOut({
id: orderarticle.id,
name: orderarticle.name,
quantity: getDecorator(orderarticle, "QUANTITY"),
quantity: getDecorator(orderarticle, "QUANTITY", 1),
price: Math.round(orderarticle.price * promo),
promo: (1 - real_price / orderline.display_price).toFixed(2),
unit_quantity: orderarticle.unit_quantity,

View File

@ -4,7 +4,7 @@
"dependencies": {
"luxon": "^3.2.1",
"minimist": "^1.2.7",
"picnic-api": "yorickvp/picnic-api#getArticle"
"picnic-api": "^3.0.0"
},
"bin": {
"picnic": "./bin/picnic.js"

View File

@ -598,9 +598,10 @@ path-type@^4.0.0:
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==
picnic-api@yorickvp/picnic-api#getArticle:
version "2.0.1"
resolved "https://codeload.github.com/yorickvp/picnic-api/tar.gz/338b2ba6ab8a2c54f5778cfbe8ab71eaffcd411b"
picnic-api@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/picnic-api/-/picnic-api-3.0.0.tgz#a6277110e9667e8fe944da53a50033a404755018"
integrity sha512-5NO6t5lEzFDQ4IMtbPgtzzJTJcJ5JNmhlUleFkOeDPNdrjk9dt13S+mkPMEF605pjyPaXsTdfNLksrzQdWeuyw==
dependencies:
axios "^0.26.0"
crypto-js "^4.1.1"