@dascompany/database 0.0.5 → 0.0.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.
package/dist/SQL.json CHANGED
@@ -82,9 +82,13 @@
82
82
  "selectNextId": "SELECT nextval('orders.orders_id'::regclass)"
83
83
  },
84
84
  "ordersProducts": {
85
- "selectForOrder": "SELECT id, order_id, product_id, net_price FROM orders.orders_products WHERE order_id = $order_id::BIGINT AND in_order = true",
86
- "insert": "INSERT INTO orders.orders_products( id, order_id, product_id, net_price ) VALUES ($id::BIGINT, $order_id::BIGINT, $product_id::BIGINT, $net_price::DOUBLE PRECISION )",
87
- "selectNextId": "SELECT nextval('orders.orders_products_id'::regclass)"
85
+ "selectProducts": "SELECT op.id, order_id, product_id, title, sku, p.file_id, op.net_price FROM orders.orders_products as op JOIN products as p ON op.product_id = p.id WHERE order_id = $order_id::BIGINT AND in_order = true",
86
+ "select": "SELECT id, order_id, product_id, in_order FROM orders.orders_products WHERE order_id = $order_id::BIGINT AND in_order = true",
87
+ "selectAll": "SELECT * FROM orders.orders_products $WHERE",
88
+ "getAllActiveForOrderId": "SELECT * FROM orders.orders_products WHERE order_id = $order_id::BIGINT and in_order = true",
89
+ "insert": "INSERT INTO orders.orders_products( id, order_id, product_id, net_price ) VALUES ( $id::BIGINT , $order_id::BIGINT, $product_id::BIGINT, $net_price::DOUBLE PRECISION )",
90
+ "selectNextId": "SELECT nextval('orders.orders_products_id'::regclass)",
91
+ "delete": "UPDATE orders.orders_products SET in_order = false WHERE id = $id::BIGINT"
88
92
  },
