@dascompany/database 0.0.4 → 0.0.5

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.
Files changed (36) hide show
  1. package/dist/SQL.json +8 -1
  2. package/dist/TableConnection.d.ts +6 -6
  3. package/dist/TableConnection.js +6 -6
  4. package/dist/index.d.ts +4 -1
  5. package/dist/index.js +3 -1
  6. package/dist/mappers/FileConnectionMapper.js +4 -4
  7. package/dist/mappers/FileMapper.d.ts +9 -0
  8. package/dist/mappers/FileMapper.js +17 -0
  9. package/dist/mappers/ProductMapper.d.ts +9 -0
  10. package/dist/mappers/ProductMapper.js +18 -0
  11. package/dist/reader/FilesReader.d.ts +5 -0
  12. package/dist/reader/FilesReader.js +24 -5
  13. package/dist/repo/FilesRepo.d.ts +7 -0
  14. package/dist/repo/FilesRepo.js +26 -0
  15. package/dist/stockObjects/File.d.ts +21 -0
  16. package/dist/stockObjects/File.js +50 -0
  17. package/dist/stockObjects/Product.d.ts +30 -0
  18. package/dist/stockObjects/Product.js +60 -1
  19. package/dist/tables/{ClientAccountsTable.d.ts → clients/ClientAccountsTable.d.ts} +4 -4
  20. package/dist/tables/{ClientAccountsTable.js → clients/ClientAccountsTable.js} +2 -2
  21. package/dist/tables/files/FileConnectionsTable.d.ts +2 -2
  22. package/dist/tables/files/FilesTable.d.ts +10 -0
  23. package/dist/tables/files/FilesTable.js +48 -0
  24. package/dist/tables/{DeliveryStatusTypesTable.d.ts → personalInformation/DeliveryStatusTypesTable.d.ts} +1 -1
  25. package/dist/tables/{DeliveryStatusTypesTable.js → personalInformation/DeliveryStatusTypesTable.js} +2 -2
  26. package/dist/tables/{DeliveryStatusesTable.d.ts → personalInformation/DeliveryStatusesTable.d.ts} +3 -3
  27. package/dist/tables/{DeliveryStatusesTable.js → personalInformation/DeliveryStatusesTable.js} +2 -2
  28. package/dist/tables/{AdminAccountsTable.d.ts → public/AdminAccountsTable.d.ts} +4 -4
  29. package/dist/tables/{AdminAccountsTable.js → public/AdminAccountsTable.js} +2 -2
  30. package/dist/tables/{ProductsTable.d.ts → public/ProductsTable.d.ts} +4 -4
  31. package/dist/tables/{ProductsTable.js → public/ProductsTable.js} +2 -2
  32. package/package.json +1 -1
  33. package/dist/tables/StatusTypesTable.d.ts +0 -4
  34. package/dist/tables/StatusTypesTable.js +0 -9
  35. package/dist/types/FileConnectionTypeE.d.ts +0 -4
  36. package/dist/types/FileConnectionTypeE.js +0 -5
package/dist/SQL.json CHANGED
@@ -99,8 +99,15 @@
99
99
  "selectNextId": "SELECT nextval('orders.payment_details_id'::regclass)"
100
100
  },
101
101
  "files": {
102
+ "selectId": "SELECT id FROM files.files $WHERE",
103
+ "selectAll": "SELECT f.id, f.name, f.orginal_name, f.catalog, f.size_kb, f.type, f.created_at FROM files.files as f $WHERE $ORDERBY",
102
104
  "select": "SELECT id, name, orginal_name, catalog, size_kb, type, created_at FROM files.files WHERE id = $id::BIGINT",
103
- "selectForConnection": "SELECT id, name, catalog, type FROM files.files JOIN files.file_connections ON file_id = id WHERE connection_type = $connection_type::TEXT AND connection_id = $connection_id::BIGINT ORDER BY sequence"
105
+ "selectForConnection": "SELECT id, name, catalog, type FROM files.files JOIN files.file_connections ON file_id = id WHERE connection_type = $connection_type::TEXT AND connection_id = $connection_id::BIGINT ORDER BY sequence",
106
+ "selectNextId": "SELECT nextval('files.files_id'::regclass)",
107
+ "insert": "INSERT INTO files.files( id, name, orginal_name, catalog, size_kb, type, created_at ) VALUES ( $id::BIGINT, $name::TEXT, $orginal_name::TEXT, $catalog::TEXT, $size_kb::BIGINT, $type::TEXT, now() )",
108
+ "update": "UPDATE files.files SET name = $name::TEXT, orginal_name = $orginal_name::TEXT, catalog = $catalog::TEXT, size_kb = $size_kb::BIGINT, type = $type::TEXT WHERE id = $id::BIGINT ",
109
+ "count": "SELECT COUNT(*) AS total_rows FROM files.files as f $WHERE ",
110
+ "delete": "DELETE FROM files.files WHERE id = $id::BIGINT "
104
111
  },
