@dascompany/product 2.1.11 → 2.1.13

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
@@ -78,7 +78,7 @@
78
78
  "delete": "UPDATE orders.orders_products SET in_order = false WHERE id = $id::BIGINT"
79
79
  },
80
80
  "statuses": {
81
- "select": "SELECT s.id, s.order_id, created_at, user_id, s.type as type_id, st.key as type_name FROM orders.statuses as s JOIN orders.status_types as st ON s.type = st.id",
81
+ "select": "SELECT * FROM orders.statuses",
82
82
  "insert": "INSERT INTO orders.statuses( id, type, order_id, user_id ) VALUES ($id::BIGINT, $type::BIGINT, $order_id::BIGINT, $user_id::BIGINT)",
83
83
  "selectNextId": "SELECT nextval('orders.statuses_id'::regclass)"
84
84
  },
@@ -10,6 +10,10 @@ export default class OrderProductMapper {
10
10
  await this.orderProductsTable.insert(this.orderProduct);
11
11
  }
12
12
  async delete() {
13
- throw Error('NOT IMPLEMENTED');
13
+ const orderId = this.orderProduct.getId();
14
+ if (orderId)
15
+ await this.orderProductsTable.delete(orderId);
16
+ else
17
+ throw new Error('Can`t remove the order and product connection without providing its ID');
14
18
  }
15
19
  }
@@ -1,3 +1,5 @@
1
+ import { QueryOptions } from "@dascompany/database";
1
2
  export default class StatusTypesReader {
2
- static get(): Promise<any[]>;
3
+ static get(queryOptions: QueryOptions): Promise<any[]>;
4
+ static getAll(queryOptions?: QueryOptions): Promise<any[]>;
3
5
  }
@@ -1,7 +1,11 @@
1
1
  import DatabaseConnection from "../DatabaseConnection";
2
2
  export default class StatusTypesReader {
3
- static async get() {
4
- const statusTypes = await DatabaseConnection.getInstance().statusTypes.select();
3
+ static async get(queryOptions) {
4
+ const statusTypes = await DatabaseConnection.getInstance().statusTypes.select(queryOptions);
5
+ return statusTypes;
6
+ }
7
+ static async getAll(queryOptions) {
8
+ const statusTypes = await DatabaseConnection.getInstance().statusTypes.selectAll(queryOptions);
5
9
  return statusTypes;
6
10
  }
7
11
  }
@@ -88,7 +88,7 @@ export default class Order extends StockObject {
88
88
  if (id) {
89
89
  let totalPrice = 0;
90
90
  const queryOptions = new QueryOptions();
91
- queryOptions.setWhere([{ name: 'id', type: ParameterType.bigint, value: id }]);
91
+ queryOptions.setWhere([{ name: 'op.id', type: ParameterType.bigint, value: id }]);
92
92
  const orderProducts = await OrderProductsRepo.getAll(queryOptions);
93
93
  for (const product of orderProducts) {
94
94
  totalPrice += product.getNetPrice();
@@ -4,7 +4,7 @@ import OrderProduct from '../../stockObjects/OrderProduct';
4
4
  export default class OrdersProductsTable extends Table {
5
5
  selectAll(queryOptions?: QueryOptions): Promise<OrderProductRow[]>;
6
6
  insert(orderProduct: OrderProduct): Promise<boolean>;
7
- delete(orderProduct: OrderProduct): Promise<boolean>;
7
+ delete(id: number): Promise<boolean>;
8
8
  private selectNextId;
9
9
  private bindParams;
10
10
  }
@@ -15,9 +15,8 @@ export default class OrdersProductsTable extends Table {
15
15
  orderProduct.setId(id);
16
16
  return true;
17
17
  }
18
- async delete(orderProduct) {
18
+ async delete(id) {
19
19
  const query = this.createQuery(SQL.ordersProducts.delete);
20
- const id = orderProduct.getId();
21
20
  query.bindParameter('id', id);
22
21
  await query.execute();
23
22
  return true;
@@ -1,4 +1,5 @@
1
- import { Table } from '@dascompany/database';
1
+ import { QueryOptions, Table } from '@dascompany/database';
2
2
  export default class StatusTypesTable extends Table {
3
- select(): Promise<any[]>;
3
+ select(queryOptions: QueryOptions): Promise<any[]>;
4
+ selectAll(queryOptions?: QueryOptions): Promise<any[]>;
4
5
  }
@@ -1,8 +1,13 @@
1
1
  import { Table } from '@dascompany/database';
2
2
  import * as SQL from '../../SQL.json';
3
3
  export default class StatusTypesTable extends Table {
4
- async select() {
5
- const query = this.createQuery(SQL.statusTypes.select);
4
+ async select(queryOptions) {
5
+ const query = this.createQuery(SQL.statusTypes.select, queryOptions);
6
+ const result = await query.execute();
7
+ return result.getRow();
8
+ }
9
+ async selectAll(queryOptions) {
10
+ const query = this.createQuery(SQL.statusTypes.select, queryOptions);
6
11
  const result = await query.execute();
7
12
  return result.getRows();
8
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dascompany/product",
3
- "version": "2.1.11",
3
+ "version": "2.1.13",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "vitest",