89
93
  "statuses": {
90
94
  "selectForOrder": "SELECT s.id, order_id, created_at, user_id, st.key as type FROM orders.statuses as s JOIN orders.status_types as st ON s.type = st.id WHERE order_id = $order_id::BIGINT ORDER BY s.id DESC LIMIT 1",
package/dist/index.d.ts CHANGED
@@ -46,7 +46,6 @@ import AdminRepo from './repo/AdminRepo';
46
46
  import TableConnection from './TableConnection';
47
47
  import ParameterType from './types/parameters/ParameterType';
48
48
  import DeliveryStatusReader from './reader/DeliveryStatusReader';
49
- import FileConnectionE from './types/FileConnectionE';
50
49
  import ConnectorE from './types/ConnectorE';
51
50
  import ParameterI from './types/ParameterI';
52
51
  import QueryOptionsI from './types/QueryOptionsI';
@@ -62,4 +61,8 @@ import FileConnectionsRepo from "./repo/FileConnectionsRepo";
62
61
  import CompanyDataReader from "./reader/CompanyDataReader";
63
62
  import OrderByI from "./utils/OrderByI";
64
63
  import FilesRepo from './repo/FilesRepo';
65
- export { TableConnection, DatabaseConnection, OrderByI, ParameterType, ConnectorE, FileConnectionE, PaymentStatusE, Parameters, ParameterI, QueryOptionsI, ResultLimitationI, OrderProductI, ParameterFilter, PaymentDetailsReader, FilesReader, PaymentMethodReader, DeliveryStatusReader, PaymentStatusesReader, AddressesReader, ClientAccountReader, CompanyDetailsReader, ContactDetailsReader, DeliveryDetailsReader, DeliveryMethodReader, InvoiceDetailsReader, OrderProductsReader, OrderReader, OrderStatusReader, PersonalDataReader, ProductReader, StatusTypesReader, FileConnectionsReader, CompanyDataReader, DeliveryMethodRepo, AdminRepo, PaymentDetailsRepo, AddressesRepo, ClientAccountRepo, CompanyDetailsRepo, ContactDetailsRepo, DeliveryDetailsRepo, CompanyDataRepo, InvoiceDetailsRepo, OrderRepo, PersonalDataRepo, PaymentMethodRepo, ProductRepo, FileConnectionsRepo, FilesRepo, Address, Admin, Client, CompanyDetails, ContactDetails, DeliveryDetails, InvoiceDetails, DeliveryStatus, Order, OrderProduct, PaymentDetails, PaymentStatus, PersonalData, Product, Status, };
64
+ import File from './stockObjects/File';
65
+ import QueryOptions from './query/QueryOptions';
66
+ import OrderProductsRepo from "./repo/OrderProductsRepo";
67
+ import FileConnectionTypeE from './types/FileConnectionTypeE';
68
+ export { TableConnection, DatabaseConnection, File, OrderByI, ParameterType, ConnectorE, FileConnectionTypeE, PaymentStatusE, Parameters, ParameterI, QueryOptions, QueryOptionsI, ResultLimitationI, OrderProductI, ParameterFilter, PaymentDetailsReader, FilesReader, PaymentMethodReader, DeliveryStatusReader, PaymentStatusesReader, AddressesReader, ClientAccountReader, CompanyDetailsReader, ContactDetailsReader, DeliveryDetailsReader, DeliveryMethodReader, InvoiceDetailsReader, OrderProductsReader, OrderReader, OrderStatusReader, PersonalDataReader, ProductReader, StatusTypesReader, FileConnectionsReader, CompanyDataReader, DeliveryMethodRepo, AdminRepo, PaymentDetailsRepo, AddressesRepo, ClientAccountRepo, CompanyDetailsRepo, ContactDetailsRepo, DeliveryDetailsRepo, CompanyDataRepo, InvoiceDetailsRepo, OrderRepo, PersonalDataRepo, PaymentMethodRepo, ProductRepo, FileConnectionsRepo, FilesRepo, OrderProductsRepo, Address, Admin, Client, CompanyDetails, ContactDetails, DeliveryDetails, InvoiceDetails, DeliveryStatus, Order, OrderProduct, PaymentDetails, PaymentStatus, PersonalData, Product, Status, };
package/dist/index.js CHANGED
@@ -46,7 +46,6 @@ import AdminRepo from './repo/AdminRepo';
46
46
  import TableConnection from './TableConnection';
47
47
  import ParameterType from './types/parameters/ParameterType';
48
48
  import DeliveryStatusReader from './reader/DeliveryStatusReader';
49
- import FileConnectionE from './types/FileConnectionE';
50
49
  import ConnectorE from './types/ConnectorE';
51
50
  import PaymentStatusE from './types/PaymentStatusE';
52
51
  import Parameters from './utils/Parameters';
@@ -56,4 +55,8 @@ import FileConnectionsReader from "./reader/FileConnectionsReader";
56
55
  import FileConnectionsRepo from "./repo/FileConnectionsRepo";
57
56
  import CompanyDataReader from "./reader/CompanyDataReader";
58
57
  import FilesRepo from './repo/FilesRepo';
59
- export { TableConnection, DatabaseConnection, ParameterType, ConnectorE, FileConnectionE, PaymentStatusE, Parameters, PaymentDetailsReader, FilesReader, PaymentMethodReader, DeliveryStatusReader, PaymentStatusesReader, AddressesReader, ClientAccountReader, CompanyDetailsReader, ContactDetailsReader, DeliveryDetailsReader, DeliveryMethodReader, InvoiceDetailsReader, OrderProductsReader, OrderReader, OrderStatusReader, PersonalDataReader, ProductReader, StatusTypesReader, FileConnectionsReader, CompanyDataReader, DeliveryMethodRepo, AdminRepo, PaymentDetailsRepo, AddressesRepo, ClientAccountRepo, CompanyDetailsRepo, ContactDetailsRepo, DeliveryDetailsRepo, CompanyDataRepo, InvoiceDetailsRepo, OrderRepo, PersonalDataRepo, PaymentMethodRepo, ProductRepo, FileConnectionsRepo, FilesRepo, Address, Admin, Client, CompanyDetails, ContactDetails, DeliveryDetails, InvoiceDetails, DeliveryStatus, Order, OrderProduct, PaymentDetails, PaymentStatus, PersonalData, Product, Status, };
58
+ import File from './stockObjects/File';
59
+ import QueryOptions from './query/QueryOptions';
60
+ import OrderProductsRepo from "./repo/OrderProductsRepo";
61
+ import FileConnectionTypeE from './types/FileConnectionTypeE';
62
+ export { TableConnection, DatabaseConnection, File, ParameterType, ConnectorE, FileConnectionTypeE, PaymentStatusE, Parameters, QueryOptions, PaymentDetailsReader, FilesReader, PaymentMethodReader, DeliveryStatusReader, PaymentStatusesReader, AddressesReader, ClientAccountReader, CompanyDetailsReader, ContactDetailsReader, DeliveryDetailsReader, DeliveryMethodReader, InvoiceDetailsReader, OrderProductsReader, OrderReader, OrderStatusReader, PersonalDataReader, ProductReader, StatusTypesReader, FileConnectionsReader, CompanyDataReader, DeliveryMethodRepo, AdminRepo, PaymentDetailsRepo, AddressesRepo, ClientAccountRepo, CompanyDetailsRepo, ContactDetailsRepo, DeliveryDetailsRepo, CompanyDataRepo, InvoiceDetailsRepo, OrderRepo, PersonalDataRepo, PaymentMethodRepo, ProductRepo, FileConnectionsRepo, FilesRepo, OrderProductsRepo, Address, Admin, Client, CompanyDetails, ContactDetails, DeliveryDetails, InvoiceDetails, DeliveryStatus, Order, OrderProduct, PaymentDetails, PaymentStatus, PersonalData, Product, Status, };
@@ -13,6 +13,8 @@ export default class ProductMapper {
13
13
  await this.productTable.insert(this.product);
14
14
  }
15
15
  async delete() {
16
- await this.productTable.delete(this.product.getId());
16
+ const id = this.product.getId();
17
+ if (id)
18
+ await this.productTable.delete(id);
17
19
  }
18
20
  }
