@dascompany/product 4.1.9 → 4.2.1

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,10 +18,11 @@
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",
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"
21
+ "selectAll": "SELECT * FROM clients.account_cart WHERE account_id = $account_id::BIGINT",
22
+ "select": "SELECT * FROM clients.account_cart WHERE account_id = $account_id::BIGINT AND product_id = $product_id::BIGINT",
23
+ "insert": "INSERT INTO clients.account_cart(account_id, product_id, installation, quantity) VALUES ($account_id::BIGINT, $product_id::BIGINT, $installation::BOOL, $quantity::INT)",
24
+ "update": "UPDATE clients.account_cart SET installation = $installation::BOOL, quantity = $quantity::INT WHERE account_id = $account_id::BIGINT AND product_id = $product_id::BIGINT AND (installation != $installation::BOOL OR quantity != $quantity::INT)",
25
+ "delete": "DELETE FROM clients.account_cart WHERE product_id = $product_id::BIGINT AND account_id = $account_id::BIGINT"
25
26
  },
26
27
  "accountDeliveryDetails": {
27
28
  "select": "SELECT * FROM clients.account_delivery_details WHERE account_id = $account_id::BIGINT",
@@ -0,0 +1,21 @@
1
+ export default class AccountCartItem {
2
+ private accountId;
3
+ private productId;
4
+ private installation;
5
+ private quantity;
6
+ constructor(accountId: string, productId: string, installation: boolean, quantity: number);
7
+ getData(): {
8
+ accountId: string;
9
+ productId: string;
10
+ installation: boolean;
11
+ quantity: number;
12
+ };
13
+ getAccountId(): string;
14
+ getProductId(): string;
15
+ getInstallation(): boolean;
16
+ getQuantity(): number;
17
+ setAccountId(accountId: string): void;
18
+ setProductId(productId: string): void;
19
+ setInstallation(installation: boolean): void;
20
+ setQuantity(quantity: number): void;
21
+ }
@@ -0,0 +1,44 @@
1
+ export default class AccountCartItem {
2
+ accountId;
3
+ productId;
4
+ installation;
5
+ quantity;
6
+ constructor(accountId, productId, installation, quantity) {
7
+ this.accountId = accountId;
8
+ this.productId = productId;
9
+ this.installation = installation;
10
+ this.quantity = quantity;
11
+ }
12
+ getData() {
13
+ return {
14
+ accountId: this.accountId,
15
+ productId: this.productId,
16
+ installation: this.installation,
17
+ quantity: this.quantity,
18
+ };
19
+ }
20
+ getAccountId() {
21
+ return this.accountId;
22
+ }
23
+ getProductId() {
24
+ return this.productId;
25
+ }
26
+ getInstallation() {
27
+ return this.installation;
28
+ }
29
+ getQuantity() {
30
+ return this.quantity;
31
+ }
32
+ setAccountId(accountId) {
33
+ this.accountId = accountId;
34
+ }
35
+ setProductId(productId) {
36
+ this.productId = productId;
37
+ }
38
+ setInstallation(installation) {
39
+ this.installation = installation;
40
+ }
41
+ setQuantity(quantity) {
42
+ this.quantity = quantity;
43
+ }
44
+ }
@@ -1,9 +1,12 @@
1
1
  import { Table } from '@dascompany/database';
2
2
  import AccountCartRow from '../../types/rows/AccountCartRow';
3
+ import AccountCartItem from '../../stockObjects/AccountCartItem.ts';
3
4
  export default class AccountCartTable extends Table {
4
5
  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>;
6
+ select(accountId: string, productId: string): Promise<AccountCartRow[]>;
7
+ delete(accountId: string, productId: string): Promise<void>;
8
+ insert(accountCartItem: AccountCartItem): Promise<void>;
9
+ update(accountCartItem: AccountCartItem): Promise<void>;
8
10
  private bindParams;
11
+ private bindSideParams;
9
12
  }
@@ -2,29 +2,43 @@ import { Table } from '@dascompany/database';
2
2
  import * as SQL from '../../SQL.json';
3
3
  export default class AccountCartTable extends Table {
4
4
  async selectAll(accountId) {
5
- const query = this.createQuery(SQL.accountCart.select);
5
+ const query = this.createQuery(SQL.accountCart.selectAll);
6
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, installation) {
10
+ async select(accountId, productId) {
11
+ const query = this.createQuery(SQL.accountCart.select);
12
+ query.bindParameter('account_id', accountId);
13
+ query.bindParameter('product_id', productId);
14
+ const result = await query.execute();
15
+ return result.getRow();
16
+ }
17
+ async delete(accountId, productId) {
11
18
  const query = this.createQuery(SQL.accountCart.delete);
12
- this.bindParams(query, accountId, productId, installation);
19
+ this.bindParams(query, accountId, productId);
13
20
  await query.execute();
14
21
  }
15
- async insert(accountId, productId, installation) {
22
+ async insert(accountCartItem) {
16
23
  const query = this.createQuery(SQL.accountCart.insert);
17
- this.bindParams(query, accountId, productId, installation);
24
+ this.bindParams(query, accountCartItem.getAccountId(), accountCartItem.getProductId());
25
+ this.bindSideParams(query, accountCartItem);
18
26
  await query.execute();
19
27
  }
20
- async update(accountId, productId, oldInstallation, newInstallation) {
28
+ async update(accountCartItem) {
21
29
  const query = this.createQuery(SQL.accountCart.update);
22
- this.bindParams(query, accountId, productId, newInstallation);
30
+ query.bindParameter('account_id', accountCartItem.getAccountId());
31
+ query.bindParameter('product_id', accountCartItem.getProductId());
32
+ query.bindParameter('installation', accountCartItem.getInstallation());
33
+ query.bindParameter('quantity', accountCartItem.getQuantity());
23
34
  await query.execute();
24
35
  }
25
- bindParams(query, accountId, productId, installation) {
36
+ bindParams(query, accountId, productId) {
26
37
  query.bindParameter('account_id', accountId);
27
38
  query.bindParameter('product_id', productId);
28
- query.bindParameter('installation', installation);
39
+ }
40
+ bindSideParams(query, accountCartItem) {
41
+ query.bindParameter('installation', accountCartItem.getInstallation());
42
+ query.bindParameter('quantity', accountCartItem.getQuantity());
29
43
  }
30
44
  }
@@ -1,5 +1,5 @@
1
1
  export default class AccountCart {
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>;
2
+ static delete(accountId: string, productId: string): Promise<boolean>;
3
+ static insert(accountId: string, productId: string, installation: boolean, quantity: number): Promise<boolean>;
4
+ static update(accountId: string, productId: string, installation: boolean, quantity: number): Promise<boolean>;
5
5
  }
@@ -1,15 +1,18 @@
1
1
  import DatabaseConnection from "../DatabaseConnection";
2
+ import AccountCartItem from "../stockObjects/AccountCartItem.ts";
2
3
  export default class AccountCart {
3
- static async delete(accountId, productId, installation) {
4
- await DatabaseConnection.getInstance().accountCart.delete(accountId, productId, installation);
4
+ static async delete(accountId, productId) {
5
+ await DatabaseConnection.getInstance().accountCart.delete(accountId, productId);
5
6
  return true;
6
7
  }
7
- static async insert(accountId, productId, installation) {
8
- await DatabaseConnection.getInstance().accountCart.insert(accountId, productId, installation);
8
+ static async insert(accountId, productId, installation, quantity) {
9
+ const item = new AccountCartItem(accountId, productId, installation, quantity);
10
+ await DatabaseConnection.getInstance().accountCart.insert(item);
9
11
  return true;
10
12
  }
11
- static async update(accountId, productId, oldInstallation, installation) {
12
- await DatabaseConnection.getInstance().accountCart.update(accountId, productId, oldInstallation, installation);
13
+ static async update(accountId, productId, installation, quantity) {
14
+ const item = new AccountCartItem(accountId, productId, installation, quantity);
15
+ await DatabaseConnection.getInstance().accountCart.update(item);
13
16
  return true;
14
17
  }
15
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dascompany/product",
3
- "version": "4.1.9",
3
+ "version": "4.2.1",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "vitest",
package/produkty.json ADDED
File without changes