@dascompany/product 4.2.7 → 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.
package/dist/index.d.ts CHANGED
@@ -75,4 +75,5 @@ import CompanyDataI from "./types/CompanyDataI";
75
75
  import MarketPlacesReader from "./reader/MarketPlacesReader";
76
76
  import PriceConverter from "./utils/PriceConverter";
77
77
  import createQueryOptionsForId from "./utils/createQueryOptionsForId";
78
- export { Client, ClientAccountRepo, ClientAccountReader, AccountDeliveryDetailsReader, AccountCompanyDetailsReader, AccountCart, AccountCartReader, Admin, AdminRepo, AdminReader, Address, AddressI, AddressesRepo, AddressesReader, PersonalData, PersonalDataRepo, PersonalDataReader, PersonalDataI, CompanyDetails, CompanyDetailsRepo, CompanyDetailsReader, CompanyDetailsI, DeliveryDetails, DeliveryDetailsRepo, DeliveryDetailsReader, DeliveryDetailsI, DeliveryMethods, DeliveryMethodRepo, DeliveryMethodReader, DeliveryMethodI, DeliveryMethodTypeE, DeliveryStatus, DeliveryStatusReader, DeliveryStatusTypeE, PaymentDetails, PaymentDetailsRepo, PaymentDetailsReader, PaymentDetailsI, PaymentMethods, PaymentMethodRepo, PaymentMethodReader, PaymentMethodE, PaymentMethodI, PaymentStatus, PaymentStatusesReader, PaymentStatusE, Order, OrderRepo, OrderReader, OrderProduct, OrderProductsRepo, OrderProductsReader, OrderProductI, Status, OrderStatusReader, StatusI, OrderStatusTypeE, StatusTypesReader, ProductI, Product, ProductRepo, ProductReader, File, FilesRepo, FilesReader, FileI, FileConnection, FileConnectionsRepo, FileConnectionsReader, FileConnectionTypeE, CompanyData, CompanyDataRepo, CompanyDataReader, CompanyDataI, MarketPlacesReader, PriceConverter, createQueryOptionsForId };
78
+ import CilentAccountExistWithThisEmail from "./lib/errors/CilentAccountExistWithThisEmail";
79
+ export { Client, ClientAccountRepo, ClientAccountReader, AccountDeliveryDetailsReader, AccountCompanyDetailsReader, AccountCart, AccountCartReader, Admin, AdminRepo, AdminReader, Address, AddressI, AddressesRepo, AddressesReader, PersonalData, PersonalDataRepo, PersonalDataReader, PersonalDataI, CompanyDetails, CompanyDetailsRepo, CompanyDetailsReader, CompanyDetailsI, DeliveryDetails, DeliveryDetailsRepo, DeliveryDetailsReader, DeliveryDetailsI, DeliveryMethods, DeliveryMethodRepo, DeliveryMethodReader, DeliveryMethodI, DeliveryMethodTypeE, DeliveryStatus, DeliveryStatusReader, DeliveryStatusTypeE, PaymentDetails, PaymentDetailsRepo, PaymentDetailsReader, PaymentDetailsI, PaymentMethods, PaymentMethodRepo, PaymentMethodReader, PaymentMethodE, PaymentMethodI, PaymentStatus, PaymentStatusesReader, PaymentStatusE, Order, OrderRepo, OrderReader, OrderProduct, OrderProductsRepo, OrderProductsReader, OrderProductI, Status, OrderStatusReader, StatusI, OrderStatusTypeE, StatusTypesReader, ProductI, Product, ProductRepo, ProductReader, File, FilesRepo, FilesReader, FileI, FileConnection, FileConnectionsRepo, FileConnectionsReader, FileConnectionTypeE, CompanyData, CompanyDataRepo, CompanyDataReader, CompanyDataI, MarketPlacesReader, PriceConverter, createQueryOptionsForId, CilentAccountExistWithThisEmail };
package/dist/index.js CHANGED
@@ -63,4 +63,5 @@ import CompanyDataReader from "./reader/CompanyDataReader";
63
63
  import MarketPlacesReader from "./reader/MarketPlacesReader";
64
64
  import PriceConverter from "./utils/PriceConverter";
65
65
  import createQueryOptionsForId from "./utils/createQueryOptionsForId";