@@ -20,7 +20,7 @@ export default class CompanyDataReader {
20
20
  name: '',
21
21
  taxNumber: '',
22
22
  phoneNumber: '',
23
- address: {}
23
+ address: null
24
24
  };
25
25
  }
26
26
  }
@@ -1,4 +1,4 @@
1
- import FileConnectionE from "../types/FileConnectionE";
1
+ import FileConnectionTypeE from "../types/FileConnectionTypeE";
2
2
  import FileI from "../types/FileI";
3
3
  import QueryOptionsI from "../types/QueryOptionsI";
4
4
  export default class FilesReader {
@@ -6,7 +6,7 @@ export default class FilesReader {
6
6
  static getAll(queryOptions: QueryOptionsI): Promise<FileI[]>;
7
7
  static isExist(queryOptions: QueryOptionsI): Promise<number>;
8
8
  static getQuantity(queryOptions: any): Promise<number>;
9
- static getForConnection(connectionType: FileConnectionE, connectionId: number): Promise<FileI[]>;
9
+ static getForConnection(connectionType: FileConnectionTypeE, connectionId: number): Promise<FileI[]>;
10
10
  private static correctFiles;
11
11
  private static correctFile;
12
12
  }
@@ -1,6 +1,6 @@
1
1
  import OrderProductI from "../types/OrderProductI";
2
2
  export default class OrderProductsReader {
3
- static getForOrder(orderId: number): Promise<OrderProductI[]>;
3
+ static getForOrder(orderId: number): Promise<any[]>;
4
4
  static getAll(orderId: number): Promise<OrderProductI[]>;
5
5
  private static correctProduct;
6
6
  }
@@ -2,10 +2,11 @@ import ProductI from "../types/ProductI";
2
2
  import QueryOptionsI from "../types/QueryOptionsI";
3
3
  export default class ProductReader {
4
4
  static get(productId: number): Promise<ProductI>;
5
+ static getIdForSku(productSku: string): Promise<number>;
5
6
  static getForUrl(productUrl: string): Promise<ProductI>;
6
- static getListForOrder(): Promise<any>;
7
7
  static getAll(queryOptions: QueryOptionsI): Promise<ProductI[]>;
8
8
  static getQuantity(queryOptions: QueryOptionsI): Promise<number>;
9
+ static getListForOrder(): Promise<any>;
9
10
  private static correctProducts;
10
11
  private static correctProduct;
11
12
  private static correctProductForOrderList;
@@ -1,17 +1,34 @@
1
1
  import DatabaseConnection from "../DatabaseConnection";
2
+ import FileConnectionTypeE from "../types/FileConnectionTypeE";
2
3
  import calculateNetToGrossPrice from "../utils/calculateNetToGrossPrice";
3
4
  import FilesReader from "./FilesReader";
4
5
  export default class ProductReader {
5
6
  static async get(productId) {
6
7
  const connection = DatabaseConnection.get();
7
8
  const product = await connection.products.select(productId);
8
- return this.correctProduct(product);
9
+ const thumbnail = await FilesReader.get(product.file_id);
10
+ const files = await FilesReader.getForConnection(FileConnectionTypeE.product, product.id);
11
+ return this.correctProduct(product, thumbnail, files);
12
+ }
13
+ static async getIdForSku(productSku) {
14
+ const connection = DatabaseConnection.get();
15
+ return await connection.products.selectIdForSku(productSku);
9
16
  }
10
17
  static async getForUrl(productUrl) {
11
18
  const connection = DatabaseConnection.get();
12
19
  const product = await connection.products.selectForUrl(productUrl);
13
20
  return this.correctProduct(product);
14
21
  }
22
+ static async getAll(queryOptions) {
23
+ const connection = DatabaseConnection.get();
24
+ const products = await connection.products.selectAll(queryOptions);
25
+ return this.correctProducts(products);
26
+ }
27
+ static async getQuantity(queryOptions) {
28
+ const connection = DatabaseConnection.get();
29
+ const quantity = await connection.products.count(queryOptions);
30
+ return quantity;
31
+ }
15
32
  static async getListForOrder() {
16
33
  const connection = DatabaseConnection.get();
17
34
  let correctProducts = [];
@@ -23,16 +40,6 @@ export default class ProductReader {
23
40
  }
24
41
  return correctProducts;
25
42
  }
26
- static async getAll(queryOptions) {
27
- const connection = DatabaseConnection.get();
28
- const products = await connection.products.selectAll(queryOptions);
29
- return this.correctProducts(products);
30
- }
31
- static async getQuantity(queryOptions) {
32
- const connection = DatabaseConnection.get();
33
- const quantity = await connection.products.count(queryOptions);
34
- return quantity;
35
- }
36
43
  static correctProducts(products) {
37
44
  const correctProducts = [];
38
45
  for (let i = 0; i < products.length; i++) {
@@ -41,7 +48,7 @@ export default class ProductReader {
41
48
  }
42
49
  return correctProducts;
43
50
  }
44
- static correctProduct(product) {
51
+ static correctProduct(product, thumbnail, files) {
45
52
  return {
46
53
  id: product.id,
47
54
  sku: product.sku,
@@ -55,9 +62,10 @@ export default class ProductReader {
55
62
  width: product.width,
56
63
  height: product.height,
57
64
  length: product.length,
58
- fileId: product.file_id,
59
65
  createdAt: product.created_at,
60
66
  deleted: product.deleted,
67
+ thumbnail: thumbnail ? thumbnail : null,
68
+ files: files,
61
69
  grossPrice: calculateNetToGrossPrice(product.net_price, product.vat)
62
70
  };
63
71
  }
@@ -1,7 +1,7 @@
1
- import FileConnectionE from "../types/FileConnectionE";
1
+ import FileConnectionTypeE from "../types/FileConnectionTypeE";
2
2
  export default class FilesRepo {
3
3
  static get(fileId: number): Promise<any>;
4
- static getAllForConnection(connectionType: FileConnectionE, connectionId: number): Promise<any>;
4
+ static getAllForConnection(connectionType: FileConnectionTypeE, connectionId: number): Promise<any>;
5
5
  private static createFilesFromRows;
6
6
  private static createFileFromRow;
7
7
  }
@@ -0,0 +1,7 @@
1
+ import OrderProduct from "../stockObjects/OrderProduct";
2
+ export default class OrderProductsRepo {
3
+ static getAllActiveForOrderId(orderId: number): Promise<OrderProduct[]>;
4
+ static getAllForIds(orderProductsIds: number[]): Promise<OrderProduct[]>;
5
+ private static createOrdersProductsFromRows;
6
+ private static createOrdersProductFromRow;
7
+ }
@@ -0,0 +1,37 @@
1
+ import DatabaseConnection from "../DatabaseConnection";
2
+ import OrderProduct from "../stockObjects/OrderProduct";
3
+ import ConnectorE from "../types/ConnectorE";
4
+ import ParameterType from "../types/parameters/ParameterType";
5
+ export default class OrderProductsRepo {
6
+ static async getAllActiveForOrderId(orderId) {
7
+ const connection = DatabaseConnection.get();
8
+ const orderProducts = await connection.ordersProducts.selectAll(orderId);
9
+ return this.createOrdersProductsFromRows(orderProducts);
10
+ }
11
+ static async getAllForIds(orderProductsIds) {
12
+ const connection = DatabaseConnection.get();
13
+ const queryOptions = {
14
+ where: {
15
+ connector: ConnectorE.and,
16
+ parameters: [
17
+ { name: 'id', type: ParameterType.arrayBigint, value: orderProductsIds },
18
+ ]
19
+ }
20
+ };
21
+ const orderProducts = await connection.ordersProducts.selectAllForIds(queryOptions);
22
+ return this.createOrdersProductsFromRows(orderProducts);
23
+ }
24
+ static async createOrdersProductsFromRows(dataRows) {
25
+ const products = [];
26
+ for (const dataRow of dataRows) {
27
+ const product = await this.createOrdersProductFromRow(dataRow);
28
+ products.push(product);
29
+ }
30
+ return products;
31
+ }
32
+ static async createOrdersProductFromRow(dataRow) {
33
+ const orderProduct = new OrderProduct(dataRow.order_id, dataRow.product_id, dataRow.net_price, dataRow.in_order);
34
+ orderProduct.setId(dataRow.id);
35
+ return orderProduct;
36
+ }
37
+ }
@@ -36,5 +36,6 @@ export default class Order extends StockObject {
36
36
  setInvoiceDetailsId(invoiceDetailsId: number): void;
37
37
  setPaymentDetailsId(paymentDetailsId: number): void;
38
38
  setZsiId(zsiId: number): void;
39
+ calculateAndUpdatePrice(): Promise<void>;
39
40
  protected getMapper(): StockObjectMapper;
40
41
  }
@@ -1,4 +1,5 @@
1
1
  import OrderMapper from "../mappers/OrderMapper";
2
+ import OrderProductsRepo from "../repo/OrderProductsRepo";
2
3
  import StockObject from "../types/StockObject";
3
4
  import calculateNetToGrossPrice from "../utils/calculateNetToGrossPrice";
4
5
  export default class Order extends StockObject {
@@ -82,6 +83,14 @@ export default class Order extends StockObject {
82
83
  setZsiId(zsiId) {
83
84
  this.zsiId = zsiId;
84
85
  }
86
+ async calculateAndUpdatePrice() {
87
+ let totalPrice = 0;
88
+ const orderProducts = await OrderProductsRepo.getAllActiveForOrderId(this.getId());
89
+ for (const product of orderProducts) {
90
+ totalPrice += product.getNetPrice();
91
+ }
92
+ this.setPrice(totalPrice);
93
+ }
85
94
  getMapper() {
86
95
  return new OrderMapper(this);
87
96
  }
@@ -5,7 +5,7 @@ export default class OrderProduct extends StockObject {
5
5
  private productId;
6
6
  private netPrice;
7
7
  private inOrder;
8
- constructor(orderId: number, productId: number, netPrice: number);
8
+ constructor(orderId: number, productId: number, netPrice: number, inOrder: boolean);
9
9
  getOrderId(): number;
10
10
  getProductId(): number;
11
11
  getNetPrice(): number;
@@ -5,12 +5,12 @@ export default class OrderProduct extends StockObject {
5
5
  productId;
6
6
  netPrice;
7
7
  inOrder;
8
- constructor(orderId, productId, netPrice) {
8
+ constructor(orderId, productId, netPrice, inOrder) {
9
9
  super();
10
10
  this.orderId = orderId;
11
11
  this.productId = productId;
12
12
  this.netPrice = netPrice;
13
- this.inOrder = true;
13
+ this.inOrder = inOrder;
14
14
  }
15
15
  getOrderId() {
16
16
  return this.orderId;
@@ -1,6 +1,6 @@
1
1
  import ProductMapper from "../mappers/ProductMapper";
2
2
  import FilesReader from "../reader/FilesReader";
3
- import FileConnectionE from "../types/FileConnectionE";
3
+ import FileConnectionTypeE from "../types/FileConnectionTypeE";
4
4
  import StockObject from "../types/StockObject";
5
5
  import calculateNetToGrossPrice from "../utils/calculateNetToGrossPrice";
6
6
  export default class Product extends StockObject {
@@ -90,7 +90,7 @@ export default class Product extends StockObject {
90
90
  if (!this.files) {
91
91
  const id = this.getId();
92
92
  if (id) {
93
- const files = await FilesReader.getForConnection(FileConnectionE.product, id);
93
+ const files = await FilesReader.getForConnection(FileConnectionTypeE.product, id);
94
94
  this.files = files;
95
95
  }
96
96
  }
@@ -1,9 +1,9 @@
1
1
  import Table from '../../Table';
2
- import FileConnectionE from '../../types/FileConnectionE';
2
+ import FileConnectionTypeE from '../../types/FileConnectionTypeE';
3
3
  import FileConnection from '../../stockObjects/FileConnection';
4
4
  import FileConnectionRow from '../../types/rows/FileConnectionRow';
5
5
  export default class FileConnectionsTable extends Table {
6
- select(connectionType: FileConnectionE, connection_id: number): Promise<any[]>;
6
+ select(connectionType: FileConnectionTypeE, connection_id: number): Promise<any[]>;
7
7
  selectForFileId(fileId: number): Promise<FileConnectionRow[]>;
8
8
  insert(fileConnection: FileConnection): Promise<void>;
9
9
  delete(fileId: number): Promise<boolean>;
@@ -1,13 +1,13 @@
1
1
  import Table from '../../Table';
2
2
  import FileRow from '../../types/rows/FileRow';
3
- import FileConnectionE from '../../types/FileConnectionE';
3
+ import FileConnectionTypeE from '../../types/FileConnectionTypeE';
4
4
  import QueryOptionsI from '../../types/QueryOptionsI';
5
5
  import File from '../../stockObjects/File';
6
6
  export default class FilesTable extends Table {
7
7
  selectId(queryOptions: QueryOptionsI): Promise<number>;
8
8
  selectAll(queryOptions: QueryOptionsI): Promise<FileRow[]>;
9
9
  select(fileId: number): Promise<FileRow>;
10
- selectForConnection(connectionType: FileConnectionE, connectionId: number): Promise<FileRow[]>;
10
+ selectForConnection(connectionType: FileConnectionTypeE, connectionId: number): Promise<FileRow[]>;
11
11
  insert(file: File): Promise<boolean>;
12
12
  update(fileData: File): Promise<boolean>;
13
13
  count(queryOptions: QueryOptionsI): Promise<number>;
@@ -1,8 +1,12 @@
1
1
  import Table from '../../Table';
2
2
  import OrderProductRow from '../../types/rows/OrderProductRow';
3
3
  import OrderProduct from '../../stockObjects/OrderProduct';
4
+ import QueryOptionsI from '../../types/QueryOptionsI';
4
5
  export default class OrdersProductsTable extends Table {
5
6
  selectAll(orderId: number): Promise<OrderProductRow[]>;
6
- insert(orderProduct: OrderProduct): Promise<void>;
7
+ selectAllForIds(queryOprions: QueryOptionsI): Promise<OrderProduct[]>;
8
+ delete(orderProduct: OrderProduct): Promise<boolean>;
9
+ private bindParams;
10
+ insert(orderProduct: OrderProduct): Promise<boolean>;
7
11
  private selectNextId;
8
12
  }
@@ -2,20 +2,37 @@ import Table from '../../Table';
2
2
  import * as SQL from '../../SQL.json';
3
3
  export default class OrdersProductsTable extends Table {
4
4
  async selectAll(orderId) {
5
- const query = this.createQuery(SQL.ordersProducts.selectForOrder);
5
+ const query = this.createQuery(SQL.ordersProducts.getAllActiveForOrderId);
6
6
  query.bindParameter('order_id', orderId);
7
- const results = await query.execute();
8
- return results.getRows();
7
+ const result = await query.execute();
8
+ return result.getRows();
9
9
  }
10
- async insert(orderProduct) {
11
- const id = await this.selectNextId();
12
- const query = this.createQuery(SQL.ordersProducts.insert);
10
+ async selectAllForIds(queryOprions) {
11
+ const query = this.createQuery(SQL.ordersProducts.selectAll, queryOprions);
12
+ const result = await query.execute();
13
+ return result.getRows();
14
+ }
15
+ async delete(orderProduct) {
16
+ const query = this.createQuery(SQL.ordersProducts.delete);
17
+ const id = orderProduct.getId();
13
18
  query.bindParameter('id', id);
19
+ await query.execute();
20
+ return true;
21
+ }
22
+ bindParams(query, orderProduct) {
14
23
  query.bindParameter('order_id', orderProduct.getOrderId());
15
24
  query.bindParameter('product_id', orderProduct.getProductId());
16
25
  query.bindParameter('net_price', orderProduct.getNetPrice());
26
+ query.bindParameter('in_order', orderProduct.getInOrder());
27
+ }
28
+ async insert(orderProduct) {
29
+ const query = this.createQuery(SQL.ordersProducts.insert);
30
+ const id = await this.selectNextId();
31
+ query.bindParameter('id', id);
32
+ this.bindParams(query, orderProduct);
17
33
  await query.execute();
18
34
  orderProduct.setId(id);
35
+ return true;
19
36
  }
20
37
  async selectNextId() {
21
38
  const query = this.createQuery(SQL.ordersProducts.selectNextId);
@@ -4,5 +4,5 @@ export default interface CompanyDataI {
4
4
  name: string;
5
5
  taxNumber: string;
6
6
  phoneNumber: string;
7
- address: AddressI;
7
+ address: AddressI | null;
8
8
  }
@@ -0,0 +1,4 @@
1
+ declare enum FileConnectionTypeE {
2
+ product = "product"
3
+ }
4
+ export default FileConnectionTypeE;
@@ -0,0 +1,5 @@
1
+ var FileConnectionTypeE;
2
+ (function (FileConnectionTypeE) {
3
+ FileConnectionTypeE["product"] = "product";
4
+ })(FileConnectionTypeE || (FileConnectionTypeE = {}));
5
+ export default FileConnectionTypeE;
@@ -1,9 +1,15 @@
1
1
  import FileI from "./FileI";
2
2
  export default interface OrderProductI {
3
- orderProductId: number;
4
3
  id: number;
5
- netPrice: number;
6
- title: string;
7
- sku: string;
8
- file: FileI;
4
+ productId: number;
5
+ orderId: number;
6
+ product: {
7
+ id: number;
8
+ sku: string;
9
+ title: string;
10
+ netPrice: number;
11
+ grossPrice: number;
12
+ vat: number;
13
+ file: FileI;
14
+ };
9
15
  }
@@ -14,6 +14,7 @@ export default interface ProductI {
14
14
  length: number;
15
15
  height: number;
16
16
  fileId: number;
17
+ thumbnail: FileI | null;
17
18
  createdAt: string;
18
19
  deleted: boolean;
19
20
  file?: FileI;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dascompany/database",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "vitest",
@@ -1,4 +0,0 @@
1
- declare enum FileConnectionE {
2
- product = "product"
3
- }
4
- export default FileConnectionE;
@@ -1,5 +0,0 @@
1
- var FileConnectionE;
2
- (function (FileConnectionE) {
3
- FileConnectionE["product"] = "product";
4
- })(FileConnectionE || (FileConnectionE = {}));
5
- export default FileConnectionE;