@dascompany/product 3.6.1 → 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.
package/dist/SQL.json CHANGED
@@ -59,7 +59,7 @@
59
59
  "select": "SELECT * FROM products",
60
60
  "selectId": "SELECT id FROM products",
61
61
  "insert": "INSERT INTO products( id, sku, article_number, url, title, description, net_price, promotional_net_price, vat, color, quantity, width, length, height, file_id, json_data, deleted) VALUES ($id::BIGINT, $sku::TEXT, $article_number::TEXT, $url::TEXT, $title::TEXT, $description::TEXT, $net_price::DOUBLE PRECISION, $promotional_net_price::DOUBLE PRECISION, $vat::INT, $color::TEXT, $quantity::INT, $width::INT, $length::INT, $height::DOUBLE PRECISION,$file_id::BIGINT , $json_data::JSON, false::BOOL)",
62
- "update": "UPDATE products SET url = $url::TEXT, title = $title::TEXT, description = $description::TEXT , net_price = $net_price::DOUBLE PRECISION, promotional_net_price = $promotional_net_price::DOUBLE PRECISION, vat = $vat::INT, color = $color::TEXT, quantity = $quantity::INT, width = $width::INT, length = $length::INT, height = $height::DOUBLE PRECISION, file_id = $file_id::BIGINT, json_data = $json_data::JSON WHERE id = $id::BIGINT",
62
+ "update": "UPDATE products SET url = $url::TEXT, article_number = $article_number::TEXT, title = $title::TEXT, description = $description::TEXT , net_price = $net_price::DOUBLE PRECISION, promotional_net_price = $promotional_net_price::DOUBLE PRECISION, vat = $vat::INT, color = $color::TEXT, quantity = $quantity::INT, width = $width::INT, length = $length::INT, height = $height::DOUBLE PRECISION, file_id = $file_id::BIGINT, json_data = $json_data::JSON WHERE id = $id::BIGINT",
63
63
  "delete": "UPDATE products SET deleted = true WHERE id = $id::BIGINT",
64
64
  "maxPrice": "SELECT MAX(net_price) FROM products",
65
65
  "count": "SELECT COUNT(*) AS total_rows FROM products",
@@ -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,
@@ -60,6 +60,7 @@ export default class Product extends StockObject {
60
60
  calculateGrossPrice(): number;
61
61
  setCreatedAt(createdAt: any): void;
62
62
  setUrl(url: string): string;
63
+ setArticleNumber(articleNumber: string): string;
63
64
  setTitle(title: string): string;
64
65
  setDescription(description: string): string;
65
66
  setNetPrice(netPrice: number): number;
@@ -144,6 +144,9 @@ export default class Product extends StockObject {
144
144
  setUrl(url) {
145
145
  return this.url = url;
146
146
  }
147
+ setArticleNumber(articleNumber) {
148
+ return this.articleNumber = articleNumber;
149
+ }
147
150
  setTitle(title) {
148
151
  return this.title = title;
149
152
  }
@@ -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.1",
3
+ "version": "3.6.3",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "vitest",