105
112
  "fileConnections": {
106
113
  "select": "SELECT file_id, sequence FROM files.file_connections WHERE connection_type = $connection_type::BIGINT and connection_id = $connection_id::BIGINT",
@@ -3,12 +3,12 @@ import Connection from './Connection';
3
3
  import OrdersTable from './tables/orders/OrdersTable';
4
4
  import FilesTable from './tables/files/FilesTable';
5
5
  import StatusesTable from './tables/orders/StatusesTable';
6
- import ProductsTable from './tables/ProductsTable';
7
- import ClientAccountsTable from './tables/ClientAccountsTable';
6
+ import ProductsTable from './tables/public/ProductsTable';
7
+ import ClientAccountsTable from './tables/clients/ClientAccountsTable';
8
8
  import OrdersProductsTable from './tables/orders/OrdersProductsTable';
9
9
  import PaymentStatusTypesTable from './tables/orders/PaymentStatusTypesTable';
10
10
  import AddressesTable from './tables/personalInformation/AddressesTable';
11
- import DeliveryStatusTypesTable from './tables/DeliveryStatusTypesTable';
11
+ import DeliveryStatusTypesTable from './tables/personalInformation/DeliveryStatusTypesTable';
12
12
  import PaymentMethodsTable from './tables/settings/PaymentMethodsTable';
13
13
  import PersonalDataTable from './tables/personalInformation/PersonalDataTable';
14
14
  import DeliveryMethodsTable from './tables/settings/DeliveryMethodsTable';
@@ -16,11 +16,11 @@ import CompanyDetailsTable from './tables/personalInformation/CompanyDetailsTabl
16
16
  import ContactDetailsTable from './tables/personalInformation/ContactDetailsTable';
17
17
  import InvoiceDetailsTable from './tables/personalInformation/InvoiceDetailsTable';
18
18
  import DeliveryDetailsTable from './tables/personalInformation/DeliveryDetailsTable';
19
- import DeliveryStatusesTable from './tables/DeliveryStatusesTable';
19
+ import DeliveryStatusesTable from './tables/personalInformation/DeliveryStatusesTable';
20
20
  import PaymentDetailsTable from './tables/orders/PaymentDetailsTable';
21
21
  import PaymentStatusesTable from './tables/orders/PaymentStatusesTable';
22
- import AdminAccountsTable from './tables/AdminAccountsTable';
23
- import StatusTypesTable from './tables/StatusTypesTable';
22
+ import AdminAccountsTable from './tables/public/AdminAccountsTable';
23
+ import StatusTypesTable from './tables/orders/StatusTypesTable';
24
24
  import CompanyDataTable from './tables/settings/CompanyDataTable';
25
25
  import FileConnectionsTable from './tables/files/FileConnectionsTable';
26
26
  export default class TableConnection extends Connection {
@@ -2,12 +2,12 @@ import Connection from './Connection';
2
2
  import OrdersTable from './tables/orders/OrdersTable';
3
3
  import FilesTable from './tables/files/FilesTable';
4
4
  import StatusesTable from './tables/orders/StatusesTable';
5
- import ProductsTable from './tables/ProductsTable';
6
- import ClientAccountsTable from './tables/ClientAccountsTable';
5
+ import ProductsTable from './tables/public/ProductsTable';
6
+ import ClientAccountsTable from './tables/clients/ClientAccountsTable';
7
7
  import OrdersProductsTable from './tables/orders/OrdersProductsTable';
8
8
  import PaymentStatusTypesTable from './tables/orders/PaymentStatusTypesTable';
9
9
  import AddressesTable from './tables/personalInformation/AddressesTable';
10
- import DeliveryStatusTypesTable from './tables/DeliveryStatusTypesTable';
10
+ import DeliveryStatusTypesTable from './tables/personalInformation/DeliveryStatusTypesTable';
11
11
  import PaymentMethodsTable from './tables/settings/PaymentMethodsTable';
12
12
  import PersonalDataTable from './tables/personalInformation/PersonalDataTable';
13
13
  import DeliveryMethodsTable from './tables/settings/DeliveryMethodsTable';
@@ -15,11 +15,11 @@ import CompanyDetailsTable from './tables/personalInformation/CompanyDetailsTabl
15
15
  import ContactDetailsTable from './tables/personalInformation/ContactDetailsTable';
16
16
  import InvoiceDetailsTable from './tables/personalInformation/InvoiceDetailsTable';
17
17
  import DeliveryDetailsTable from './tables/personalInformation/DeliveryDetailsTable';
18
- import DeliveryStatusesTable from './tables/DeliveryStatusesTable';
18
+ import DeliveryStatusesTable from './tables/personalInformation/DeliveryStatusesTable';
19
19
  import PaymentDetailsTable from './tables/orders/PaymentDetailsTable';
20
20
  import PaymentStatusesTable from './tables/orders/PaymentStatusesTable';
21
- import AdminAccountsTable from './tables/AdminAccountsTable';
22
- import StatusTypesTable from './tables/StatusTypesTable';
21
+ import AdminAccountsTable from './tables/public/AdminAccountsTable';
22
+ import StatusTypesTable from './tables/orders/StatusTypesTable';
23
23
  import CompanyDataTable from './tables/settings/CompanyDataTable';
24
24
  import FileConnectionsTable from './tables/files/FileConnectionsTable';
25
25
  export default class TableConnection extends Connection {
package/dist/index.d.ts CHANGED
@@ -59,4 +59,7 @@ import DeliveryMethodRepo from './repo/DeliveryMethodRepo';
59
59
  import StatusTypesReader from './reader/StatusTypesReader';
60
60
  import FileConnectionsReader from "./reader/FileConnectionsReader";
61
61
  import FileConnectionsRepo from "./repo/FileConnectionsRepo";
62
- export { TableConnection, DatabaseConnection, 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, DeliveryMethodRepo, AdminRepo, PaymentDetailsRepo, AddressesRepo, ClientAccountRepo, CompanyDetailsRepo, ContactDetailsRepo, DeliveryDetailsRepo, CompanyDataRepo, InvoiceDetailsRepo, OrderRepo, PersonalDataRepo, PaymentMethodRepo, ProductRepo, FileConnectionsRepo, Address, Admin, Client, CompanyDetails, ContactDetails, DeliveryDetails, InvoiceDetails, DeliveryStatus, Order, OrderProduct, PaymentDetails, PaymentStatus, PersonalData, Product, Status, };
62
+ import CompanyDataReader from "./reader/CompanyDataReader";
63
+ import OrderByI from "./utils/OrderByI";
64
+ 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, };
package/dist/index.js CHANGED
@@ -54,4 +54,6 @@ import DeliveryMethodRepo from './repo/DeliveryMethodRepo';
54
54
  import StatusTypesReader from './reader/StatusTypesReader';
55
55
  import FileConnectionsReader from "./reader/FileConnectionsReader";
56
56
  import FileConnectionsRepo from "./repo/FileConnectionsRepo";
57
- 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, DeliveryMethodRepo, AdminRepo, PaymentDetailsRepo, AddressesRepo, ClientAccountRepo, CompanyDetailsRepo, ContactDetailsRepo, DeliveryDetailsRepo, CompanyDataRepo, InvoiceDetailsRepo, OrderRepo, PersonalDataRepo, PaymentMethodRepo, ProductRepo, FileConnectionsRepo, Address, Admin, Client, CompanyDetails, ContactDetails, DeliveryDetails, InvoiceDetails, DeliveryStatus, Order, OrderProduct, PaymentDetails, PaymentStatus, PersonalData, Product, Status, };
57
+ import CompanyDataReader from "./reader/CompanyDataReader";
58
+ 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, };
@@ -7,10 +7,10 @@ export default class FileConnectionMapper {
7
7
  this.fileConnection = fileConnection;
8
8
  }
