@dascompany/product 4.0.9 → 4.0.11

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
@@ -18,9 +18,10 @@
18
18
  "selectNextId": "SELECT nextval('clients.accounts_id'::regclass)"
19
19
  },
20
20
  "accountCart": {
21
- "select": "SELECT * FROM clients.account_cart WHERE account_id = $account_id::BIGINT AND product_id = $product_id::BIGINT",
22
- "insert": "INSERT INTO clients.account_cart(account_id, product_id) VALUES ($account_id::BIGINT, $product_id::BIGINT)",
23
- "delete": "DELETE FROM clients.account_cart WHERE product_id = $product_id::BIGINT AND account_id = $account_id::BIGINT"
21
+ "select": "SELECT * FROM clients.account_cart WHERE account_id = $account_id::BIGINT",
22
+ "insert": "INSERT INTO clients.account_cart(account_id, product_id, installation) VALUES ($account_id::BIGINT, $product_id::BIGINT, installation::BOOL)",
23
+ "update": "UPDATE clients.account_cart SET installation = $installation WHERE account_id = $account_id::BIGINT AND product_id = $product_id::BIGINT AND installation = $installation::Bool",
24
+ "delete": "DELETE FROM clients.account_cart WHERE product_id = $product_id::BIGINT AND account_id = $account_id::BIGINT AND installation = $installation::BOOL"
24
25
  },