66
- export { Client, ClientAccountRepo, ClientAccountReader, AccountDeliveryDetailsReader, AccountCompanyDetailsReader, AccountCart, AccountCartReader, Admin, AdminRepo, AdminReader, Address, AddressesRepo, AddressesReader, PersonalData, PersonalDataRepo, PersonalDataReader, CompanyDetails, CompanyDetailsRepo, CompanyDetailsReader, DeliveryDetails, DeliveryDetailsRepo, DeliveryDetailsReader, DeliveryMethods, DeliveryMethodRepo, DeliveryMethodReader, DeliveryMethodTypeE, DeliveryStatus, DeliveryStatusReader, DeliveryStatusTypeE, PaymentDetails, PaymentDetailsRepo, PaymentDetailsReader, PaymentMethods, PaymentMethodRepo, PaymentMethodReader, PaymentMethodE, PaymentStatus, PaymentStatusesReader, PaymentStatusE, Order, OrderRepo, OrderReader, OrderProduct, OrderProductsRepo, OrderProductsReader, Status, OrderStatusReader, OrderStatusTypeE, StatusTypesReader, Product, ProductRepo, ProductReader, File, FilesRepo, FilesReader, FileConnection, FileConnectionsRepo, FileConnectionsReader, FileConnectionTypeE, CompanyData, CompanyDataRepo, CompanyDataReader, MarketPlacesReader, PriceConverter, createQueryOptionsForId };
66
+ import CilentAccountExistWithThisEmail from "./lib/errors/CilentAccountExistWithThisEmail";
67
+ export { Client, ClientAccountRepo, ClientAccountReader, AccountDeliveryDetailsReader, AccountCompanyDetailsReader, AccountCart, AccountCartReader, Admin, AdminRepo, AdminReader, Address, AddressesRepo, AddressesReader, PersonalData, PersonalDataRepo, PersonalDataReader, CompanyDetails, CompanyDetailsRepo, CompanyDetailsReader, DeliveryDetails, DeliveryDetailsRepo, DeliveryDetailsReader, DeliveryMethods, DeliveryMethodRepo, DeliveryMethodReader, DeliveryMethodTypeE, DeliveryStatus, DeliveryStatusReader, DeliveryStatusTypeE, PaymentDetails, PaymentDetailsRepo, PaymentDetailsReader, PaymentMethods, PaymentMethodRepo, PaymentMethodReader, PaymentMethodE, PaymentStatus, PaymentStatusesReader, PaymentStatusE, Order, OrderRepo, OrderReader, OrderProduct, OrderProductsRepo, OrderProductsReader, Status, OrderStatusReader, OrderStatusTypeE, StatusTypesReader, Product, ProductRepo, ProductReader, File, FilesRepo, FilesReader, FileConnection, FileConnectionsRepo, FileConnectionsReader, FileConnectionTypeE, CompanyData, CompanyDataRepo, CompanyDataReader, MarketPlacesReader, PriceConverter, createQueryOptionsForId, CilentAccountExistWithThisEmail };
@@ -0,0 +1,3 @@
1
+ export default class CilentAccountExistWithThisEmail extends Error {
2
+ constructor(email: string);
3
+ }
@@ -0,0 +1,5 @@
1
+ export default class CilentAccountExistWithThisEmail extends Error {
2
+ constructor(email) {
3
+ super(`Client account with email: ${email} already exist!`);
4
+ }
5
+ }
@@ -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), Number(product.vat)),
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 = 23; //brak stawki vat dla zamówienia
49
+ const vatPercentage = this.vat ? this.vat : 23;
50
50
  return PriceConverter.netToGrossPrice(this.net_price, vatPercentage);
51
51
  }
52
52
  getClientId() {
@@ -1,5 +1,6 @@
1
1
  import { ParameterType, QueryOptions, Table } from '@dascompany/database';
2
2
  import * as SQL from '../../SQL.json';
3
+ import CilentAccountExistWithThisEmail from '../../lib/errors/CilentAccountExistWithThisEmail';
3
4
  export default class ClientAccountsTable extends Table {
4
5
  async select(queryOptions) {
5
6
  const query = this.createQuery(SQL.accounts.select, queryOptions);
@@ -46,7 +47,7 @@ export default class ClientAccountsTable extends Table {
46
47
  queryOptions.setWhere([{ name: 'email', type: ParameterType.string, value: clientEmail }]);
47
48
  let accountId = await this.selectId(queryOptions);
48
49
  if (accountId)
49
- throw new Error(`Client account with email: ${clientEmail} already exist!`);
50
+ throw new CilentAccountExistWithThisEmail(clientEmail);
50
51
  else
51
52
  accountId = await this.selectNextId();
52
53
  const query = this.createQuery(SQL.accounts.insert);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dascompany/product",
3
- "version": "4.2.7",
3
+ "version": "4.2.9",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "vitest",