@dascompany/database 0.0.1 → 0.0.3
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 +17 -2
- package/dist/index.d.ts +14 -1
- package/dist/index.js +9 -1
- package/dist/mappers/DeliveryMethodsMapper.d.ts +9 -0
- package/dist/mappers/DeliveryMethodsMapper.js +17 -0
- package/dist/query/QueryOptions.d.ts +6 -0
- package/dist/query/QueryOptions.js +25 -0
- package/dist/reader/ClientAccountReader.d.ts +6 -0
- package/dist/reader/ClientAccountReader.js +27 -10
- package/dist/reader/DeliveryMethodReader.d.ts +1 -0
- package/dist/reader/DeliveryMethodReader.js +5 -0
- package/dist/repo/AdminRepo.d.ts +12 -0
- package/dist/repo/AdminRepo.js +32 -0
- package/dist/repo/ClientAccountRepo.d.ts +2 -0
- package/dist/repo/ClientAccountRepo.js +10 -0
- package/dist/repo/ContactDetailsRepo.d.ts +1 -0
- package/dist/repo/ContactDetailsRepo.js +8 -3
- package/dist/repo/ProductRepo.d.ts +1 -0
- package/dist/repo/ProductRepo.js +5 -0
- package/dist/stockObjects/DeliveryMethods.d.ts +12 -0
- package/dist/stockObjects/DeliveryMethods.js +26 -0
- package/dist/stockObjects/Order.d.ts +1 -1
- package/dist/stockObjects/Product.d.ts +1 -1
- package/dist/stockObjects/Product.js +5 -2
- package/dist/tables/ClientAccountsTable.d.ts +5 -2
- package/dist/tables/ClientAccountsTable.js +16 -4
- package/dist/tables/ProductsTable.d.ts +10 -0
- package/dist/tables/ProductsTable.js +72 -0
- package/dist/tables/personalInformation/ContactDetailsTable.d.ts +1 -1
- package/dist/tables/store-settings/DeliveryMethodsTable.d.ts +6 -0
- package/dist/tables/store-settings/DeliveryMethodsTable.js +28 -0
- package/dist/types/parameters/ParameterType.d.ts +12 -9
- package/dist/types/parameters/ParameterType.js +12 -9
- package/dist/types/rows/DeliveryMethodRow.d.ts +5 -0
- package/dist/types/rows/DeliveryMethodRow.js +1 -0
- package/dist/utils/Filters.d.ts +6 -0
- package/dist/utils/Filters.js +31 -0
- package/dist/utils/OrderByI.d.ts +4 -0
- package/dist/utils/OrderByI.js +1 -0
- package/dist/utils/Parameters.d.ts +5 -0
- package/dist/utils/Parameters.js +23 -0
- package/dist/utils/parameters/ParameterConversionSystem.d.ts +5 -0
- package/dist/utils/parameters/ParameterConversionSystem.js +28 -0
- package/dist/utils/parameters/ParameterFilterSystem.d.ts +4 -0
- package/dist/utils/parameters/ParameterFilterSystem.js +11 -0
- package/dist/utils/parameters/ParameterRulesSystem.d.ts +3 -0
- package/dist/utils/parameters/ParameterRulesSystem.js +8 -0
- package/package.json +2 -2
package/dist/SQL.json
CHANGED
|
@@ -11,11 +11,14 @@
|
|
|
11
11
|
},
|
|
12
12
|
"accounts": {
|
|
13
13
|
"select": "SELECT id, email, created_at, activated, deleted, contact_details_id, delivery_details_id, invoice_details_id FROM clients.accounts WHERE id = $account_id::BIGINT",
|
|
14
|
+
"selectAll": "SELECT id, email, created_at, activated, deleted FROM clients.accounts $WHERE $ORDERBY $LIMIT",
|
|
14
15
|
"selectNextId": "SELECT nextval('clients.accounts_id'::regclass)",
|
|
15
16
|
"getIdForEmail": "SELECT id FROM clients.accounts WHERE LOWER( email ) = LOWER($email::TEXT)",
|
|
16
17
|
"insert": "INSERT INTO clients.accounts( id, email, activated, contact_details_id) VALUES ($id::BIGINT, LOWER($email::TEXT), $activated::BOOL, $contact_details_id::BIGINT)",
|
|
17
18
|
"update": "UPDATE clients.accounts SET activated = $activated::BOOL, deleted = $deleted::BOOL, contact_details_id = $contact_details_id::BIGINT, delivery_details_id = $delivery_details_id::BIGINT, invoice_details_id = $invoice_details_id::BIGINT WHERE id = $id::BIGINT",
|
|
18
|
-
"delete": "DELETE FROM clients.accounts WHERE id = $account_id::BIGINT"
|
|
19
|
+
"delete": "DELETE FROM clients.accounts WHERE id = $account_id::BIGINT",
|
|
20
|
+
"count": "SELECT COUNT(*) AS total_rows FROM clients.accounts $WHERE ",
|
|
21
|
+
"selectEmail": "SELECT email FROM clients.accounts WHERE id = $id:BIGINT"
|
|
19
22
|
},
|
|
20
23
|
"contactDetails": {
|
|
21
24
|
"select": "SELECT id, personal_data_id, address_id FROM personal_information.contact_details WHERE id = $id::BIGINT",
|
|
@@ -37,6 +40,8 @@
|
|
|
37
40
|
},
|
|
38
41
|
"addresses": {
|
|
39
42
|
"select": "SELECT id, country, city, postal_code, street, house_number, apartment_number FROM personal_information.addresses WHERE id = $id::BIGINT",
|
|
43
|
+
"selectTypes": "SELECT type FROM personal_information.addresses WHERE account_id = $account_id::BIGINT",
|
|
44
|
+
"selectId": "SELECT id FROM personal_information.addresses WHERE account_id = $account_id::BIGINT AND type = $type::SMALLINT",
|
|
40
45
|
"insert": "INSERT INTO personal_information.addresses( id, country, city, postal_code, street, house_number, apartment_number) VALUES( $id::BIGINT, $country::TEXT, $city::TEXT, $postal_code::TEXT, $street::TEXT, $house_number::TEXT, $apartment_number::TEXT) ",
|
|
41
46
|
"update": "UPDATE personal_information.addresses SET country = $country::TEXT, city = $city::TEXT, postal_code = $postal_code::TEXT , street = $street::TEXT , house_number = $house_number::TEXT , apartment_number = $apartment_number::TEXT WHERE id = $id::BIGINT",
|
|
42
47
|
"selectNextId": "SELECT nextval('personal_information.addresses_id'::regclass)"
|
|
@@ -58,6 +63,12 @@
|
|
|
58
63
|
"products": {
|
|
59
64
|
"select": "SELECT id, sku, url, title, description, net_price, vat, color, quantity, width, height, length, file_id, created_at, deleted FROM products WHERE id = $id::BIGINT",
|
|
60
65
|
"selectAll": "SELECT id, sku, url, title, description, net_price, vat, color, quantity, width, height, length, file_id, created_at, deleted FROM products WHERE deleted = false $PARAMS $ORDERBY LIMIT $limit::BIGINT OFFSET $offset::BIGINT",
|
|
66
|
+
"selectListForOrder": "SELECT id, title, sku, file_id, net_price FROM products WHERE deleted = false",
|
|
67
|
+
"selectIdForSku": "SELECT id FROM products WHERE LOWER( sku ) = LOWER($sku::TEXT) AND deleted = false",
|
|
68
|
+
"insert": "INSERT INTO products( id, sku, url, title, description, net_price, vat, color, quantity, width, length, height, file_id, deleted) VALUES ($id::BIGINT, $sku::TEXT, $url::TEXT, $title::TEXT, $description::TEXT, $net_price::DOUBLE PRECISION, $vat::INT, $color::TEXT, $quantity::INT, $width::INT, $length::INT, $height::DOUBLE PRECISION,$file_id::BIGINT ,false::BOOL)",
|
|
69
|
+
"update": "UPDATE products SET url = $url::TEXT, title = $title::TEXT , description = $description::TEXT , net_price = $net_price::DOUBLE PRECISION, vat = $vat::INT, color = $color::TEXT, quantity = $quantity::INT, width = $width::INT, length = $length::INT, height = $height::DOUBLE PRECISION, file_id = $file_id::BIGINT WHERE id = $id::BIGINT",
|
|
70
|
+
"delete": "UPDATE products SET deleted = true WHERE id = $id::BIGINT",
|
|
71
|
+
"restore": "UPDATE products SET deleted = false WHERE id = $id::BIGINT",
|
|
61
72
|
"selectForSku": "SELECT id as product_id FROM products WHERE LOWER( sku ) = LOWER($sku::TEXT)",
|
|
62
73
|
"selectForUrl": "SELECT id, sku, url, title, description, net_price, vat, color, quantity, width, height, length, file_id, created_at, deleted FROM products WHERE LOWER( url ) = LOWER($url::TEXT)",
|
|
63
74
|
"selectNextId": "SELECT nextval('product_id'::regclass)",
|
|
@@ -97,7 +108,11 @@
|
|
|
97
108
|
},
|
|
98
109
|
"deliveryMethods": {
|
|
99
110
|
"select": "SELECT * FROM settings.delivery_methods WHERE id = $id::BIGINT",
|
|
100
|
-
"selectAll": "SELECT * FROM settings.delivery_methods
|
|
111
|
+
"selectAll": "SELECT * FROM settings.delivery_methods ORDER BY id",
|
|
112
|
+
"selectAllActive": "SELECT * FROM settings.delivery_methods WHERE active=true ORDER BY id",
|
|
113
|
+
"insert": "INSERT INTO settings.delivery_methods(id, key, active) VALUES ( $id::BIGINT, $key::TEXT, $active::BOOL)",
|
|
114
|
+
"update": "UPDATE settings.delivery_methods SET id = $id::BIGINT, key = $key::TEXT, active = $active::BOOL WHERE id = $id::BIGINT",
|
|
115
|
+
"selectNextId": "SELECT nextval('settings.delivery_methods_id'::regclass)"
|
|
101
116
|
},
|
|
102
117
|
"paymentStatusTypes": {
|
|
103
118
|
"select": "SELECT * FROM orders.payment_status_types WHERE id = $id::BIGINT"
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import DeliveryMethodReader from "./reader/DeliveryMethodReader";
|
|
|
8
8
|
import InvoiceDetailsReader from "./reader/InvoiceDetailsReader";
|
|
9
9
|
import OrderProductsReader from "./reader/OrderProductsReader";
|
|
10
10
|
import OrderReader from "./reader/OrderReader";
|
|
11
|
+
import FilesReader from './reader/FilesReader';
|
|
11
12
|
import OrderStatusReader from "./reader/OrderStatusReader";
|
|
12
13
|
import PaymentDetailsReader from "./reader/payment/PaymentDetailsReader";
|
|
13
14
|
import PaymentMethodReader from "./reader/payment/PaymentMethodReader";
|
|
@@ -39,4 +40,16 @@ import PersonalData from "./stockObjects/PersonalData";
|
|
|
39
40
|
import Product from "./stockObjects/Product";
|
|
40
41
|
import Status from "./stockObjects/Status";
|
|
41
42
|
import Client from "./stockObjects/Client";
|
|
42
|
-
|
|
43
|
+
import AdminRepo from './repo/AdminRepo';
|
|
44
|
+
import TableConnection from './TableConnection';
|
|
45
|
+
import ParameterType from './types/parameters/ParameterType';
|
|
46
|
+
import DeliveryStatusReader from './reader/DeliveryStatusReader';
|
|
47
|
+
import FileConnectionE from './types/FileConnectionE';
|
|
48
|
+
import ConnectorE from './types/ConnectorE';
|
|
49
|
+
import ParameterI from './types/ParameterI';
|
|
50
|
+
import QueryOptionsI from './types/QueryOptionsI';
|
|
51
|
+
import ResultLimitationI from './types/ResultLimitationI';
|
|
52
|
+
import ParameterFilter from './types/parameters/ParameterFilter';
|
|
53
|
+
import PaymentStatusE from './types/PaymentStatusE';
|
|
54
|
+
import OrderProductI from './types/OrderProductI';
|
|
55
|
+
export { TableConnection, DatabaseConnection, ParameterType, ConnectorE, FileConnectionE, PaymentStatusE, ParameterI, QueryOptionsI, ResultLimitationI, OrderProductI, ParameterFilter, PaymentDetailsReader, FilesReader, PaymentMethodReader, DeliveryStatusReader, PaymentStatusesReader, AddressesReader, ClientAccountReader, CompanyDetailsReader, ContactDetailsReader, DeliveryDetailsReader, DeliveryMethodReader, InvoiceDetailsReader, OrderProductsReader, OrderReader, OrderStatusReader, PersonalDataReader, ProductReader, AdminRepo, PaymentDetailsRepo, AddressesRepo, ClientAccountRepo, CompanyDetailsRepo, ContactDetailsRepo, DeliveryDetailsRepo, InvoiceDetailsRepo, OrderRepo, PersonalDataRepo, ProductRepo, Address, Admin, Client, CompanyDetails, ContactDetails, DeliveryDetails, InvoiceDetails, DeliveryStatus, Order, OrderProduct, PaymentDetails, PaymentStatus, PersonalData, Product, Status, };
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import DeliveryMethodReader from "./reader/DeliveryMethodReader";
|
|
|
8
8
|
import InvoiceDetailsReader from "./reader/InvoiceDetailsReader";
|
|
9
9
|
import OrderProductsReader from "./reader/OrderProductsReader";
|
|
10
10
|
import OrderReader from "./reader/OrderReader";
|
|
11
|
+
import FilesReader from './reader/FilesReader';
|
|
11
12
|
import OrderStatusReader from "./reader/OrderStatusReader";
|
|
12
13
|
import PaymentDetailsReader from "./reader/payment/PaymentDetailsReader";
|
|
13
14
|
import PaymentMethodReader from "./reader/payment/PaymentMethodReader";
|
|
@@ -39,4 +40,11 @@ import PersonalData from "./stockObjects/PersonalData";
|
|
|
39
40
|
import Product from "./stockObjects/Product";
|
|
40
41
|
import Status from "./stockObjects/Status";
|
|
41
42
|
import Client from "./stockObjects/Client";
|
|
42
|
-
|
|
43
|
+
import AdminRepo from './repo/AdminRepo';
|
|
44
|
+
import TableConnection from './TableConnection';
|
|
45
|
+
import ParameterType from './types/parameters/ParameterType';
|
|
46
|
+
import DeliveryStatusReader from './reader/DeliveryStatusReader';
|
|
47
|
+
import FileConnectionE from './types/FileConnectionE';
|
|
48
|
+
import ConnectorE from './types/ConnectorE';
|
|
49
|
+
import PaymentStatusE from './types/PaymentStatusE';
|
|
50
|
+
export { TableConnection, DatabaseConnection, ParameterType, ConnectorE, FileConnectionE, PaymentStatusE, PaymentDetailsReader, FilesReader, PaymentMethodReader, DeliveryStatusReader, PaymentStatusesReader, AddressesReader, ClientAccountReader, CompanyDetailsReader, ContactDetailsReader, DeliveryDetailsReader, DeliveryMethodReader, InvoiceDetailsReader, OrderProductsReader, OrderReader, OrderStatusReader, PersonalDataReader, ProductReader, AdminRepo, PaymentDetailsRepo, AddressesRepo, ClientAccountRepo, CompanyDetailsRepo, ContactDetailsRepo, DeliveryDetailsRepo, InvoiceDetailsRepo, OrderRepo, PersonalDataRepo, ProductRepo, Address, Admin, Client, CompanyDetails, ContactDetails, DeliveryDetails, InvoiceDetails, DeliveryStatus, Order, OrderProduct, PaymentDetails, PaymentStatus, PersonalData, Product, Status, };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import DeliveryMethods from "../stockObjects/DeliveryMethods";
|
|
2
|
+
import StockObjectMapper from "../types/StockObjectMapper";
|
|
3
|
+
export default class DeliveryMethodsMapper implements StockObjectMapper {
|
|
4
|
+
private deliveryMethods;
|
|
5
|
+
private deliveryMethodsTable;
|
|
6
|
+
constructor(deliveryMethods: DeliveryMethods);
|
|
7
|
+
save(): Promise<void>;
|
|
8
|
+
delete(): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import DatabaseConnection from "../DatabaseConnection";
|
|
2
|
+
export default class DeliveryMethodsMapper {
|
|
3
|
+
deliveryMethods;
|
|
4
|
+
deliveryMethodsTable;
|
|
5
|
+
constructor(deliveryMethods) {
|
|
6
|
+
this.deliveryMethodsTable = DatabaseConnection.get().deliveryMethods;
|
|
7
|
+
this.deliveryMethods = deliveryMethods;
|
|
8
|
+
}
|
|
9
|
+
async save() {
|
|
10
|
+
if (this.deliveryMethods.getId())
|
|
11
|
+
await this.deliveryMethodsTable.update(this.deliveryMethods);
|
|
12
|
+
else
|
|
13
|
+
await this.deliveryMethodsTable.insert(this.deliveryMethods);
|
|
14
|
+
}
|
|
15
|
+
async delete() {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import ResultLimitationI from "../types/ResultLimitationI";
|
|
2
|
+
import OrderByI from "../utils/OrderByI";
|
|
3
|
+
export default class QueryOptions {
|
|
4
|
+
static correctingSorting(querySortBy: any): OrderByI[];
|
|
5
|
+
static correctingLimitation(queryLimit: any, queryOffset: any): ResultLimitationI;
|
|
6
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import ParameterType from "../types/parameters/ParameterType";
|
|
2
|
+
import Filters from "../utils/Filters";
|
|
3
|
+
import Parameters from "../utils/Parameters";
|
|
4
|
+
export default class QueryOptions {
|
|
5
|
+
static correctingSorting(querySortBy) {
|
|
6
|
+
const sortBy = Parameters.correct(querySortBy, { type: ParameterType.arrayObject });
|
|
7
|
+
const table = [];
|
|
8
|
+
if (sortBy[0]) {
|
|
9
|
+
sortBy.forEach((element) => {
|
|
10
|
+
const key = Parameters.correct(element.key, { type: ParameterType.string, filter: Filters.databaseColumn });
|
|
11
|
+
const order = Parameters.correct(element.order, { type: ParameterType.string });
|
|
12
|
+
table.push({ key, order });
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return table;
|
|
16
|
+
}
|
|
17
|
+
static correctingLimitation(queryLimit, queryOffset) {
|
|
18
|
+
const limit = Parameters.correct(queryLimit, { type: ParameterType.bigint });
|
|
19
|
+
const offset = Parameters.correct(queryOffset, { type: ParameterType.bigint });
|
|
20
|
+
return {
|
|
21
|
+
limit,
|
|
22
|
+
offset
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import QueryOptions from "../query/QueryOptions";
|
|
1
2
|
import ClientAccountI from "../types/ClientAccountI";
|
|
2
3
|
export default class ClientAccountReader {
|
|
3
4
|
static get(accountId: number): Promise<ClientAccountI>;
|
|
5
|
+
static getAll(queryOptions: QueryOptions): Promise<{
|
|
6
|
+
clientAccounts: ClientAccountI[];
|
|
7
|
+
quantity: number;
|
|
8
|
+
}>;
|
|
4
9
|
static getForEmail(email: string): Promise<ClientAccountI>;
|
|
5
10
|
static getIdForEmail(email: string): Promise<number>;
|
|
11
|
+
private static correctClientsFromRows;
|
|
6
12
|
private static correctData;
|
|
7
13
|
}
|
|
@@ -5,6 +5,15 @@ export default class ClientAccountReader {
|
|
|
5
5
|
const account = await connection.accounts.select(accountId);
|
|
6
6
|
return this.correctData(account);
|
|
7
7
|
}
|
|
8
|
+
static async getAll(queryOptions) {
|
|
9
|
+
const connection = DatabaseConnection.get();
|
|
10
|
+
const clientAccounts = await connection.accounts.selectAll(queryOptions);
|
|
11
|
+
const quantity = await connection.accounts.count(queryOptions);
|
|
12
|
+
return {
|
|
13
|
+
clientAccounts: this.correctClientsFromRows(clientAccounts),
|
|
14
|
+
quantity
|
|
15
|
+
};
|
|
16
|
+
}
|
|
8
17
|
static async getForEmail(email) {
|
|
9
18
|
const connection = DatabaseConnection.get();
|
|
10
19
|
const account = await connection.accounts.selectForEmail(email);
|
|
@@ -12,19 +21,27 @@ export default class ClientAccountReader {
|
|
|
12
21
|
}
|
|
13
22
|
static async getIdForEmail(email) {
|
|
14
23
|
const connection = DatabaseConnection.get();
|
|
15
|
-
const accountId = await connection.accounts.
|
|
24
|
+
const accountId = await connection.accounts.getIdForEmail(email);
|
|
16
25
|
return accountId;
|
|
17
26
|
}
|
|
18
|
-
static
|
|
27
|
+
static correctClientsFromRows(dataRows) {
|
|
28
|
+
const clients = [];
|
|
29
|
+
for (const dataRow of dataRows) {
|
|
30
|
+
const client = this.correctData(dataRow);
|
|
31
|
+
clients.push(client);
|
|
32
|
+
}
|
|
33
|
+
return clients;
|
|
34
|
+
}
|
|
35
|
+
static correctData(client) {
|
|
19
36
|
return {
|
|
20
|
-
id:
|
|
21
|
-
email:
|
|
22
|
-
createdAt:
|
|
23
|
-
activated:
|
|
24
|
-
deleted:
|
|
25
|
-
contactDetailsId:
|
|
26
|
-
deliveryDetailsId:
|
|
27
|
-
invoiceDetailsId:
|
|
37
|
+
id: client.id,
|
|
38
|
+
email: client.email,
|
|
39
|
+
createdAt: client.created_at,
|
|
40
|
+
activated: client.activated,
|
|
41
|
+
deleted: client.deleted,
|
|
42
|
+
contactDetailsId: client.contact_details_id,
|
|
43
|
+
deliveryDetailsId: client.delivery_details_id,
|
|
44
|
+
invoiceDetailsId: client.invoice_details_id,
|
|
28
45
|
};
|
|
29
46
|
}
|
|
30
47
|
}
|
|
@@ -10,4 +10,9 @@ export default class DeliveryMethodReader {
|
|
|
10
10
|
const deliveryMethods = await connection.deliveryMethods.selectAll();
|
|
11
11
|
return deliveryMethods;
|
|
12
12
|
}
|
|
13
|
+
static async getAllActive() {
|
|
14
|
+
const connection = DatabaseConnection.get();
|
|
15
|
+
const deliveryMethods = await connection.deliveryMethods.selectAllActive();
|
|
16
|
+
return deliveryMethods;
|
|
17
|
+
}
|
|
13
18
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Admin from "../stockObjects/Admin";
|
|
2
|
+
import QueryOptionsI from "../types/QueryOptionsI";
|
|
3
|
+
export default class AdminRepo {
|
|
4
|
+
static get(accountId: number): Promise<Admin>;
|
|
5
|
+
static getIdForEmail(email: string): Promise<number>;
|
|
6
|
+
static getAll(queryOptions: QueryOptionsI): Promise<{
|
|
7
|
+
adminAccounts: Admin[];
|
|
8
|
+
quantity: number;
|
|
9
|
+
}>;
|
|
10
|
+
private static createAdminsFromRows;
|
|
11
|
+
private static createAdminFromRow;
|
|
12
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import DatabaseConnection from "../DatabaseConnection";
|
|
2
|
+
import Admin from "../stockObjects/Admin";
|
|
3
|
+
export default class AdminRepo {
|
|
4
|
+
static async get(accountId) {
|
|
5
|
+
const connection = DatabaseConnection.get();
|
|
6
|
+
const account = await connection.adminAccounts.select(accountId);
|
|
7
|
+
return this.createAdminFromRow(account);
|
|
8
|
+
}
|
|
9
|
+
static async getIdForEmail(email) {
|
|
10
|
+
const connection = DatabaseConnection.get();
|
|
11
|
+
return await connection.adminAccounts.selectForEmail(email);
|
|
12
|
+
}
|
|
13
|
+
static async getAll(queryOptions) {
|
|
14
|
+
const connection = DatabaseConnection.get();
|
|
15
|
+
const adminAccounts = await connection.adminAccounts.selectAll(queryOptions);
|
|
16
|
+
const quantity = await connection.adminAccounts.count(queryOptions);
|
|
17
|
+
return { adminAccounts: this.createAdminsFromRows(adminAccounts), quantity };
|
|
18
|
+
}
|
|
19
|
+
static createAdminsFromRows(dataRows) {
|
|
20
|
+
const admins = [];
|
|
21
|
+
for (const dataRow of dataRows) {
|
|
22
|
+
const admin = this.createAdminFromRow(dataRow);
|
|
23
|
+
admins.push(admin);
|
|
24
|
+
}
|
|
25
|
+
return admins;
|
|
26
|
+
}
|
|
27
|
+
static createAdminFromRow(dataRow) {
|
|
28
|
+
const admin = new Admin(dataRow.email, dataRow.first_name, dataRow.last_name, dataRow.activated, dataRow.deleted, dataRow.created_at);
|
|
29
|
+
admin.setId(dataRow.id);
|
|
30
|
+
return admin;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import Client from "../stockObjects/Client";
|
|
2
2
|
export default class ClientAccountRepo {
|
|
3
3
|
static get(accountId: number): Promise<Client>;
|
|
4
|
+
static getById(clientId: number): Promise<Client>;
|
|
5
|
+
static getEmailForId(clientId: number): Promise<string>;
|
|
4
6
|
private static createCilentAccountFromRow;
|
|
5
7
|
}
|
|
@@ -6,6 +6,16 @@ export default class ClientAccountRepo {
|
|
|
6
6
|
const accountData = await connection.accounts.select(accountId);
|
|
7
7
|
return this.createCilentAccountFromRow(accountData);
|
|
8
8
|
}
|
|
9
|
+
static async getById(clientId) {
|
|
10
|
+
const connection = DatabaseConnection.get();
|
|
11
|
+
const client = await connection.accounts.select(clientId);
|
|
12
|
+
return this.createCilentAccountFromRow(client);
|
|
13
|
+
}
|
|
14
|
+
static async getEmailForId(clientId) {
|
|
15
|
+
const connection = DatabaseConnection.get();
|
|
16
|
+
const email = await connection.accounts.selectEmail(clientId);
|
|
17
|
+
return email;
|
|
18
|
+
}
|
|
9
19
|
static createCilentAccountFromRow(accountData) {
|
|
10
20
|
const client = new Client(accountData.email, accountData.activated, accountData.deleted, accountData.contact_details_id, accountData.delivery_details_id, accountData.invoice_details_id, accountData.created_at);
|
|
11
21
|
client.setId(accountData.id);
|
|
@@ -6,9 +6,14 @@ export default class ContactDetailsRepo {
|
|
|
6
6
|
const contactDetailsRow = await connection.contactDetails.select(contactDetailsId);
|
|
7
7
|
return this.createContactDetailsFromRow(contactDetailsRow);
|
|
8
8
|
}
|
|
9
|
+
static async getNextId() {
|
|
10
|
+
const connection = DatabaseConnection.get();
|
|
11
|
+
const contactDetails = await connection.contactDetails.selectNextId();
|
|
12
|
+
return contactDetails;
|
|
13
|
+
}
|
|
9
14
|
static createContactDetailsFromRow(contactDetailsRow) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
return
|
|
15
|
+
const contactDetails = new ContactDetails(contactDetailsRow.personal_data_id, contactDetailsRow.address_id);
|
|
16
|
+
contactDetails.setId(contactDetailsRow.id);
|
|
17
|
+
return contactDetails;
|
|
13
18
|
}
|
|
14
19
|
}
|
package/dist/repo/ProductRepo.js
CHANGED
|
@@ -6,6 +6,11 @@ export default class ProductRepo {
|
|
|
6
6
|
const product = await connection.products.select(productId);
|
|
7
7
|
return this.createProductFromRow(product);
|
|
8
8
|
}
|
|
9
|
+
static async getForSku(productSku) {
|
|
10
|
+
const connection = DatabaseConnection.get();
|
|
11
|
+
const product = await connection.products.selectForSku(productSku);
|
|
12
|
+
return this.createProductFromRow(product);
|
|
13
|
+
}
|
|
9
14
|
static createProductFromRow(productRow) {
|
|
10
15
|
const product = new Product(productRow.sku, productRow.url, productRow.title, productRow.description, productRow.net_price, productRow.vat, productRow.color, productRow.quantity, productRow.width, productRow.length, productRow.height, productRow.file_id, productRow.deleted);
|
|
11
16
|
product.setId(productRow.id);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import StockObject from "../types/StockObject";
|
|
2
|
+
import StockObjectMapper from "../types/StockObjectMapper";
|
|
3
|
+
export default class DeliveryMethods extends StockObject {
|
|
4
|
+
private key;
|
|
5
|
+
private active;
|
|
6
|
+
constructor(key: string, active: boolean);
|
|
7
|
+
getKey(): string;
|
|
8
|
+
getActive(): boolean;
|
|
9
|
+
setKey(key: string): string;
|
|
10
|
+
setActive(active: boolean): boolean;
|
|
11
|
+
protected getMapper(): StockObjectMapper;
|
|
12
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import DeliveryMethodsMapper from "../mappers/DeliveryMethodsMapper";
|
|
2
|
+
import StockObject from "../types/StockObject";
|
|
3
|
+
export default class DeliveryMethods extends StockObject {
|
|
4
|
+
key;
|
|
5
|
+
active;
|
|
6
|
+
constructor(key, active) {
|
|
7
|
+
super();
|
|
8
|
+
this.key = key;
|
|
9
|
+
this.active = active;
|
|
10
|
+
}
|
|
11
|
+
getKey() {
|
|
12
|
+
return this.key;
|
|
13
|
+
}
|
|
14
|
+
getActive() {
|
|
15
|
+
return this.active;
|
|
16
|
+
}
|
|
17
|
+
setKey(key) {
|
|
18
|
+
return this.key = key;
|
|
19
|
+
}
|
|
20
|
+
setActive(active) {
|
|
21
|
+
return this.active = active;
|
|
22
|
+
}
|
|
23
|
+
getMapper() {
|
|
24
|
+
return new DeliveryMethodsMapper(this);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -34,7 +34,7 @@ export default class Product extends StockObject {
|
|
|
34
34
|
getFileId(): number;
|
|
35
35
|
getDeleted(): boolean;
|
|
36
36
|
getFile(): Promise<FileI | null>;
|
|
37
|
-
getFiles(): Promise<FileI[]>;
|
|
37
|
+
getFiles(): Promise<FileI[] | null>;
|
|
38
38
|
setCreatedAt(createdAt: any): void;
|
|
39
39
|
protected getMapper(): StockObjectMapper;
|
|
40
40
|
}
|
|
@@ -87,8 +87,11 @@ export default class Product extends StockObject {
|
|
|
87
87
|
}
|
|
88
88
|
async getFiles() {
|
|
89
89
|
if (!this.files) {
|
|
90
|
-
const
|
|
91
|
-
|
|
90
|
+
const id = this.getId();
|
|
91
|
+
if (id) {
|
|
92
|
+
const files = await FilesReader.getForConnection(FileConnectionE.product, id);
|
|
93
|
+
this.files = files;
|
|
94
|
+
}
|
|
92
95
|
}
|
|
93
96
|
return this.files;
|
|
94
97
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import Table from '../Table';
|
|
2
2
|
import ClientAccountRow from '../types/rows/ClientAccountRow';
|
|
3
3
|
import Client from '../stockObjects/Client';
|
|
4
|
+
import QueryOptions from '../query/QueryOptions';
|
|
4
5
|
export default class ClientAccountsTable extends Table {
|
|
5
6
|
select(accountId: number): Promise<ClientAccountRow>;
|
|
7
|
+
selectEmail(id: number): Promise<string>;
|
|
8
|
+
count(queryOptions: QueryOptions): Promise<number>;
|
|
9
|
+
selectAll(queryOptions: QueryOptions): Promise<ClientAccountRow[]>;
|
|
6
10
|
selectForEmail(email: string): Promise<ClientAccountRow>;
|
|
7
|
-
selectIdForEmail(email: string): Promise<number>;
|
|
8
11
|
update(clientData: Client): Promise<void>;
|
|
9
12
|
delete(accountId: number): Promise<number>;
|
|
10
13
|
private bindParameters;
|
|
11
14
|
insert(clientAccount: Client): Promise<void>;
|
|
12
|
-
|
|
15
|
+
getIdForEmail(email: string): Promise<number>;
|
|
13
16
|
private selectNextId;
|
|
14
17
|
}
|
|
@@ -7,14 +7,26 @@ export default class ClientAccountsTable extends Table {
|
|
|
7
7
|
const result = await query.execute();
|
|
8
8
|
return result.getRow();
|
|
9
9
|
}
|
|
10
|
+
async selectEmail(id) {
|
|
11
|
+
const query = this.createQuery(SQL.accounts.selectEmail);
|
|
12
|
+
query.bindParameter('id', id);
|
|
13
|
+
const result = await query.execute();
|
|
14
|
+
return result.getValue();
|
|
15
|
+
}
|
|
16
|
+
async count(queryOptions) {
|
|
17
|
+
const query = this.createQuery(SQL.accounts.count, queryOptions);
|
|
18
|
+
const result = await query.execute();
|
|
19
|
+
return result.getValue();
|
|
20
|
+
}
|
|
21
|
+
async selectAll(queryOptions) {
|
|
22
|
+
const query = this.createQuery(SQL.accounts.selectAll, queryOptions);
|
|
23
|
+
const result = await query.execute();
|
|
24
|
+
return result.getRows();
|
|
25
|
+
}
|
|
10
26
|
async selectForEmail(email) {
|
|
11
27
|
const id = await this.getIdForEmail(email);
|
|
12
28
|
return await this.select(id);
|
|
13
29
|
}
|
|
14
|
-
async selectIdForEmail(email) {
|
|
15
|
-
const id = await this.getIdForEmail(email);
|
|
16
|
-
return id;
|
|
17
|
-
}
|
|
18
30
|
async update(clientData) {
|
|
19
31
|
const query = this.createQuery(SQL.accounts.update);
|
|
20
32
|
query.bindParameter('id', clientData.getId());
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import Table from '../Table';
|
|
2
2
|
import QueryOptionsI from '../types/QueryOptionsI';
|
|
3
3
|
import ProductRow from '../types/rows/ProductRow';
|
|
4
|
+
import Product from '../stockObjects/Product';
|
|
4
5
|
export default class ProductsTable extends Table {
|
|
5
6
|
select(productId: number): Promise<ProductRow>;
|
|
7
|
+
selectForSku(sku: string): Promise<ProductRow>;
|
|
8
|
+
selectIdForSku(sku: string): Promise<number>;
|
|
9
|
+
selectListForOrder(): Promise<ProductRow[]>;
|
|
6
10
|
selectAll(queryOption: QueryOptionsI): Promise<ProductRow[]>;
|
|
7
11
|
selectForUrl(url: string): Promise<ProductRow>;
|
|
12
|
+
insert(productData: Product): Promise<number>;
|
|
8
13
|
count(queryOption: QueryOptionsI): Promise<number>;
|
|
14
|
+
update(product: Product): Promise<boolean>;
|
|
15
|
+
delete(productId: number): Promise<number>;
|
|
16
|
+
restore(product: Product): Promise<number>;
|
|
17
|
+
private bindParameters;
|
|
18
|
+
private selectNextId;
|
|
9
19
|
}
|
|
@@ -7,6 +7,23 @@ export default class ProductsTable extends Table {
|
|
|
7
7
|
const result = await query.execute();
|
|
8
8
|
return result.getRow();
|
|
9
9
|
}
|
|
10
|
+
async selectForSku(sku) {
|
|
11
|
+
const query = this.createQuery(SQL.products.selectForSku);
|
|
12
|
+
query.bindParameter('sku', String(sku).toUpperCase());
|
|
13
|
+
const result = await query.execute();
|
|
14
|
+
return result.getRow();
|
|
15
|
+
}
|
|
16
|
+
async selectIdForSku(sku) {
|
|
17
|
+
const query = this.createQuery(SQL.products.selectIdForSku);
|
|
18
|
+
query.bindParameter('sku', String(sku).toUpperCase());
|
|
19
|
+
const result = await query.execute();
|
|
20
|
+
return result.getValue();
|
|
21
|
+
}
|
|
22
|
+
async selectListForOrder() {
|
|
23
|
+
const query = this.createQuery(SQL.products.selectListForOrder);
|
|
24
|
+
const result = await query.execute();
|
|
25
|
+
return result.getRows();
|
|
26
|
+
}
|
|
10
27
|
async selectAll(queryOption) {
|
|
11
28
|
const query = this.createQuery(SQL.products.selectAll, queryOption);
|
|
12
29
|
const result = await query.execute();
|
|
@@ -18,9 +35,64 @@ export default class ProductsTable extends Table {
|
|
|
18
35
|
const result = await query.execute();
|
|
19
36
|
return result.getRow();
|
|
20
37
|
}
|
|
38
|
+
async insert(productData) {
|
|
39
|
+
const sku = productData.getSku();
|
|
40
|
+
let productId = await this.selectIdForSku(sku);
|
|
41
|
+
if (productId)
|
|
42
|
+
throw new Error(`Product with SKU: ${sku} already exist!`);
|
|
43
|
+
else
|
|
44
|
+
productId = await this.selectNextId();
|
|
45
|
+
const query = this.createQuery(SQL.products.insert);
|
|
46
|
+
query.bindParameter('id', productId);
|
|
47
|
+
this.bindParameters(query, productData);
|
|
48
|
+
productData.setId(productId);
|
|
49
|
+
await query.execute();
|
|
50
|
+
return productId;
|
|
51
|
+
}
|
|
21
52
|
async count(queryOption) {
|
|
22
53
|
const query = this.createQuery(SQL.products.count, queryOption);
|
|
23
54
|
const result = await query.execute();
|
|
24
55
|
return result.getValue();
|
|
25
56
|
}
|
|
57
|
+
async update(product) {
|
|
58
|
+
const query = this.createQuery(SQL.products.update);
|
|
59
|
+
query.bindParameter('id', product.getId());
|
|
60
|
+
this.bindParameters(query, product);
|
|
61
|
+
await query.execute();
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
async delete(productId) {
|
|
65
|
+
const query = this.createQuery(SQL.products.delete);
|
|
66
|
+
query.bindParameter('id', productId);
|
|
67
|
+
const result = await query.execute();
|
|
68
|
+
return result.getRowCount();
|
|
69
|
+
}
|
|
70
|
+
async restore(product) {
|
|
71
|
+
const productId = await this.selectIdForSku(product.getSku());
|
|
72
|
+
if (productId)
|
|
73
|
+
throw Error(`This product cannot be restored because it has been edited. There is a newer version of this product (id: ${productId})`);
|
|
74
|
+
const query = this.createQuery(SQL.products.restore);
|
|
75
|
+
query.bindParameter('id', product.getId());
|
|
76
|
+
const result = await query.execute();
|
|
77
|
+
return result.getRowCount();
|
|
78
|
+
}
|
|
79
|
+
bindParameters(query, productData) {
|
|
80
|
+
query.bindParameter('sku', productData.getSku());
|
|
81
|
+
query.bindParameter('url', productData.getUrl());
|
|
82
|
+
query.bindParameter('title', productData.getTitle());
|
|
83
|
+
query.bindParameter('description', productData.getDescription());
|
|
84
|
+
query.bindParameter('net_price', productData.getNetPrice());
|
|
85
|
+
query.bindParameter('vat', productData.getVat());
|
|
86
|
+
query.bindParameter('color', productData.getColor());
|
|
87
|
+
query.bindParameter('quantity', productData.getQuantity());
|
|
88
|
+
query.bindParameter('width', productData.getWidth());
|
|
89
|
+
query.bindParameter('length', productData.getLength());
|
|
90
|
+
query.bindParameter('height', productData.getHeight());
|
|
91
|
+
query.bindParameter('file_id', productData.getFileId());
|
|
92
|
+
}
|
|
93
|
+
async selectNextId() {
|
|
94
|
+
const query = this.createQuery(SQL.products.selectNextId);
|
|
95
|
+
const result = await query.execute();
|
|
96
|
+
return result.getValue();
|
|
97
|
+
}
|
|
26
98
|
}
|
|
@@ -5,6 +5,6 @@ export default class ContactDetailsTable extends Table {
|
|
|
5
5
|
select(contactDetailsId: number): Promise<ContactDetailsRow>;
|
|
6
6
|
insert(contactDetails: ContactDetails): Promise<void>;
|
|
7
7
|
update(contactDetails: ContactDetails): Promise<void>;
|
|
8
|
-
|
|
8
|
+
selectNextId(): Promise<number>;
|
|
9
9
|
private bindParameters;
|
|
10
10
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import Table from '../../Table';
|
|
2
2
|
import DeliveryMethodI from '../../types/DeliveryMethodI';
|
|
3
|
+
import DeliveryMethodRow from '../../types/rows/DeliveryMethodRow';
|
|
4
|
+
import DeliveryMethods from '../../stockObjects/DeliveryMethods';
|
|
3
5
|
export default class DeliveryMethodsTable extends Table {
|
|
4
6
|
select(id: number): Promise<DeliveryMethodI>;
|
|
5
7
|
selectAll(): Promise<DeliveryMethodI[]>;
|
|
8
|
+
selectAllActive(): Promise<DeliveryMethodRow[]>;
|
|
9
|
+
insert(deliveryMethods: DeliveryMethods): Promise<boolean>;
|
|
10
|
+
update(deliveryMethods: DeliveryMethods): Promise<boolean>;
|
|
11
|
+
private selectNextId;
|
|
6
12
|
}
|
|
@@ -12,4 +12,32 @@ export default class DeliveryMethodsTable extends Table {
|
|
|
12
12
|
const result = await query.execute();
|
|
13
13
|
return result.getRows();
|
|
14
14
|
}
|
|
15
|
+
async selectAllActive() {
|
|
16
|
+
const query = this.createQuery(SQL.deliveryMethods.selectAllActive);
|
|
17
|
+
const result = await query.execute();
|
|
18
|
+
return result.getRows();
|
|
19
|
+
}
|
|
20
|
+
async insert(deliveryMethods) {
|
|
21
|
+
const id = await this.selectNextId();
|
|
22
|
+
const query = this.createQuery(SQL.deliveryMethods.insert);
|
|
23
|
+
query.bindParameter('id', id);
|
|
24
|
+
query.bindParameter('key', deliveryMethods.getKey());
|
|
25
|
+
query.bindParameter('active', deliveryMethods.getActive());
|
|
26
|
+
await query.execute();
|
|
27
|
+
deliveryMethods.setId(id);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
async update(deliveryMethods) {
|
|
31
|
+
const query = this.createQuery(SQL.deliveryMethods.update);
|
|
32
|
+
query.bindParameter('id', deliveryMethods.getId());
|
|
33
|
+
query.bindParameter('key', deliveryMethods.getKey());
|
|
34
|
+
query.bindParameter('active', deliveryMethods.getActive());
|
|
35
|
+
await query.execute();
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
async selectNextId() {
|
|
39
|
+
const query = this.createQuery(SQL.deliveryMethods.selectNextId);
|
|
40
|
+
const result = await query.execute();
|
|
41
|
+
return result.getValue();
|
|
42
|
+
}
|
|
15
43
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
declare enum ParameterType {
|
|
2
2
|
arrayNumber = 0,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
arrayBigint = 1,
|
|
4
|
+
arrayString = 2,
|
|
5
|
+
arrayBoolean = 3,
|
|
6
|
+
arrayValue = 4,
|
|
7
|
+
arrayObject = 5,
|
|
8
|
+
bigint = 6,
|
|
9
|
+
smallint = 7,
|
|
10
|
+
number = 8,
|
|
11
|
+
string = 9,
|
|
12
|
+
boolean = 10,
|
|
13
|
+
object = 11,
|
|
14
|
+
column = 12
|
|
12
15
|
}
|
|
13
16
|
export default ParameterType;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
var ParameterType;
|
|
2
2
|
(function (ParameterType) {
|
|
3
3
|
ParameterType[ParameterType["arrayNumber"] = 0] = "arrayNumber";
|
|
4
|
-
ParameterType[ParameterType["
|
|
5
|
-
ParameterType[ParameterType["
|
|
6
|
-
ParameterType[ParameterType["
|
|
7
|
-
ParameterType[ParameterType["
|
|
8
|
-
ParameterType[ParameterType["
|
|
9
|
-
ParameterType[ParameterType["
|
|
10
|
-
ParameterType[ParameterType["
|
|
11
|
-
ParameterType[ParameterType["
|
|
12
|
-
ParameterType[ParameterType["
|
|
4
|
+
ParameterType[ParameterType["arrayBigint"] = 1] = "arrayBigint";
|
|
5
|
+
ParameterType[ParameterType["arrayString"] = 2] = "arrayString";
|
|
6
|
+
ParameterType[ParameterType["arrayBoolean"] = 3] = "arrayBoolean";
|
|
7
|
+
ParameterType[ParameterType["arrayValue"] = 4] = "arrayValue";
|
|
8
|
+
ParameterType[ParameterType["arrayObject"] = 5] = "arrayObject";
|
|
9
|
+
ParameterType[ParameterType["bigint"] = 6] = "bigint";
|
|
10
|
+
ParameterType[ParameterType["smallint"] = 7] = "smallint";
|
|
11
|
+
ParameterType[ParameterType["number"] = 8] = "number";
|
|
12
|
+
ParameterType[ParameterType["string"] = 9] = "string";
|
|
13
|
+
ParameterType[ParameterType["boolean"] = 10] = "boolean";
|
|
14
|
+
ParameterType[ParameterType["object"] = 11] = "object";
|
|
15
|
+
ParameterType[ParameterType["column"] = 12] = "column";
|
|
13
16
|
})(ParameterType || (ParameterType = {}));
|
|
14
17
|
export default ParameterType;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export default class Filters {
|
|
2
|
+
static email(value) {
|
|
3
|
+
value = value.trimStart();
|
|
4
|
+
value = value.trimEnd();
|
|
5
|
+
value = value.replace(/[^\w\.-@]/g, "");
|
|
6
|
+
value = value.substring(0, 99);
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
static phoneNumber(value) {
|
|
10
|
+
value = value.trimStart();
|
|
11
|
+
value = value.trimEnd();
|
|
12
|
+
value = value.replace(/[^\d\+48]/g, "");
|
|
13
|
+
value = value.substring(0, 99);
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
static sanitizeString(value) {
|
|
17
|
+
value = value.trimStart();
|
|
18
|
+
value = value.trimEnd();
|
|
19
|
+
value = value.replaceAll(/<[^>]*>/g, '');
|
|
20
|
+
value = value.replace(/[^a-zA-Z0-9-żźćńółęąśŻŹĆĄŚĘŁÓŃ\ ]/g, "");
|
|
21
|
+
value = value.substring(0, 99);
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
static databaseColumn(value) {
|
|
25
|
+
value = value.trimStart();
|
|
26
|
+
value = value.trimEnd();
|
|
27
|
+
value = value.replace(/[^a-zA-Z\_]/g, "");
|
|
28
|
+
value = value.substring(0, 99);
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ParameterType from "../types/parameters/ParameterType";
|
|
2
|
+
import Filters from "./Filters";
|
|
3
|
+
import ParameterConversionSystem from "./parameters/ParameterConversionSystem";
|
|
4
|
+
import ParameterFilterSystem from "./parameters/ParameterFilterSystem";
|
|
5
|
+
import ParameterRulesSystem from "./parameters/ParameterRulesSystem";
|
|
6
|
+
export default class Parameters {
|
|
7
|
+
static correct(parameter, parameterFilter) {
|
|
8
|
+
let correctedParameter = ParameterConversionSystem.convert(parameter, parameterFilter.type);
|
|
9
|
+
if (!parameterFilter.filter && this.isParameterValueString(parameterFilter.type))
|
|
10
|
+
parameterFilter.filter = Filters.sanitizeString;
|
|
11
|
+
if (parameterFilter.filter)
|
|
12
|
+
correctedParameter = ParameterFilterSystem.filter(correctedParameter, parameterFilter);
|
|
13
|
+
if (parameterFilter.rules)
|
|
14
|
+
correctedParameter = ParameterRulesSystem.validate(correctedParameter, parameterFilter.rules);
|
|
15
|
+
return correctedParameter;
|
|
16
|
+
}
|
|
17
|
+
static isParameterValueString(type) {
|
|
18
|
+
if (type == ParameterType.string || type == ParameterType.arrayString)
|
|
19
|
+
return true;
|
|
20
|
+
else
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import ParameterType from "../../types/parameters/ParameterType";
|
|
2
|
+
export default class ParameterConversionSystem {
|
|
3
|
+
static convert(parameter, type) {
|
|
4
|
+
switch (type) {
|
|
5
|
+
case ParameterType.number: return Number(parameter);
|
|
6
|
+
case ParameterType.string: return String(parameter);
|
|
7
|
+
case ParameterType.boolean: return Boolean(parameter);
|
|
8
|
+
case ParameterType.object: return JSON.parse(parameter);
|
|
9
|
+
case ParameterType.bigint: return BigInt(parameter);
|
|
10
|
+
case ParameterType.arrayNumber: return this.convertArray(parameter, ParameterType.number);
|
|
11
|
+
case ParameterType.arrayString: return this.convertArray(parameter, ParameterType.string);
|
|
12
|
+
case ParameterType.arrayBoolean: return this.convertArray(parameter, ParameterType.boolean);
|
|
13
|
+
case ParameterType.arrayObject: return this.convertArray(parameter, ParameterType.object);
|
|
14
|
+
case ParameterType.arrayBigint: return this.convertArray(parameter, ParameterType.bigint);
|
|
15
|
+
case ParameterType.column: return String(parameter);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
static convertArray(parameterArray, type) {
|
|
19
|
+
if (!Array.isArray(parameterArray)) {
|
|
20
|
+
if (parameterArray)
|
|
21
|
+
parameterArray = [parameterArray];
|
|
22
|
+
else
|
|
23
|
+
parameterArray = [];
|
|
24
|
+
}
|
|
25
|
+
const convertedParameterArray = parameterArray.map(parameter => this.convert(parameter, type));
|
|
26
|
+
return convertedParameterArray;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import ParameterType from "../../types/parameters/ParameterType";
|
|
2
|
+
export default class ParameterFilterSystem {
|
|
3
|
+
static filter(parameter, parameterFilter) {
|
|
4
|
+
switch (parameterFilter.type) {
|
|
5
|
+
case ParameterType.string: return parameterFilter.filter(parameter);
|
|
6
|
+
case ParameterType.arrayString:
|
|
7
|
+
return parameter.map((stringParameter) => parameterFilter.filter(stringParameter));
|
|
8
|
+
default: return parameter;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dascompany/database",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "vitest",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"keywords": [],
|
|
15
15
|
"author": "",
|
|
16
16
|
"license": "ISC",
|
|
17
|
-
"description": "",
|
|
17
|
+
"description": "@Dascompany/repo",
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"types": "^0.1.1",
|
|
20
20
|
"typescript": "^5.7.3",
|