update
parent
d71eb1ec02
commit
0b72623f39
14
flake.lock
14
flake.lock
|
@ -7,11 +7,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1670813451,
|
"lastModified": 1686315622,
|
||||||
"narHash": "sha256-v0IvQ35CMKtPreGlxWb1FvFUraJNZd144+MbiDwGoAA=",
|
"narHash": "sha256-ccqZqY6wUFot0ewyNKQUrMR6IEliGza+pjKoSVMXIeM=",
|
||||||
"owner": "serokell",
|
"owner": "serokell",
|
||||||
"repo": "nix-npm-buildpackage",
|
"repo": "nix-npm-buildpackage",
|
||||||
"rev": "ec0365cd14a3359a23b80a9e2531a09afc3488fc",
|
"rev": "991a792bccd611842f6bc1aa99fe80380ad68d44",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -22,10 +22,10 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1673796341,
|
"lastModified": 1707978831,
|
||||||
"narHash": "sha256-1kZi9OkukpNmOaPY7S5/+SlCDOuYnP3HkXHvNDyLQcc=",
|
"narHash": "sha256-UblFdWQ2MMZNzD9C/w8+7RjAJ2QIbebbzHUniQ/a44o=",
|
||||||
"path": "/nix/store/lzgxbh8c61phbh074y2707l2yw6vvaa1-source",
|
"path": "/nix/store/y9g7wyciqipzhay576bqdc5fr20kgi78-source",
|
||||||
"rev": "6dccdc458512abce8d19f74195bb20fdb067df50",
|
"rev": "c68a9fc85c2cb3a313be6ff40511635544dde8da",
|
||||||
"type": "path"
|
"type": "path"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
47
index.ts
47
index.ts
|
@ -11,30 +11,33 @@ import { jsonOut, csvOut, sum, runCommands, getXdgConfigHome } from "./util.js"
|
||||||
import path from "node:path"
|
import path from "node:path"
|
||||||
import repl from "node:repl"
|
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(
|
function getDecorator(
|
||||||
thing: { decorators?: Decorator[] },
|
thing: PicnicExt.Decorated,
|
||||||
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[] },
|
|
||||||
name: string,
|
name: string,
|
||||||
fallback?: R
|
fallback?: number | string
|
||||||
): R | undefined {
|
): number | string | undefined {
|
||||||
if (!thing.decorators) return fallback
|
if (!thing.decorators) return fallback
|
||||||
const l = thing.decorators.filter(x => x.type == name)
|
const j = thing.decorators as PicnicExt.ExtendedDecorator[]
|
||||||
if (l.length) {
|
const l = j.filter(x => x.type == name)
|
||||||
switch (name) {
|
if (l.length > 0 && l[0].type == name) {
|
||||||
|
switch (l[0].type) {
|
||||||
case "QUANTITY":
|
case "QUANTITY":
|
||||||
return l[0].quantity
|
return l[0].quantity
|
||||||
case "PRICE":
|
case "PRICE":
|
||||||
|
@ -62,7 +65,7 @@ function deliveryToCSV(delv: Delivery) {
|
||||||
csvOut({
|
csvOut({
|
||||||
id: orderarticle.id,
|
id: orderarticle.id,
|
||||||
name: orderarticle.name,
|
name: orderarticle.name,
|
||||||
quantity: getDecorator(orderarticle, "QUANTITY"),
|
quantity: getDecorator(orderarticle, "QUANTITY", 1),
|
||||||
price: Math.round(orderarticle.price * promo),
|
price: Math.round(orderarticle.price * promo),
|
||||||
promo: (1 - real_price / orderline.display_price).toFixed(2),
|
promo: (1 - real_price / orderline.display_price).toFixed(2),
|
||||||
unit_quantity: orderarticle.unit_quantity,
|
unit_quantity: orderarticle.unit_quantity,
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"luxon": "^3.2.1",
|
"luxon": "^3.2.1",
|
||||||
"minimist": "^1.2.7",
|
"minimist": "^1.2.7",
|
||||||
"picnic-api": "yorickvp/picnic-api#getArticle"
|
"picnic-api": "^3.0.0"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"picnic": "./bin/picnic.js"
|
"picnic": "./bin/picnic.js"
|
||||||
|
|
|
@ -598,9 +598,10 @@ path-type@^4.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
|
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
|
||||||
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==
|
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==
|
||||||
|
|
||||||
picnic-api@yorickvp/picnic-api#getArticle:
|
picnic-api@^3.0.0:
|
||||||
version "2.0.1"
|
version "3.0.0"
|
||||||
resolved "https://codeload.github.com/yorickvp/picnic-api/tar.gz/338b2ba6ab8a2c54f5778cfbe8ab71eaffcd411b"
|
resolved "https://registry.yarnpkg.com/picnic-api/-/picnic-api-3.0.0.tgz#a6277110e9667e8fe944da53a50033a404755018"
|
||||||
|
integrity sha512-5NO6t5lEzFDQ4IMtbPgtzzJTJcJ5JNmhlUleFkOeDPNdrjk9dt13S+mkPMEF605pjyPaXsTdfNLksrzQdWeuyw==
|
||||||
dependencies:
|
dependencies:
|
||||||
axios "^0.26.0"
|
axios "^0.26.0"
|
||||||
crypto-js "^4.1.1"
|
crypto-js "^4.1.1"
|
||||||
|
|
Loading…
Reference in New Issue