@dascompany/product 3.6.2 → 3.6.3

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.
@@ -23,11 +23,11 @@ export default class OrderProductsReader {
23
23
  productId: orderProduct.product_id,
24
24
  sku: orderProduct.sku,
25
25
  title: orderProduct.title,
26
- netPrice: Number(orderProduct.net_price),
26
+ netPrice: PriceConverter.priceToPenny(orderProduct.net_price),
27
27
  installation: orderProduct.installation_price ? true : false,
28
- installationPrice: Number(orderProduct.installation_price),
28
+ installationPrice: PriceConverter.priceToPenny(orderProduct.installation_price),
29
29
  grossPrice: PriceConverter.netToGrossPrice(Number(orderProduct.net_price), Number(orderProduct.vat)),
30
- vat: Number(orderProduct.vat),
30
+ vat: orderProduct.vat,
31
31
  thumbnail,
32
32
  };
33
33
  return correctProduct;
@@ -1,6 +1,7 @@
1
1
  import { ParameterType, QueryOptions } from "@dascompany/database";
2
2
  import DatabaseConnection from "../DatabaseConnection";
3
3
  import OrderStatusReader from "./OrderStatusReader";
4
+ import PriceConverter from "../utils/PriceConverter";
4
5
  export default class OrderReader {
5
6
  static async get(queryOptions) {
6
7
  const orderData = await DatabaseConnection.getInstance().orders.select(queryOptions);
@@ -39,7 +40,7 @@ export default class OrderReader {
39
40
  const correctOrder = {
40
41
  id: order.id,
41
42
  email: order.email,
42
- price: Number(order.price),
43
+ price: PriceConverter.priceToPenny(order.price),
43
44
  createdAt: order.created_at,
44
45
  clientId: order.client_id,
45
46
  deliveryDetailsId: order.delivery_details_id,
@@ -46,11 +46,11 @@ export default class ProductReader {
46
46
  url: product.url,
47
47
  title: product.title,
48
48
  description: product.description,
49
- netPrice: Number(product.net_price),
50
- promotionalNetPrice: Number(product.promotional_net_price),
51
- vat: Number(product.vat),
49
+ netPrice: PriceConverter.priceToPenny(product.net_price),
50
+ promotionalNetPrice: PriceConverter.priceToPenny(product.promotional_net_price),
51
+ vat: product.vat,
52
52
  color: product.color,
53
- quantity: Number(product.quantity),
53
+ quantity: product.quantity,
54
54
  width: product.width,
55
55
  height: product.height,
56
56
  length: product.length,
@@ -0,0 +1,7 @@
1
+ import AddressI from "./AddressI";
2
+ export default interface AccountDeliveryDetailsI {
3
+ id: number;
4
+ accountId: number;
5
+ address: AddressI;
6
+ personalData: number;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -2,10 +2,10 @@ export default interface OrderProductRow {
2
2
  id: string;
3
3
  order_id: string;
4
4
  product_id: string;
5
- net_price: string;
6
- installation_price: string;
5
+ net_price: number;
6
+ installation_price: number;
7
7
  title: string;
8
8
  sku: string;
9
- vat: string;
9
+ vat: number;
10
10
  file_id: string;
11
11
  }
@@ -1,4 +1,5 @@
1
1
  export default class PriceConverter {
2
2
  static netToGrossPrice(netPrice: number, vatPercentage?: number): number;
3
- static grossToNetPrice(grossPrice: number, vatPercentage?: number): number;
3
+ static grossToNetPrice(grossPrice: number, vatPercentage?: number): string;
4
+ static priceToPenny(price: number): number;
4
5
  }
@@ -3,12 +3,14 @@ export default class PriceConverter {
3
3
  const netPriceInPenny = Math.round(netPrice * 100);
4
4
  const vatPriceInPenny = Math.round((netPriceInPenny * vatPercentage) / 100);
5
5
  const grossPriceInPenny = netPriceInPenny + vatPriceInPenny;
6
- const grossPrice = (grossPriceInPenny / 100).toFixed(2);
7
- return Number(grossPrice);
6
+ return grossPriceInPenny;
8
7
  }
9
8
  static grossToNetPrice(grossPrice, vatPercentage = 23) {
10
9
  const grossPriceInPenny = Math.round(grossPrice * 100);
11
10
  const netPrice = ((grossPriceInPenny / (vatPercentage / 100 + 1)) / 100).toFixed(2);
12
- return Number(netPrice);
11
+ return netPrice;
12
+ }
13
+ static priceToPenny(price) {
14
+ return Math.round(price * 100);
13
15
  }
14
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dascompany/product",
3
- "version": "3.6.2",
3
+ "version": "3.6.3",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "vitest",