@dascompany/product 4.2.2 → 4.2.4

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.
@@ -22,6 +22,7 @@ import AdminAccountsTable from './tables/public/AdminAccountsTable';
22
22
  import AccountCompanyDetailsTable from './tables/clients/AccountCompanyDetailsTable';
23
23
  import AccountDeliveryDetailsTable from './tables/clients/AccountDeliveryDetailsTable';
24
24
  import AccountCartTable from './tables/clients/AccountCartTable';
25
+ import MarketPlacesTable from './tables/settings/MarketPlacesTable';
25
26
  export default class DatabaseConnection {
26
27
  static instance: DatabaseConnection;
27
28
  private tables;
@@ -51,5 +52,6 @@ export default class DatabaseConnection {
51
52
  get paymentDetails(): PaymentDetailsTable;
52
53
  get paymentStatuses(): PaymentStatusesTable;
53
54
  get companyData(): CompanyDataTable;
55
+ get marketPlaces(): MarketPlacesTable;
54
56
  get fileConnections(): FileConnectionsTable;
55
57
  }
@@ -24,6 +24,7 @@ import AdminAccountsTable from './tables/public/AdminAccountsTable';
24
24
  import AccountCompanyDetailsTable from './tables/clients/AccountCompanyDetailsTable';
25
25
  import AccountDeliveryDetailsTable from './tables/clients/AccountDeliveryDetailsTable';
26
26
  import AccountCartTable from './tables/clients/AccountCartTable';
27
+ import MarketPlacesTable from './tables/settings/MarketPlacesTable';
27
28
  export default class DatabaseConnection {
28
29
  static instance;
29
30
  tables = new Map();
@@ -151,6 +152,11 @@ export default class DatabaseConnection {
151
152
  this.tables.set(TableNames.companyData, new CompanyDataTable(this.connection));
152
153
  return this.tables.get(TableNames.companyData);
153
154
  }
155
+ get marketPlaces() {
156
+ if (!this.tables.get(TableNames.marketPlaces))
157
+ this.tables.set(TableNames.marketPlaces, new MarketPlacesTable(this.connection));
158
+ return this.tables.get(TableNames.marketPlaces);
159
+ }
154
160
  get fileConnections() {
155
161
  if (!this.tables.get(TableNames.fileConnections))
156
162
  this.tables.set(TableNames.fileConnections, new FileConnectionsTable(this.connection));
package/dist/SQL.json CHANGED
@@ -18,11 +18,10 @@
18
18
  "selectNextId": "SELECT nextval('clients.accounts_id'::regclass)"
19
19
  },
20
20
  "accountCart": {
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",
21
+ "select": "SELECT * FROM clients.account_cart ",
23
22
  "insert": "INSERT INTO clients.account_cart(account_id, product_id, installation, quantity) VALUES ($account_id::BIGINT, $product_id::BIGINT, $installation::BOOL, $quantity::INT)",
24
23
  "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"
24
+ "delete": "DELETE FROM clients.account_cart "
26
25
  },
27
26
  "accountDeliveryDetails": {
28
27
  "select": "SELECT * FROM clients.account_delivery_details WHERE account_id = $account_id::BIGINT",
@@ -147,5 +146,8 @@
147
146
  "insert": "INSERT INTO settings.company_data(id, name, email, phone_number, registration_number, tax_number, swift_number, regon_number, bank_account_number, bank_name, address_id) VALUES ( $id::BIGINT, $name::TEXT, $email::TEXT, $phone_number::TEXT, $registartion_number::TEXT, $tax_number::TEXT, $swift_number::TEXT, $regon_number::TEXT, $bank_account_number::TEXT, $bank_name::TEXT, $address_id::BIGINT )",
148
147
  "update": "UPDATE settings.company_data SET id = $id::BIGINT, name = $name::TEXT , email = LOWER($email::TEXT), phone_number = $phone_number::TEXT, registration_number = $registration_number::TEXT,tax_number = $tax_number::TEXT, regon_number = $regon_number::TEXT, bank_account_number = $bank_account_number::TEXT, bank_name = $bank_name::TEXT WHERE id = $id::BIGINT",
149
148
  "selectNextId": "SELECT nextval('settings.company_data_id'::regclass)"
149
+ },
150
+ "marketPlaces": {
151
+ "select": "SELECT * FROM settings.market_places"
150
152
  }
151
153
  }
@@ -1,4 +1,6 @@
1
+ import { QueryOptions } from "@dascompany/database";
1
2
  export default class AccountCartReader {
2
3
  static getAll(accountId: string): Promise<any[]>;
4
+ static get(queryOptions: QueryOptions): Promise<any[]>;
3
5
  private static correctAccountCart;
4
6
  }
@@ -1,7 +1,14 @@
1
+ import { ParameterType, QueryOptions } from "@dascompany/database";
1
2
  import DatabaseConnection from "../DatabaseConnection";
2
3
  export default class AccountCartReader {
3
4
  static async getAll(accountId) {
4
- const accountCart = await DatabaseConnection.getInstance().accountCart.selectAll(accountId);
5
+ const queryOptions = new QueryOptions();
6
+ queryOptions.setWhere([{ name: 'account_id', type: ParameterType.bigint, value: accountId }]);
7
+ const accountCart = await DatabaseConnection.getInstance().accountCart.select(queryOptions);
8
+ return this.correctAccountCart(accountCart);
9
+ }
10
+ static async get(queryOptions) {
11
+ const accountCart = await DatabaseConnection.getInstance().accountCart.select(queryOptions);
5
12
  return this.correctAccountCart(accountCart);
6
13
  }
7
14
  static async correctAccountCart(accountCart) {
@@ -0,0 +1,14 @@
1
+ import { QueryOptions } from "@dascompany/database";
2
+ type MarketData = {
3
+ id: string;
4
+ country: string;
5
+ language: string;
6
+ vatRate: string;
7
+ };
8
+ export default class MarketPlacesReader {
9
+ static get(queryOptions: QueryOptions): Promise<MarketData>;
10
+ static getAll(queryOptions: QueryOptions): Promise<MarketData[]>;
11
+ private static correctMarkets;
12
+ private static correctMarket;
13
+ }
14
+ export {};
@@ -0,0 +1,29 @@
1
+ import DatabaseConnection from "../DatabaseConnection";
2
+ export default class MarketPlacesReader {
3
+ static async get(queryOptions) {
4
+ if (!queryOptions.getLimit())
5
+ queryOptions.setLimit(1, 0);
6
+ const marketPlace = await DatabaseConnection.getInstance().marketPlaces.select(queryOptions);
7
+ return this.correctMarket(marketPlace[0]);
8
+ }
9
+ static async getAll(queryOptions) {
10
+ const marketPlace = await DatabaseConnection.getInstance().marketPlaces.select(queryOptions);
11
+ return this.correctMarkets(marketPlace);
12
+ }
13
+ static correctMarkets(marketRows) {
14
+ const markets = [];
15
+ marketRows.forEach((market) => {
16
+ markets.push(this.correctMarket(market));
17
+ });
18
+ return markets;
19
+ }
20
+ static correctMarket(marketRow) {
21
+ const correctMarket = {
22
+ id: marketRow.id,
23
+ country: marketRow.country,
24
+ language: marketRow.language,
25
+ vatRate: marketRow.vat_rate,
26
+ };
27
+ return correctMarket;
28
+ }
29
+ }
@@ -22,6 +22,7 @@ declare enum TableNames {
22
22
  products = "productsTable",
23
23
  companyData = "companyDataTable",
24
24
  deliveryMethods = "deliveryMethodsTable",
25
- paymentMethods = "paymentMethodsTable"
25
+ paymentMethods = "paymentMethodsTable",
26
+ marketPlaces = "marketPlacesTable"
26
27
  }
27
28
  export default TableNames;
@@ -24,5 +24,6 @@ var TableNames;
24
24
  TableNames["companyData"] = "companyDataTable";
25
25
  TableNames["deliveryMethods"] = "deliveryMethodsTable";
26
26
  TableNames["paymentMethods"] = "paymentMethodsTable";
27
+ TableNames["marketPlaces"] = "marketPlacesTable";
27
28
  })(TableNames || (TableNames = {}));
28
29
  export default TableNames;
@@ -1,10 +1,9 @@
1
- import { Table } from '@dascompany/database';
1
+ import { QueryOptions, Table } from '@dascompany/database';
2
2
  import AccountCartRow from '../../types/rows/AccountCartRow';
3
3
  import AccountCartItem from '../../stockObjects/AccountCartItem.ts';
4
4
  export default class AccountCartTable extends Table {
5
- selectAll(accountId: string): Promise<AccountCartRow[]>;
6
- select(accountId: string, productId: string): Promise<AccountCartRow[]>;
7
- delete(accountId: string, productId: string): Promise<void>;
5
+ select(queryOptions: QueryOptions): Promise<AccountCartRow[]>;
6
+ delete(queryOptions: QueryOptions): Promise<void>;
8
7
  insert(accountCartItem: AccountCartItem): Promise<void>;
9
8
  update(accountCartItem: AccountCartItem): Promise<void>;
10
9
  private bindParams;
@@ -1,22 +1,13 @@
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) {
5
- const query = this.createQuery(SQL.accountCart.selectAll);
6
- query.bindParameter('account_id', accountId);
4
+ async select(queryOptions) {
5
+ const query = this.createQuery(SQL.accountCart.select, queryOptions);
7
6
  const result = await query.execute();
8
7
  return result.getRows();
9
8
  }
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) {
18
- const query = this.createQuery(SQL.accountCart.delete);
19
- this.bindParams(query, accountId, productId);
9
+ async delete(queryOptions) {
10
+ const query = this.createQuery(SQL.accountCart.delete, queryOptions);
20
11
  await query.execute();
21
12
  }
22
13
  async insert(accountCartItem) {
@@ -0,0 +1,5 @@
1
+ import { QueryOptions, Table } from '@dascompany/database';
2
+ import MarketPlaceRow from '../../types/rows/MarketPlaceRow';
3
+ export default class MarketPlacesTable extends Table {
4
+ select(queryOptions: QueryOptions): Promise<MarketPlaceRow[]>;
5
+ }
@@ -0,0 +1,9 @@
1
+ import { Table } from '@dascompany/database';
2
+ import * as SQL from '../../SQL.json';
3
+ export default class MarketPlacesTable extends Table {
4
+ async select(queryOptions) {
5
+ const query = this.createQuery(SQL.marketPlaces.select, queryOptions);
6
+ const result = await query.execute();
7
+ return result.getRows();
8
+ }
9
+ }
@@ -0,0 +1,6 @@
1
+ export default interface MarketPlaceRow {
2
+ id: string;
3
+ country: string;
4
+ language: string;
5
+ vat_rate: string;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,6 @@
1
+ import { QueryOptions } from "@dascompany/database";
1
2
  export default class AccountCart {
2
- static delete(accountId: string, productId: string): Promise<boolean>;
3
+ static delete(queryOptions: QueryOptions): Promise<boolean>;
3
4
  static insert(accountId: string, productId: string, installation: boolean, quantity: number): Promise<boolean>;
4
5
  static update(accountId: string, productId: string, installation: boolean, quantity: number): Promise<boolean>;
5
6
  }
@@ -1,8 +1,10 @@
1
1
  import DatabaseConnection from "../DatabaseConnection";
2
2
  import AccountCartItem from "../stockObjects/AccountCartItem.ts";
3
3
  export default class AccountCart {
4
- static async delete(accountId, productId) {
5
- await DatabaseConnection.getInstance().accountCart.delete(accountId, productId);
4
+ static async delete(queryOptions) {
5
+ if (!queryOptions.getWhere()?.parameters.length)
6
+ throw new Error("you can't delete table elements without query options where");
7
+ await DatabaseConnection.getInstance().accountCart.delete(queryOptions);
6
8
  return true;
7
9
  }
8
10
  static async insert(accountId, productId, installation, quantity) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dascompany/product",
3
- "version": "4.2.2",
3
+ "version": "4.2.4",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "vitest",