9
9
  async save() {
10
- if (this.fileConnection.getId())
11
- await this.fileConnectionsTable.update(this.fileConnection);
12
- else
13
- await this.fileConnectionsTable.insert(this.fileConnection);
10
+ const id = this.fileConnection.getId();
11
+ if (id)
12
+ await this.fileConnectionsTable.delete(id);
13
+ await this.fileConnectionsTable.insert(this.fileConnection);
14
14
  }
15
15
  async delete() {
16
16
  }
@@ -0,0 +1,9 @@
1
+ import File from "../stockObjects/File";
2
+ import StockObjectMapper from "../types/StockObjectMapper";
3
+ export default class FileMapper implements StockObjectMapper {
4
+ private file;
5
+ private filesTable;
6
+ constructor(file: File);
7
+ save(): Promise<void>;
8
+ delete(): Promise<void>;
9
+ }
@@ -0,0 +1,17 @@
1
+ import DatabaseConnection from "../DatabaseConnection";
2
+ export default class FileMapper {
3
+ file;
4
+ filesTable;
5
+ constructor(file) {
6
+ this.filesTable = DatabaseConnection.get().files;
7
+ this.file = file;
8
+ }
9
+ async save() {
10
+ if (this.file.getId())
11
+ await this.filesTable.update(this.file);
12
+ else
13
+ await this.filesTable.insert(this.file);
14
+ }
15
+ async delete() {
16
+ }
17
+ }
@@ -0,0 +1,9 @@
1
+ import Product from "../stockObjects/Product";
2
+ import StockObjectMapper from "../types/StockObjectMapper";
3
+ export default class ProductMapper implements StockObjectMapper {
4
+ private product;
5
+ private productTable;
6
+ constructor(product: Product);
7
+ save(): Promise<void>;
8
+ delete(): Promise<void>;
9
+ }
@@ -0,0 +1,18 @@
1
+ import DatabaseConnection from "../DatabaseConnection";
2
+ export default class ProductMapper {
3
+ product;
4
+ productTable;
5
+ constructor(product) {
6
+ this.productTable = DatabaseConnection.get().products;
7
+ this.product = product;
8
+ }
9
+ async save() {
10
+ if (this.product.getId() && !this.product.getDeleted())
11
+ await this.productTable.update(this.product);
12
+ else
13
+ await this.productTable.insert(this.product);
14
+ }
15
+ async delete() {
16
+ await this.productTable.delete(this.product.getId());
17
+ }
18
+ }
@@ -1,7 +1,12 @@
1
1
  import FileConnectionE from "../types/FileConnectionE";
