mirror of
https://github.com/ae-utbm/sith.git
synced 2026-03-13 15:15:03 +00:00
adapt products export to new price system
This commit is contained in:
@@ -1,13 +1,9 @@
|
|||||||
import { showSaveFilePicker } from "native-file-system-adapter";
|
import { showSaveFilePicker } from "native-file-system-adapter";
|
||||||
import type TomSelect from "tom-select";
|
import type TomSelect from "tom-select";
|
||||||
import { paginated } from "#core:utils/api.ts";
|
import { paginated } from "#core:utils/api";
|
||||||
import { csv } from "#core:utils/csv.ts";
|
import { csv } from "#core:utils/csv";
|
||||||
import {
|
import { getCurrentUrlParams, History, updateQueryString } from "#core:utils/history";
|
||||||
getCurrentUrlParams,
|
import type { NestedKeyOf } from "#core:utils/types";
|
||||||
History,
|
|
||||||
updateQueryString,
|
|
||||||
} from "#core:utils/history.ts";
|
|
||||||
import type { NestedKeyOf } from "#core:utils/types.ts";
|
|
||||||
import {
|
import {
|
||||||
type ProductSchema,
|
type ProductSchema,
|
||||||
type ProductSearchProductsDetailedData,
|
type ProductSearchProductsDetailedData,
|
||||||
@@ -20,6 +16,9 @@ type GroupedProducts = Record<ProductType, ProductSchema[]>;
|
|||||||
const defaultPageSize = 100;
|
const defaultPageSize = 100;
|
||||||
const defaultPage = 1;
|
const defaultPage = 1;
|
||||||
|
|
||||||
|
// biome-ignore lint/style/useNamingConvention: api is snake case
|
||||||
|
type ProductWithPriceSchema = ProductSchema & { selling_price: string };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keys of the properties to include in the CSV.
|
* Keys of the properties to include in the CSV.
|
||||||
*/
|
*/
|
||||||
@@ -34,7 +33,7 @@ const csvColumns = [
|
|||||||
"purchase_price",
|
"purchase_price",
|
||||||
"selling_price",
|
"selling_price",
|
||||||
"archived",
|
"archived",
|
||||||
] as NestedKeyOf<ProductSchema>[];
|
] as NestedKeyOf<ProductWithPriceSchema>[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title of the csv columns.
|
* Title of the csv columns.
|
||||||
@@ -175,7 +174,16 @@ document.addEventListener("alpine:init", () => {
|
|||||||
this.nbPages > 1
|
this.nbPages > 1
|
||||||
? await paginated(productSearchProductsDetailed, this.getQueryParams())
|
? await paginated(productSearchProductsDetailed, this.getQueryParams())
|
||||||
: Object.values<ProductSchema[]>(this.products).flat();
|
: Object.values<ProductSchema[]>(this.products).flat();
|
||||||
const content = csv.stringify(products, {
|
// CSV cannot represent nested data
|
||||||
|
// so we create a row for each price of each product.
|
||||||
|
const productsWithPrice: ProductWithPriceSchema[] = products.flatMap(
|
||||||
|
(product: ProductSchema) =>
|
||||||
|
product.prices.map((price) =>
|
||||||
|
// biome-ignore lint/style/useNamingConvention: API is snake_case
|
||||||
|
Object.assign(product, { selling_price: price.amount }),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const content = csv.stringify(productsWithPrice, {
|
||||||
columns: csvColumns,
|
columns: csvColumns,
|
||||||
titleRow: csvColumnTitles,
|
titleRow: csvColumnTitles,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -108,7 +108,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<span class="card-content">
|
<span class="card-content">
|
||||||
<strong class="card-title" x-text="`${p.name} (${p.code})`"></strong>
|
<strong class="card-title" x-text="`${p.name} (${p.code})`"></strong>
|
||||||
<p x-text="`${p.selling_price} €`"></p>
|
<p x-text="`${p.prices.map((p) => p.amount).join(' – ')} €`"></p>
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user