@dascompany/product 3.6.4 → 3.6.6

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.
@@ -21,6 +21,7 @@ import FileConnectionsTable from './tables/files/FileConnectionsTable';
21
21
  import AdminAccountsTable from './tables/public/AdminAccountsTable';
22
22
  import AccountCompanyDetailsTable from './tables/clients/AccountCompanyDetailsTable';
23
23
  import AccountDeliveryDetailsTable from './tables/clients/AccountDeliveryDetailsTable';
24
+ import AccountCartTable from './tables/clients/AccountCartTable';
24
25
  export default class DatabaseConnection {
25
26
  static instance: DatabaseConnection;
26
27
  private tables;
@@ -35,6 +36,7 @@ export default class DatabaseConnection {
35
36
  get addresses(): AddressesTable;
36
37
  get clientAccounts(): ClientAccountsTable;
37
38
  get accountCompanyDetails(): AccountCompanyDetailsTable;
39
+ get accountCart(): AccountCartTable;
38
40
  get accountDeliveryDetails(): AccountDeliveryDetailsTable;
39
41
  get adminAccounts(): AdminAccountsTable;
40
42
  get companyDetails(): CompanyDetailsTable;
@@ -23,6 +23,7 @@ import FileConnectionsTable from './tables/files/FileConnectionsTable';
23
23
  import AdminAccountsTable from './tables/public/AdminAccountsTable';
24
24
  import AccountCompanyDetailsTable from './tables/clients/AccountCompanyDetailsTable';
25
25
  import AccountDeliveryDetailsTable from './tables/clients/AccountDeliveryDetailsTable';
26
+ import AccountCartTable from './tables/clients/AccountCartTable';
26
27
  export default class DatabaseConnection {
27
28
  static instance;
28
29
  tables = new Map();
@@ -75,6 +76,11 @@ export default class DatabaseConnection {
75
76
  this.tables.set(TableNames.accountCompanyDetails, new AccountCompanyDetailsTable(this.connection));
76
77
  return this.tables.get(TableNames.accountCompanyDetails);
77
78
  }
79
+ get accountCart() {
80
+ if (!this.tables.get(TableNames.accountCart))
81
+ this.tables.set(TableNames.accountCart, new AccountCartTable(this.connection));
82
+ return this.tables.get(TableNames.accountCart);
83
+ }
78
84
  get accountDeliveryDetails() {
79
85
  if (!this.tables.get(TableNames.accountDeliveryDetails))
80
86
  this.tables.set(TableNames.accountDeliveryDetails, new AccountDeliveryDetailsTable(this.connection));
package/dist/SQL.json CHANGED
@@ -17,6 +17,11 @@
17
17
  "count": "SELECT COUNT(*) AS total_rows FROM clients.accounts",
18
18
  "selectNextId": "SELECT nextval('clients.accounts_id'::regclass)"
19
19
  },
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"
24
+ },
20
25
  "accountDeliveryDetails": {
21
26
  "select": "SELECT * FROM clients.account_delivery_details WHERE account_id = $account_id::BIGINT",
22
27
  "insert": "INSERT INTO clients.account_delivery_details(account_id, delivery_details_id) VALUES ($account_id::BIGINT, $delivery_details_id::BIGINT)",
@@ -59,7 +64,7 @@
59
64
  "select": "SELECT * FROM products",
60
65
  "selectId": "SELECT id FROM products",
61
66
  "insert": "INSERT INTO products( id, sku, article_number, url, title, subtitle, 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, subtitle::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, article_number = $article_number::TEXT, title = $title::TEXT, subtitle = $subtitle::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",
67
+ "update": "UPDATE products SET url = $url::TEXT, article_number = $article_number::TEXT, title = $title::TEXT, subtitle = $subtitle::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
68
  "delete": "UPDATE products SET deleted = true WHERE id = $id::BIGINT",
64
69
  "maxPrice": "SELECT MAX(net_price) FROM products",
65
70
  "count": "SELECT COUNT(*) AS total_rows FROM products",
@@ -0,0 +1,5 @@
1
+ import ProductI from "../types/ProductI";
2
+ export default class AccountCartReader {
3
+ static getAll(accountId: string, productId: string): Promise<ProductI[]>;
4
+ private static correctAccountCart;
5
+ }
@@ -0,0 +1,17 @@
1
+ import DatabaseConnection from "../DatabaseConnection";
2
+ import createQueryOptionsForId from "../utils/createQueryOptionsForId";
3
+ import ProductReader from "./ProductReader";
4
+ export default class AccountCartReader {
5
+ static async getAll(accountId, productId) {
6
+ const accountCart = await DatabaseConnection.getInstance().accountCart.selectAll(accountId, productId);
7
+ return this.correctAccountCart(accountCart);
8
+ }
9
+ static async correctAccountCart(accountCart) {
10
+ const correctAccountCart = [];
11
+ for (let i = 0; i < accountCart.length; i++) {
12
+ const product = await ProductReader.get(createQueryOptionsForId(accountCart[i].product_id));
13
+ correctAccountCart.push(product);
14
+ }
15
+ return correctAccountCart;
16
+ }
17
+ }
@@ -2,6 +2,7 @@ declare enum TableNames {
2
2
  adminAccounts = "adminAccountsTable",
3
3
  clientAccounts = "clientAccountsTable",
4
4
  accountDeliveryDetails = "accountDeliveryDetailsTable",
5
+ accountCart = "accountCartTable",
5
6
  accountCompanyDetails = "accountCompanyDetailsTable",
6
7
  fileConnections = "fileConnectionsTable",
7
8
  files = "filesTable",
@@ -3,6 +3,7 @@ var TableNames;
3
3
  TableNames["adminAccounts"] = "adminAccountsTable";
4
4
  TableNames["clientAccounts"] = "clientAccountsTable";
5
5
  TableNames["accountDeliveryDetails"] = "accountDeliveryDetailsTable";
6
+ TableNames["accountCart"] = "accountCartTable";
6
7
  TableNames["accountCompanyDetails"] = "accountCompanyDetailsTable";
7
8
  TableNames["fileConnections"] = "fileConnectionsTable";
8
9
  TableNames["files"] = "filesTable";
@@ -0,0 +1,8 @@
1
+ import { Table } from '@dascompany/database';
2
+ import AccountCartRow from '../../types/rows/AccountCartRow';
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>;
7
+ private bindParams;
8
+ }
@@ -0,0 +1,25 @@
1
+ import { Table } from '@dascompany/database';
2
+ import * as SQL from '../../SQL.json';
3
+ export default class AccountCartTable extends Table {
4
+ async selectAll(accountId, productId) {
5
+ const query = this.createQuery(SQL.accountCart.select);
6
+ this.bindParams(query, accountId, productId);
7
+ const result = await query.execute();
8
+ return result.getRows();
9
+ }
10
+ async delete(accountId, productId) {
11
+ const query = this.createQuery(SQL.accountCart.delete);
12
+ this.bindParams(query, accountId, productId);
13
+ await query.execute();
14
+ }
15
+ async insert(accountId, productId) {
16
+ const query = this.createQuery(SQL.accountCart.insert);
17
+ this.bindParams(query, accountId, productId);
18
+ await query.execute();
19
+ }
20
+ bindParams(query, accountId, productId) {
21
+ console.log(query, accountId, productId);
22
+ query.bindParameter('account_id', accountId);
23
+ query.bindParameter('product_id', productId);
24
+ }
25
+ }
@@ -0,0 +1,4 @@
1
+ export default interface AccountCartRow {
2
+ account_id: string;
3
+ product_id: string;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export default class AccountCart {
2
+ static delete(accountId: string, productId: string): Promise<boolean>;
3
+ static insert(accountId: string, productId: string): Promise<boolean>;
4
+ }
@@ -0,0 +1,11 @@
1
+ import DatabaseConnection from "../DatabaseConnection";
2
+ export default class AccountCart {
3
+ static async delete(accountId, productId) {
4
+ await DatabaseConnection.getInstance().accountCart.delete(accountId, productId);
5
+ return true;
6
+ }
7
+ static async insert(accountId, productId) {
8
+ await DatabaseConnection.getInstance().accountCart.insert(accountId, productId);
9
+ return true;
10
+ }
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dascompany/product",
3
- "version": "3.6.4",
3
+ "version": "3.6.6",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "vitest",