2
2
  import FileI from "../types/FileI";
3
+ import QueryOptionsI from "../types/QueryOptionsI";
3
4
  export default class FilesReader {
4
5
  static get(fileId: number): Promise<FileI>;
6
+ static getAll(queryOptions: QueryOptionsI): Promise<FileI[]>;
7
+ static isExist(queryOptions: QueryOptionsI): Promise<number>;
8
+ static getQuantity(queryOptions: any): Promise<number>;
5
9
  static getForConnection(connectionType: FileConnectionE, connectionId: number): Promise<FileI[]>;
10
+ private static correctFiles;
6
11
  private static correctFile;
7
12
  }
@@ -5,14 +5,33 @@ export default class FilesReader {
5
5
  const file = await connection.files.select(fileId);
6
6
  return this.correctFile(file);
7
7
  }
8
+ static async getAll(queryOptions) {
9
+ const connection = DatabaseConnection.get();
10
+ const file = await connection.files.selectAll(queryOptions);
11
+ return this.correctFiles(file);
12
+ }
13
+ static async isExist(queryOptions) {
14
+ const connection = DatabaseConnection.get();
15
+ const fileId = await connection.files.selectId(queryOptions);
16
+ return fileId;
17
+ }
18
+ static async getQuantity(queryOptions) {
19
+ const connection = DatabaseConnection.get();
20
+ const quantity = await connection.files.count(queryOptions);
21
+ return quantity;
22
+ }
8
23
  static async getForConnection(connectionType, connectionId) {
9
24
  const connection = DatabaseConnection.get();
10
25
  const files = await connection.files.selectForConnection(connectionType, connectionId);
11
- const correctFiles = [];
12
- files.forEach((file) => {
13
- correctFiles.push(this.correctFile(file));
14
- });
15
- return correctFiles;
26
+ return this.correctFiles(files);
27
+ }
28
+ static correctFiles(fileRows) {
29
+ const fileConnections = [];
30
+ for (let i = 0; i < fileRows.length; i++) {
31
+ const fileConnection = this.correctFile(fileRows[i]);
32
+ fileConnections.push(fileConnection);
33
+ }
34
+ return fileConnections;
16
35
  }
