@dascompany/product 4.2.8 → 4.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { QueryOptions } from "@dascompany/database";
|
|
2
2
|
import ProductI from "../types/ProductI";
|
|
3
3
|
export default class ProductReader {
|
|
4
|
-
static get(queryOption: QueryOptions): Promise<ProductI>;
|
|
5
|
-
static getAll(queryOption: QueryOptions): Promise<ProductI[]>;
|
|
4
|
+
static get(queryOption: QueryOptions, vat: number): Promise<ProductI>;
|
|
5
|
+
static getAll(queryOption: QueryOptions, vat: number): Promise<ProductI[]>;
|
|
6
6
|
static getId(queryOptions: QueryOptions): Promise<string>;
|
|
7
7
|
static getQuantity(queryOptions: QueryOptions): Promise<number>;
|
|
8
8
|
static getMaxPrice(queryOptions: QueryOptions): Promise<number>;
|
|
@@ -5,18 +5,18 @@ import FileConnectionTypeE from "../types/FileConnectionTypeE";
|
|
|
5
5
|
import PriceConverter from "../utils/PriceConverter";
|
|
6
6
|
import createQueryOptionsForId from "../utils/createQueryOptionsForId";
|
|
7
7
|
export default class ProductReader {
|
|
8
|
-
static async get(queryOption) {
|
|
8
|
+
static async get(queryOption, vat) {
|
|
9
9
|
const productRow = await DatabaseConnection.getInstance().products.select(queryOption);
|
|
10
10
|
const queryOptionsFiles = new QueryOptions();
|
|
11
11
|
queryOptionsFiles.setWhere([{ name: 'connection_id', type: ParameterType.bigint, value: productRow.id }, { name: 'connection_type', type: ParameterType.string, value: FileConnectionTypeE.product }]);
|
|
12
12
|
queryOptionsFiles.setOrderBy([{ key: 'sequence', order: 'asc' }]);
|
|
13
13
|
const files = await FilesReader.getForConnection(queryOptionsFiles);
|
|
14
|
-
const product = await this.correctProduct(productRow);
|
|
14
|
+
const product = await this.correctProduct(productRow, vat);
|
|
15
15
|
return { ...product, files };
|
|
16
16
|
}
|
|
17
|
-
static async getAll(queryOption) {
|
|
17
|
+
static async getAll(queryOption, vat) {
|
|
18
18
|
const products = await DatabaseConnection.getInstance().products.selectAll(queryOption);
|
|
19
|
-
return this.correctProducts(products);
|
|
19
|
+
return this.correctProducts(products, vat);
|
|
20
20
|
}
|
|
21
21
|
static async getId(queryOptions) {
|
|
22
22
|
return await DatabaseConnection.getInstance().products.selectId(queryOptions);
|
|
@@ -29,15 +29,15 @@ export default class ProductReader {
|
|
|
29
29
|
const price = await DatabaseConnection.getInstance().products.selectMaxPrice(queryOptions);
|
|
30
30
|
return Number(price);
|
|
31
31
|
}
|
|
32
|
-
static async correctProducts(products) {
|
|
32
|
+
static async correctProducts(products, vat) {
|
|
33
33
|
const correctProducts = [];
|
|
34
34
|
for (let i = 0; i < products.length; i++) {
|
|
35
|
-
const correctProduct = await this.correctProduct(products[i]);
|
|
35
|
+
const correctProduct = await this.correctProduct(products[i], vat);
|
|
36
36
|
correctProducts.push(correctProduct);
|
|
37
37
|
}
|
|
38
38
|
return correctProducts;
|
|
39
39
|
}
|
|
40
|
-
static async correctProduct(product) {
|
|
40
|
+
static async correctProduct(product, vat) {
|
|
41
41
|
const thumbnail = await FilesReader.get(createQueryOptionsForId(product.file_id));
|
|
42
42
|
return {
|
|
43
43
|
id: product.id,
|
|
@@ -48,8 +48,8 @@ export default class ProductReader {
|
|
|
48
48
|
subtitle: product.subtitle,
|
|
49
49
|
description: product.description,
|
|
50
50
|
netPrice: product.net_price,
|
|
51
|
+
promotionalGrossPrice: PriceConverter.netToGrossPrice(product.promotional_net_price, vat),
|
|
51
52
|
promotionalNetPrice: product.promotional_net_price,
|
|
52
|
-
vat: product.vat,
|
|
53
53
|
color: product.color,
|
|
54
54
|
quantity: product.quantity,
|
|
55
55
|
width: product.width,
|
|
@@ -58,7 +58,7 @@ export default class ProductReader {
|
|
|
58
58
|
createdAt: product.created_at,
|
|
59
59
|
deleted: product.deleted,
|
|
60
60
|
thumbnail: thumbnail ? thumbnail : null,
|
|
61
|
-
grossPrice: PriceConverter.netToGrossPrice(Number(product.net_price),
|
|
61
|
+
grossPrice: PriceConverter.netToGrossPrice(Number(product.net_price), vat),
|
|
62
62
|
jsonData: product.json_data
|
|
63
63
|
};
|
|
64
64
|
}
|
|
@@ -46,7 +46,7 @@ export default class Order extends StockObject {
|
|
|
46
46
|
return this.zsiId;
|
|
47
47
|
}
|
|
48
48
|
getGrossPrice() {
|
|
49
|
-
const vatPercentage =
|
|
49
|
+
const vatPercentage = this.vat ? this.vat : 23;
|
|
50
50
|
return PriceConverter.netToGrossPrice(this.net_price, vatPercentage);
|
|
51
51
|
}
|
|
52
52
|
getClientId() {
|