25
26
  "accountDeliveryDetails": {
26
27
  "select": "SELECT * FROM clients.account_delivery_details WHERE account_id = $account_id::BIGINT",
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import Client from "./stockObjects/Client";
2
2
  import ClientAccountRepo from "./repo/ClientAccountRepo";
3
3
  import ClientAccountReader from "./reader/ClientAccountReader";
4
+ import AccountCartReader from "./reader/AccountCartReader";
4
5
  import AccountDeliveryDetailsReader from "./reader/AccountDeliveryDetailsReader";
5
6
  import AccountCompanyDetailsReader from "./reader/AccountCompanyDetailsReader";
6
7
  import Admin from "./stockObjects/Admin";
@@ -72,4 +73,4 @@ import CompanyDataReader from "./reader/CompanyDataReader";
72
73
  import CompanyDataI from "./types/CompanyDataI";
73
74
  import PriceConverter from "./utils/PriceConverter";
74
75
  import createQueryOptionsForId from "./utils/createQueryOptionsForId";
75
- export { Client, ClientAccountRepo, ClientAccountReader, AccountDeliveryDetailsReader, AccountCompanyDetailsReader, 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, PriceConverter, createQueryOptionsForId };
76
+ export { Client, ClientAccountRepo, ClientAccountReader, AccountCartReader, AccountDeliveryDetailsReader, AccountCompanyDetailsReader, 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, PriceConverter, createQueryOptionsForId };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import Client from "./stockObjects/Client";
2
2
  import ClientAccountRepo from "./repo/ClientAccountRepo";
3
3
  import ClientAccountReader from "./reader/ClientAccountReader";
4
+ import AccountCartReader from "./reader/AccountCartReader";
4
5
  import AccountDeliveryDetailsReader from "./reader/AccountDeliveryDetailsReader";
5
6
  import AccountCompanyDetailsReader from "./reader/AccountCompanyDetailsReader";
6
7
  import Admin from "./stockObjects/Admin";
@@ -60,4 +61,4 @@ import CompanyDataRepo from "./repo/CompanyDataRepo";
60
61
  import CompanyDataReader from "./reader/CompanyDataReader";
61
62
  import PriceConverter from "./utils/PriceConverter";
62
63
  import createQueryOptionsForId from "./utils/createQueryOptionsForId";
63
- export { Client, ClientAccountRepo, ClientAccountReader, AccountDeliveryDetailsReader, AccountCompanyDetailsReader, 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, PriceConverter, createQueryOptionsForId };
64
+ export { Client, ClientAccountRepo, ClientAccountReader, AccountCartReader, AccountDeliveryDetailsReader, AccountCompanyDetailsReader, 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, PriceConverter, createQueryOptionsForId };
@@ -1,5 +1,5 @@
1
1
  import ProductI from "../types/ProductI";
2
2
  export default class AccountCartReader {
3
- static getAll(accountId: string, productId: string): Promise<ProductI[]>;
3
+ static getAll(accountId: string): Promise<ProductI[]>;
4
4
  private static correctAccountCart;
5
5
  }
@@ -2,8 +2,8 @@ import DatabaseConnection from "../DatabaseConnection";
2
2
  import createQueryOptionsForId from "../utils/createQueryOptionsForId";
3
3
  import ProductReader from "./ProductReader";
4
4
  export default class AccountCartReader {
5
- static async getAll(accountId, productId) {
6
- const accountCart = await DatabaseConnection.getInstance().accountCart.selectAll(accountId, productId);
5
+ static async getAll(accountId) {
6
+ const accountCart = await DatabaseConnection.getInstance().accountCart.selectAll(accountId);
7
7
  return this.correctAccountCart(accountCart);
8
8
  }
9
9
  static async correctAccountCart(accountCart) {
@@ -39,10 +39,6 @@ export default class ProductReader {
39
39
  }
40
40
  static async correctProduct(product) {
41
41
  const thumbnail = await FilesReader.get(createQueryOptionsForId(product.file_id));
42
- const netPrice = PriceConverter.priceToPenny(product.net_price);
43
- const promotionalNetPrice = product.promotional_net_price ? PriceConverter.priceToPenny(product.promotional_net_price) : null;
44
- const grossPrice = PriceConverter.netToGrossPrice(Number(product.net_price), Number(product.vat));
45
- const promotionalGrossPrice = product.promotional_net_price ? PriceConverter.netToGrossPrice(Number(product.promotional_net_price), Number(product.vat)) : null;
46
42
  return {
47
43
  id: product.id,
48
44
  sku: product.sku,
@@ -51,8 +47,8 @@ export default class ProductReader {
51
47
  title: product.title,
52
48
  subtitle: product.subtitle,
53
49
  description: product.description,
54
- netPrice,
55
- promotionalNetPrice,
50
+ netPrice: PriceConverter.priceToPenny(product.net_price),
51
+ promotionalNetPrice: PriceConverter.priceToPenny(product.promotional_net_price),
56
52
  vat: product.vat,
57
53
  color: product.color,
58
54
  quantity: product.quantity,
@@ -62,8 +58,7 @@ export default class ProductReader {
62
58
  createdAt: product.created_at,
63
59
  deleted: product.deleted,
64
60
  thumbnail: thumbnail ? thumbnail : null,
65
- grossPrice,
66
- promotionalGrossPrice,
61
+ grossPrice: PriceConverter.netToGrossPrice(Number(product.net_price), Number(product.vat)),
67
62
  jsonData: product.json_data
68
63
  };
69
64
  }
@@ -1,8 +1,9 @@
1
1
  import { Table } from '@dascompany/database';
2
2
  import AccountCartRow from '../../types/rows/AccountCartRow';
3
3
  export default class AccountCartTable extends Table {
4
- selectAll(accountId: string, productId: string): Promise<AccountCartRow[]>;
5
- delete(accountId: string, productId: string): Promise<void>;
6
- insert(accountId: string, productId: string): Promise<void>;
4
+ selectAll(accountId: string): Promise<AccountCartRow[]>;
5
+ delete(accountId: string, productId: string, installation: boolean): Promise<void>;
6
+ insert(accountId: string, productId: string, installation: boolean): Promise<void>;
7
+ update(accountId: string, productId: string, oldInstallation: boolean, newInstallation: boolean): Promise<void>;
7
8
  private bindParams;
8
9
  }
@@ -1,25 +1,30 @@
1
1
  import { Table } from '@dascompany/database';
2
2
  import * as SQL from '../../SQL.json';
3
3
  export default class AccountCartTable extends Table {
4
- async selectAll(accountId, productId) {
4
+ async selectAll(accountId) {
5
5
  const query = this.createQuery(SQL.accountCart.select);
6
- this.bindParams(query, accountId, productId);
6
+ query.bindParameter('account_id', accountId);
7
7
  const result = await query.execute();
8
8
  return result.getRows();
9
9
  }
10
- async delete(accountId, productId) {
10
+ async delete(accountId, productId, installation) {
11
11
  const query = this.createQuery(SQL.accountCart.delete);
12
- this.bindParams(query, accountId, productId);
12
+ this.bindParams(query, accountId, productId, installation);
13
13
  await query.execute();
14
14
  }
15
- async insert(accountId, productId) {
15
+ async insert(accountId, productId, installation) {
16
16
  const query = this.createQuery(SQL.accountCart.insert);
17
- this.bindParams(query, accountId, productId);
17
+ this.bindParams(query, accountId, productId, installation);
18
+ await query.execute();
19
+ }
20
+ async update(accountId, productId, oldInstallation, newInstallation) {
21
+ const query = this.createQuery(SQL.accountCart.update);
22
+ this.bindParams(query, accountId, productId, newInstallation);
18
23
  await query.execute();
19
24
  }
20
- bindParams(query, accountId, productId) {
21
- console.log(query, accountId, productId);
25
+ bindParams(query, accountId, productId, installation) {
22
26
  query.bindParameter('account_id', accountId);
23
27
  query.bindParameter('product_id', productId);
28
+ query.bindParameter('installation', installation);
24
29
  }
25
30
  }
@@ -1,4 +1,5 @@
1
1
  export default class AccountCart {
2
- static delete(accountId: string, productId: string): Promise<boolean>;
3
- static insert(accountId: string, productId: string): Promise<boolean>;
2
+ static delete(accountId: string, productId: string, installation: boolean): Promise<boolean>;
3
+ static insert(accountId: string, productId: string, installation: boolean): Promise<boolean>;
4
+ static update(accountId: string, productId: string, oldInstallation: boolean, installation: boolean): Promise<boolean>;
4
5
  }
@@ -1,11 +1,15 @@
1
1
  import DatabaseConnection from "../DatabaseConnection";
2
2
  export default class AccountCart {
3
- static async delete(accountId, productId) {
4
- await DatabaseConnection.getInstance().accountCart.delete(accountId, productId);
3
+ static async delete(accountId, productId, installation) {
4
+ await DatabaseConnection.getInstance().accountCart.delete(accountId, productId, installation);
5
5
  return true;
6
6
  }
7
- static async insert(accountId, productId) {
8
- await DatabaseConnection.getInstance().accountCart.insert(accountId, productId);
7
+ static async insert(accountId, productId, installation) {
8
+ await DatabaseConnection.getInstance().accountCart.insert(accountId, productId, installation);
9
+ return true;
10
+ }
11
+ static async update(accountId, productId, oldInstallation, installation) {
12
+ await DatabaseConnection.getInstance().accountCart.update(accountId, productId, oldInstallation, installation);
9
13
  return true;
10
14
  }
11
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dascompany/product",
3
- "version": "4.0.9",
3
+ "version": "4.0.11",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "vitest",
@@ -20,7 +20,7 @@
20
20
  "vitest": "^3.0.6"
21
21
  },
22
22
  "peerDependencies": {
23
- "@dascompany/database": "^4.0.6",
23
+ "@dascompany/database": "^4.0.9",
24
24
  "@types/pg": "^8.11.11",
25
25
  "pg": "^8.13.3"
26
26
  }