17
36
  static correctFile(file) {
18
37
  const correctFile = {
@@ -0,0 +1,7 @@
1
+ import FileConnectionE from "../types/FileConnectionE";
2
+ export default class FilesRepo {
3
+ static get(fileId: number): Promise<any>;
4
+ static getAllForConnection(connectionType: FileConnectionE, connectionId: number): Promise<any>;
5
+ private static createFilesFromRows;
6
+ private static createFileFromRow;
7
+ }
@@ -0,0 +1,26 @@
1
+ import DatabaseConnection from "../DatabaseConnection";
2
+ import File from "../stockObjects/File";
3
+ export default class FilesRepo {
4
+ static async get(fileId) {
5
+ const connection = DatabaseConnection.get();
6
+ const file = await connection.files.select(fileId);
7
+ return this.createFileFromRow(file);
8
+ }
9
+ static async getAllForConnection(connectionType, connectionId) {
10
+ const connection = DatabaseConnection.get();
11
+ const files = await connection.files.selectForConnection(connectionType, connectionId);
12
+ return this.createFilesFromRows(files);
13
+ }
14
+ static async createFilesFromRows(dataRows) {
15
+ const files = [];
16
+ for (const dataRow of dataRows) {
17
+ const file = await this.createFileFromRow(dataRow);
18
+ files.push(file);
19
+ }
20
+ return files;
21
+ }
22
+ static createFileFromRow(file) {
23
+ const correctFile = new File(file.name, file.catalog, file.size_kb, file.type, file.orginal_name);
24
+ return correctFile;
25
+ }
26
+ }
@@ -0,0 +1,21 @@
1
+ import StockObject from "../types/StockObject";
2
+ import StockObjectMapper from "../types/StockObjectMapper";
3
+ export default class File extends StockObject {
4
+ private name;
5
+ private catalog;
6
+ private sizeKb;
7
+ private type;
8
+ private orginalName;
9
+ constructor(name: string, catalog: string, sizeKb: number, type: string, orginalName: string);
10
+ getName(): string;
11
+ getCatalog(): string;
12
+ getSizeKb(): number;
13
+ getType(): string;
14
+ getOrginalName(): string;
15
+ setName(name: string): void;
16
+ setCatalog(catalog: string): void;
17
+ setSizeKb(sizeKb: number): void;
18
+ setType(type: string): void;
19
+ setOrginalName(orginalName: string): void;
20
+ protected getMapper(): StockObjectMapper;
21
+ }
@@ -0,0 +1,50 @@
1
+ import FileMapper from "../mappers/FileMapper";
2
+ import StockObject from "../types/StockObject";
3
+ export default class File extends StockObject {
4
+ name;
5
+ catalog;
6
+ sizeKb;
7
+ type;
8
+ orginalName;
9
+ constructor(name, catalog, sizeKb, type, orginalName) {
10
+ super();
11
+ this.name = name;
12
+ this.catalog = catalog;
13
+ this.sizeKb = sizeKb;
14
+ this.type = type;
15
+ this.orginalName = orginalName;
16
+ }
17
+ getName() {
18
+ return this.name;
19
+ }
20
+ getCatalog() {
21
+ return this.catalog;
22
+ }
23
+ getSizeKb() {
24
+ return this.sizeKb;
25
+ }
26
+ getType() {
27
+ return this.type;
28
+ }
29
+ getOrginalName() {
30
+ return this.orginalName;
31
+ }
32
+ setName(name) {
33
+ this.name = name;
34
+ }
35
+ setCatalog(catalog) {
36
+ this.catalog = catalog;
37
+ }
38
+ setSizeKb(sizeKb) {
39
+ this.sizeKb = sizeKb;
40
+ }
41
+ setType(type) {
42
+ this.type = type;
43
+ }
44
+ setOrginalName(orginalName) {
45
+ this.orginalName = orginalName;
46
+ }
47
+ getMapper() {
48
+ return new FileMapper(this);
49
+ }
50
+ }
@@ -35,6 +35,36 @@ export default class Product extends StockObject {
35
35
  getDeleted(): boolean;
36
36
  getFile(): Promise<FileI | null>;
37
37
  getFiles(): Promise<FileI[] | null>;
38
+ getData(): {
39
+ id: number | null;
40
+ sku: string;
41
+ url: string;
42
+ title: string;
43
+ description: string;
44
+ netPrice: number;
45
+ vat: number;
46
+ color: string;
47
+ quantity: number;
48
+ width: number;
49
+ length: number;
50
+ height: number;
51
+ deleted: boolean;
52
+ createdAt: number | null;
53
+ fileId: number;
54
+ };
55
+ calculateGrossPrice(): number;
38
56
  setCreatedAt(createdAt: any): void;
57
+ setUrl(url: string): string;
58
+ setTitle(title: string): string;
59
+ setDescription(description: string): string;
60
+ setNetPrice(netPrice: number): number;
61
+ setVat(vat: number): number;
62
+ setColor(color: string): string;
63
+ setQuantity(quantity: number): number;
64
+ setWidth(width: number): number;
65
+ setLength(length: number): number;
66
+ setHeight(height: number): number;
67
+ setFileId(fileId: number): number;
68
+ setDeleted(deleted: boolean): boolean;
39
69
  protected getMapper(): StockObjectMapper;
40
70
  }
@@ -1,3 +1,4 @@
1
+ import ProductMapper from "../mappers/ProductMapper";
1
2
  import FilesReader from "../reader/FilesReader";
2
3
  import FileConnectionE from "../types/FileConnectionE";
3
4
  import StockObject from "../types/StockObject";
@@ -95,10 +96,68 @@ export default class Product extends StockObject {
95
96
  }
96
97
  return this.files;
97
98
  }
99
+ getData() {
100
+ return {
101
+ id: this.getId(),
102
+ sku: this.sku,
103
+ url: this.url,
104
+ title: this.title,
105
+ description: this.description,
106
+ netPrice: this.netPrice,
107
+ vat: this.vat,
108
+ color: this.color,
109
+ quantity: this.quantity,
110
+ width: this.width,
111
+ length: this.length,
112
+ height: this.height,
113
+ deleted: this.deleted,
114
+ createdAt: this.createdAt,
115
+ fileId: this.fileId,
116
+ };
117
+ }
118
+ calculateGrossPrice() {
119
+ return calculateNetToGrossPrice(this.netPrice, this.vat);
120
+ }
98
121
  setCreatedAt(createdAt) {
99
122
  this.createdAt = createdAt;
100
123
  }
124
+ setUrl(url) {
125
+ return this.url = url;
126
+ }
127
+ setTitle(title) {
128
+ return this.title = title;
129
+ }
130
+ setDescription(description) {
131
+ return this.description = description;
132
+ }
133
+ setNetPrice(netPrice) {
134
+ return this.netPrice = netPrice;
135
+ }
136
+ setVat(vat) {
137
+ return this.vat = vat;
138
+ }
139
+ setColor(color) {
140
+ return this.color = color;
141
+ }
142
+ setQuantity(quantity) {
143
+ return this.quantity = quantity;
144
+ }
145
+ setWidth(width) {
146
+ return this.width = width;
147
+ }
148
+ setLength(length) {
149
+ return this.length = length;
150
+ }
151
+ setHeight(height) {
152
+ return this.height = height;
153
+ }
154
+ setFileId(fileId) {
155
+ return this.fileId = fileId;
156
+ }
157
+ setDeleted(deleted) {
158
+ return this.deleted = deleted;
159
+ }
101
160
  getMapper() {
102
- throw new Error('there are no mapper for product');
161
+ return new ProductMapper(this);
103
162
  }
104
163
  }
@@ -1,7 +1,7 @@
1
- import Table from '../Table';
2
- import ClientAccountRow from '../types/rows/ClientAccountRow';
3
- import Client from '../stockObjects/Client';
4
- import QueryOptions from '../query/QueryOptions';
1
+ import Table from '../../Table';
2
+ import ClientAccountRow from '../../types/rows/ClientAccountRow';
3
+ import Client from '../../stockObjects/Client';
4
+ import QueryOptions from '../../query/QueryOptions';
5
5
  export default class ClientAccountsTable extends Table {
6
6
  select(accountId: number): Promise<ClientAccountRow>;
7
7
  selectEmail(id: number): Promise<string>;
@@ -1,5 +1,5 @@
1
- import Table from '../Table';
2
- import * as SQL from '../SQL.json';
1
+ import Table from '../../Table';
2
+ import * as SQL from '../../SQL.json';
3
3
  export default class ClientAccountsTable extends Table {
4
4
  async select(accountId) {
5
5
  const query = this.createQuery(SQL.accounts.select);
@@ -1,9 +1,9 @@
1
1
  import Table from '../../Table';
2
- import FileConnectionTypeE from '../../types/FileConnectionTypeE';
2
+ import FileConnectionE from '../../types/FileConnectionE';
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: FileConnectionTypeE, connection_id: number): Promise<any[]>;
6
+ select(connectionType: FileConnectionE, 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,7 +1,17 @@
1
1
  import Table from '../../Table';
2
2
  import FileRow from '../../types/rows/FileRow';
3
3
  import FileConnectionE from '../../types/FileConnectionE';
4
+ import QueryOptionsI from '../../types/QueryOptionsI';
5
+ import File from '../../stockObjects/File';
4
6
  export default class FilesTable extends Table {
7
+ selectId(queryOptions: QueryOptionsI): Promise<number>;
8
+ selectAll(queryOptions: QueryOptionsI): Promise<FileRow[]>;
5
9
  select(fileId: number): Promise<FileRow>;
6
10
  selectForConnection(connectionType: FileConnectionE, connectionId: number): Promise<FileRow[]>;
11
+ insert(file: File): Promise<boolean>;
12
+ update(fileData: File): Promise<boolean>;
13
+ count(queryOptions: QueryOptionsI): Promise<number>;
14
+ private bindParameters;
15
+ delete(fileId: number): Promise<number>;
16
+ private selectNextId;
7
17
  }
@@ -1,6 +1,16 @@
1
1
  import Table from '../../Table';
2
2
  import * as SQL from '../../SQL.json';
3
3
  export default class FilesTable extends Table {
4
+ async selectId(queryOptions) {
5
+ const query = this.createQuery(SQL.files.selectId, queryOptions);
6
+ const result = await query.execute();
7
+ return result.getValue();
8
+ }
9
+ async selectAll(queryOptions) {
10
+ const query = this.createQuery(SQL.files.selectAll, queryOptions);
11
+ const result = await query.execute();
12
+ return result.getRows();
13
+ }
4
14
  async select(fileId) {
5
15
  const query = this.createQuery(SQL.files.select);
6
16
  query.bindParameter('id', fileId);
@@ -14,4 +24,42 @@ export default class FilesTable extends Table {
14
24
  const result = await query.execute();
15
25
  return result.getRows();
16
26
  }
27
+ async insert(file) {
28
+ const query = this.createQuery(SQL.files.insert);
29
+ const id = await this.selectNextId();
30
+ query.bindParameter('id', id);
31
+ this.bindParameters(query, file);
32
+ await query.execute();
33
+ file.setId(id);
34
+ return true;
35
+ }
36
+ async update(fileData) {
37
+ const query = this.createQuery(SQL.files.update);
38
+ this.bindParameters(query, fileData);
39
+ await query.execute();
40
+ return true;
41
+ }
42
+ async count(queryOptions) {
43
+ const query = this.createQuery(SQL.files.count, queryOptions);
44
+ const result = await query.execute();
45
+ return result.getValue();
46
+ }
47
+ bindParameters(query, file) {
48
+ query.bindParameter('name', file.getName());
49
+ query.bindParameter('orginal_name', file.getOrginalName());
50
+ query.bindParameter('catalog', file.getCatalog());
51
+ query.bindParameter('size_kb', file.getSizeKb());
52
+ query.bindParameter('type', file.getType());
53
+ }
54
+ async delete(fileId) {
55
+ const query = this.createQuery(SQL.files.delete);
56
+ query.bindParameter('file_id', fileId);
57
+ const response = await query.execute();
58
+ return response.getRowCount();
59
+ }
60
+ async selectNextId() {
61
+ const query = this.createQuery(SQL.files.selectNextId);
62
+ const result = await query.execute();
63
+ return result.getValue();
64
+ }
17
65
  }
@@ -1,4 +1,4 @@
1
- import Table from '../Table';
1
+ import Table from '../../Table';
2
2
  export default class DeliveryStatusTypesTable extends Table {
3
3
  select(deliveryStatusTypeId: number): Promise<{
4
4
  id: number;
@@ -1,5 +1,5 @@
1
- import * as SQL from '../SQL.json';
2
- import Table from '../Table';
1
+ import * as SQL from '../../SQL.json';
2
+ import Table from '../../Table';
3
3
  export default class DeliveryStatusTypesTable extends Table {
4
4
  async select(deliveryStatusTypeId) {
5
5
  const query = this.createQuery(SQL.deliveryStatusTypes.select);
@@ -1,6 +1,6 @@
1
- import DeliveryStatus from '../stockObjects/DeliveryStatus';
2
- import Table from '../Table';
3
- import DeliveryStatusRow from '../types/rows/DeliveryStatusRow';
1
+ import DeliveryStatus from '../../stockObjects/DeliveryStatus';
2
+ import Table from '../../Table';
3
+ import DeliveryStatusRow from '../../types/rows/DeliveryStatusRow';
4
4
  export default class DeliveryStatusesTable extends Table {
5
5
  select(deliveryDetailsId: number): Promise<DeliveryStatusRow>;
6
6
  selectAll(deliveryDetailsId: number): Promise<DeliveryStatusRow[]>;
@@ -1,5 +1,5 @@
1
- import * as SQL from '../SQL.json';
2
- import Table from '../Table';
1
+ import * as SQL from '../../SQL.json';
2
+ import Table from '../../Table';
3
3
  export default class DeliveryStatusesTable extends Table {
4
4
  async select(deliveryDetailsId) {
5
5
  const query = this.createQuery(SQL.deliveryStatuses.select);
@@ -1,7 +1,7 @@
1
- import QueryOptionsI from "../types/QueryOptionsI";
2
- import Table from "../Table";
3
- import AdminRow from "../types/rows/AdminRow";
4
- import Admin from "../stockObjects/Admin";
1
+ import QueryOptionsI from "../../types/QueryOptionsI";
2
+ import Table from "../../Table";
3
+ import AdminRow from "../../types/rows/AdminRow";
4
+ import Admin from "../../stockObjects/Admin";
5
5
  export default class AdminAccountsTable extends Table {
6
6
  select(accountId: number): Promise<AdminRow>;
7
7
  selectAll(queryOptions: QueryOptionsI): Promise<AdminRow[]>;
@@ -1,5 +1,5 @@
1
- import Table from "../Table";
2
- import * as SQL from '../SQL.json';
1
+ import Table from "../../Table";
2
+ import * as SQL from '../../SQL.json';
3
3
  export default class AdminAccountsTable extends Table {
4
4
  async select(accountId) {
5
5
  const query = this.createQuery(SQL.adminAccounts.select);
@@ -1,7 +1,7 @@
1
- import Table from '../Table';
2
- import QueryOptionsI from '../types/QueryOptionsI';
3
- import ProductRow from '../types/rows/ProductRow';
4
- import Product from '../stockObjects/Product';
1
+ import Product from '../../stockObjects/Product';
2
+ import Table from '../../Table';
3
+ import QueryOptionsI from '../../types/QueryOptionsI';
4
+ import ProductRow from '../../types/rows/ProductRow';
5
5
  export default class ProductsTable extends Table {
6
6
  select(productId: number): Promise<ProductRow>;
7
7
  selectForSku(sku: string): Promise<ProductRow>;
@@ -1,5 +1,5 @@
1
- import Table from '../Table';
2
- import * as SQL from '../SQL.json';
1
+ import * as SQL from '../../SQL.json';
2
+ import Table from '../../Table';
3
3
  export default class ProductsTable extends Table {
4
4
  async select(productId) {
5
5
  const query = this.createQuery(SQL.products.select);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dascompany/database",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "vitest",
@@ -1,4 +0,0 @@
1
- import Table from "../Table";
2
- export default class StatusTypesTable extends Table {
3
- select(): Promise<any[]>;
4
- }
@@ -1,9 +0,0 @@
1
- import Table from "../Table";
2
- import * as SQL from '../SQL.json';
3
- export default class StatusTypesTable extends Table {
4
- async select() {
5
- const query = this.createQuery(SQL.statusTypes.select);
6
- const result = await query.execute();
7
- return result.getRows();
8
- }
9
- }
@@ -1,4 +0,0 @@
1
- declare enum FileConnectionTypeE {
2
- product = "product"
3
- }
4
- export default FileConnectionTypeE;
@@ -1,5 +0,0 @@
1
- var FileConnectionTypeE;
2
- (function (FileConnectionTypeE) {
3
- FileConnectionTypeE["product"] = "product";
4
- })(FileConnectionTypeE || (FileConnectionTypeE = {}));
5
- export default FileConnectionTypeE;