@sdflc/backend-helpers 1.0.84 → 1.0.86
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/build/BaseCore.js +1 -1
- package/build/BaseGateway.js +9 -4
- package/build/{dbMigratorAndSeeder.js → DbMigratorAndSeeder.js} +0 -20
- package/build/dbTableHelpers.d.ts +1 -0
- package/build/dbTableHelpers.js +12 -4
- package/build/esm/BaseCore.js +1 -1
- package/build/esm/BaseGateway.js +9 -4
- package/build/esm/{dbMigratorAndSeeder.js → DbMigratorAndSeeder.js} +0 -20
- package/build/esm/dbTableHelpers.d.ts +1 -0
- package/build/esm/dbTableHelpers.js +10 -3
- package/build/esm/index.d.ts +1 -1
- package/build/esm/index.js +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -1
- package/package.json +1 -1
- /package/build/{dbMigratorAndSeeder.d.ts → DbMigratorAndSeeder.d.ts} +0 -0
- /package/build/esm/{dbMigratorAndSeeder.d.ts → DbMigratorAndSeeder.d.ts} +0 -0
package/build/BaseCore.js
CHANGED
|
@@ -346,7 +346,7 @@ class BaseCore {
|
|
|
346
346
|
action: async (args, opt) => {
|
|
347
347
|
const { params } = args || {};
|
|
348
348
|
if (this.config.hasOrderNo === true) {
|
|
349
|
-
this.setOrderNo({
|
|
349
|
+
await this.setOrderNo({
|
|
350
350
|
params,
|
|
351
351
|
filter: this.getFilterToSetOrderNo({ params, opt }),
|
|
352
352
|
gateway: this.getGatewayToSetOrerNo(),
|
package/build/BaseGateway.js
CHANGED
|
@@ -57,7 +57,7 @@ class BaseGateway {
|
|
|
57
57
|
const { table, hasStatus, hasRemovedAt, hasSpace, activeStatuses, hasLang, fieldForKeyword, filterByUserField } = this.config || {};
|
|
58
58
|
// This function should be overriden
|
|
59
59
|
if (hasStatus) {
|
|
60
|
-
query.whereIn(`${table}.${constants_1.FIELDS.STATUS}`,
|
|
60
|
+
query.whereIn(`${table}.${constants_1.FIELDS.STATUS}`, filterParams?.[constants_1.FIELDS.STATUS] != null ? (0, lodash_1.castArray)(filterParams?.[constants_1.FIELDS.STATUS]) : (0, lodash_1.castArray)(activeStatuses));
|
|
61
61
|
}
|
|
62
62
|
if (hasRemovedAt) {
|
|
63
63
|
query.whereNull(`${table}.${constants_1.FIELDS.REMOVED_AT}`);
|
|
@@ -113,10 +113,15 @@ class BaseGateway {
|
|
|
113
113
|
const { hasStatus } = this.config;
|
|
114
114
|
const arr = filterParams ? (0, lodash_1.castArray)(filterParams) : [];
|
|
115
115
|
let filtersAppliedQty = 1;
|
|
116
|
-
|
|
116
|
+
const idName = this.getIdFieldUpdateRemove();
|
|
117
|
+
const ids = [];
|
|
118
|
+
for (let filter of arr) {
|
|
119
|
+
if (filter[idName]) {
|
|
120
|
+
ids.push(filter[idName]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (ids.length > 0) {
|
|
117
124
|
filtersAppliedQty++;
|
|
118
|
-
const idName = this.getIdFieldUpdateRemove();
|
|
119
|
-
query = query.whereIn(idName, arr.map((item) => item[idName]));
|
|
120
125
|
}
|
|
121
126
|
if (hasStatus === true) {
|
|
122
127
|
filtersAppliedQty++;
|
|
@@ -62,26 +62,6 @@ const SQLS = {
|
|
|
62
62
|
FROM INFORMATION_SCHEMA.TABLES';
|
|
63
63
|
`,
|
|
64
64
|
},
|
|
65
|
-
mssql: {
|
|
66
|
-
listTablesSchema: (appSettings) => `
|
|
67
|
-
SELECT TABLE_NAME as table_name
|
|
68
|
-
FROM INFORMATION_SCHEMA.TABLES
|
|
69
|
-
WHERE TABLE_SCHEMA = '${appSettings?.dbSchema}';
|
|
70
|
-
`,
|
|
71
|
-
listTables: () => `
|
|
72
|
-
SELECT TABLE_NAME as table_name
|
|
73
|
-
FROM INFORMATION_SCHEMA.TABLES
|
|
74
|
-
`,
|
|
75
|
-
dropTablesSchema: (appSettings) => `
|
|
76
|
-
SELECT 'DROP TABLE IF EXISTS [${appSettings?.dbSchema}].[' + TABLE_NAME + '];' as cmd
|
|
77
|
-
FROM INFORMATION_SCHEMA.TABLES
|
|
78
|
-
WHERE TABLE_SCHEMA = '${appSettings?.dbSchema}';
|
|
79
|
-
`,
|
|
80
|
-
dropTables: () => `
|
|
81
|
-
SELECT 'DROP TABLE IF EXISTS ' + TABLE_NAME + ';' as cmd
|
|
82
|
-
FROM INFORMATION_SCHEMA.TABLES';
|
|
83
|
-
`,
|
|
84
|
-
},
|
|
85
65
|
};
|
|
86
66
|
class DbMigratorAndSeeder {
|
|
87
67
|
knexHandle;
|
|
@@ -2,6 +2,7 @@ import { DbFieldAddDefaultInterface } from './interfaces';
|
|
|
2
2
|
import { FIELDS } from './constants';
|
|
3
3
|
export declare const dbFieldAddDefaults: (table: any, opt?: DbFieldAddDefaultInterface) => void;
|
|
4
4
|
export declare const addOrderNo: (table: any, opt?: any) => any;
|
|
5
|
+
export declare const addOrderNoNum: (table: any, opt?: any) => any;
|
|
5
6
|
export declare const addAmount: (table: any, fieldName: string) => any;
|
|
6
7
|
export declare const addSpaceId: (table: any, opt?: any) => any;
|
|
7
8
|
export declare const addUserId: (table: any, opt?: any) => any;
|
package/build/dbTableHelpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultFields = exports.addLang = exports.addAccountId = exports.addUserId = exports.addSpaceId = exports.addAmount = exports.addOrderNo = exports.dbFieldAddDefaults = void 0;
|
|
3
|
+
exports.defaultFields = exports.addLang = exports.addAccountId = exports.addUserId = exports.addSpaceId = exports.addAmount = exports.addOrderNoNum = exports.addOrderNo = exports.dbFieldAddDefaults = void 0;
|
|
4
4
|
const utils_1 = require("@sdflc/utils");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const dbFieldAddDefaults = (table, opt) => {
|
|
@@ -29,7 +29,7 @@ const dbFieldAddDefaults = (table, opt) => {
|
|
|
29
29
|
.dateTime(constants_1.FIELDS.REMOVED_AT)
|
|
30
30
|
.comment('Date and time of removal. As it is nullable it cannot be used in any unique index');
|
|
31
31
|
if (skipRemovedAtStr !== true) {
|
|
32
|
-
table.
|
|
32
|
+
table.string(constants_1.FIELDS.REMOVED_AT_STR, 32).defaultTo('').comment('Used to create unique indexes.');
|
|
33
33
|
}
|
|
34
34
|
table.index([constants_1.FIELDS.CREATED_AT]);
|
|
35
35
|
table.index([constants_1.FIELDS.UPDATED_AT]);
|
|
@@ -50,12 +50,20 @@ const addOrderNo = (table, opt) => {
|
|
|
50
50
|
return chain;
|
|
51
51
|
};
|
|
52
52
|
exports.addOrderNo = addOrderNo;
|
|
53
|
+
const addOrderNoNum = (table, opt) => {
|
|
54
|
+
const chain = table.decimal(constants_1.FIELDS.ORDER_NO, 30, 15).notNullable().defaultTo(1000000).comment('Display order');
|
|
55
|
+
if (opt?.addIndex === true) {
|
|
56
|
+
table.index([constants_1.FIELDS.ORDER_NO]);
|
|
57
|
+
}
|
|
58
|
+
return chain;
|
|
59
|
+
};
|
|
60
|
+
exports.addOrderNoNum = addOrderNoNum;
|
|
53
61
|
const addAmount = (table, fieldName) => {
|
|
54
62
|
return table.decimal(fieldName, 19, 4);
|
|
55
63
|
};
|
|
56
64
|
exports.addAmount = addAmount;
|
|
57
65
|
const addSpaceId = (table, opt) => {
|
|
58
|
-
const chain = table.
|
|
66
|
+
const chain = table.string(constants_1.FIELDS.SPACE_ID, 128).notNullable().comment('Reference to the space table');
|
|
59
67
|
if (opt?.addForeignKey === true) {
|
|
60
68
|
table.foreign(constants_1.FIELDS.SPACE_ID).references(`space.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
|
|
61
69
|
}
|
|
@@ -74,7 +82,7 @@ const addUserId = (table, opt) => {
|
|
|
74
82
|
};
|
|
75
83
|
exports.addUserId = addUserId;
|
|
76
84
|
const addAccountId = (table, opt) => {
|
|
77
|
-
const chain = table.uuid(constants_1.FIELDS.ACCOUNT_ID).notNullable().comment('Reference to the
|
|
85
|
+
const chain = table.uuid(constants_1.FIELDS.ACCOUNT_ID).notNullable().comment('Reference to the account table');
|
|
78
86
|
if (opt?.addForeignKey === true) {
|
|
79
87
|
table.foreign(constants_1.FIELDS.ACCOUNT_ID).references(`account.${constants_1.FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
|
|
80
88
|
}
|
package/build/esm/BaseCore.js
CHANGED
|
@@ -340,7 +340,7 @@ class BaseCore {
|
|
|
340
340
|
action: async (args, opt) => {
|
|
341
341
|
const { params } = args || {};
|
|
342
342
|
if (this.config.hasOrderNo === true) {
|
|
343
|
-
this.setOrderNo({
|
|
343
|
+
await this.setOrderNo({
|
|
344
344
|
params,
|
|
345
345
|
filter: this.getFilterToSetOrderNo({ params, opt }),
|
|
346
346
|
gateway: this.getGatewayToSetOrerNo(),
|
package/build/esm/BaseGateway.js
CHANGED
|
@@ -51,7 +51,7 @@ class BaseGateway {
|
|
|
51
51
|
const { table, hasStatus, hasRemovedAt, hasSpace, activeStatuses, hasLang, fieldForKeyword, filterByUserField } = this.config || {};
|
|
52
52
|
// This function should be overriden
|
|
53
53
|
if (hasStatus) {
|
|
54
|
-
query.whereIn(`${table}.${FIELDS.STATUS}`,
|
|
54
|
+
query.whereIn(`${table}.${FIELDS.STATUS}`, filterParams?.[FIELDS.STATUS] != null ? castArray(filterParams?.[FIELDS.STATUS]) : castArray(activeStatuses));
|
|
55
55
|
}
|
|
56
56
|
if (hasRemovedAt) {
|
|
57
57
|
query.whereNull(`${table}.${FIELDS.REMOVED_AT}`);
|
|
@@ -107,10 +107,15 @@ class BaseGateway {
|
|
|
107
107
|
const { hasStatus } = this.config;
|
|
108
108
|
const arr = filterParams ? castArray(filterParams) : [];
|
|
109
109
|
let filtersAppliedQty = 1;
|
|
110
|
-
|
|
110
|
+
const idName = this.getIdFieldUpdateRemove();
|
|
111
|
+
const ids = [];
|
|
112
|
+
for (let filter of arr) {
|
|
113
|
+
if (filter[idName]) {
|
|
114
|
+
ids.push(filter[idName]);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (ids.length > 0) {
|
|
111
118
|
filtersAppliedQty++;
|
|
112
|
-
const idName = this.getIdFieldUpdateRemove();
|
|
113
|
-
query = query.whereIn(idName, arr.map((item) => item[idName]));
|
|
114
119
|
}
|
|
115
120
|
if (hasStatus === true) {
|
|
116
121
|
filtersAppliedQty++;
|
|
@@ -23,26 +23,6 @@ const SQLS = {
|
|
|
23
23
|
FROM INFORMATION_SCHEMA.TABLES';
|
|
24
24
|
`,
|
|
25
25
|
},
|
|
26
|
-
mssql: {
|
|
27
|
-
listTablesSchema: (appSettings) => `
|
|
28
|
-
SELECT TABLE_NAME as table_name
|
|
29
|
-
FROM INFORMATION_SCHEMA.TABLES
|
|
30
|
-
WHERE TABLE_SCHEMA = '${appSettings?.dbSchema}';
|
|
31
|
-
`,
|
|
32
|
-
listTables: () => `
|
|
33
|
-
SELECT TABLE_NAME as table_name
|
|
34
|
-
FROM INFORMATION_SCHEMA.TABLES
|
|
35
|
-
`,
|
|
36
|
-
dropTablesSchema: (appSettings) => `
|
|
37
|
-
SELECT 'DROP TABLE IF EXISTS [${appSettings?.dbSchema}].[' + TABLE_NAME + '];' as cmd
|
|
38
|
-
FROM INFORMATION_SCHEMA.TABLES
|
|
39
|
-
WHERE TABLE_SCHEMA = '${appSettings?.dbSchema}';
|
|
40
|
-
`,
|
|
41
|
-
dropTables: () => `
|
|
42
|
-
SELECT 'DROP TABLE IF EXISTS ' + TABLE_NAME + ';' as cmd
|
|
43
|
-
FROM INFORMATION_SCHEMA.TABLES';
|
|
44
|
-
`,
|
|
45
|
-
},
|
|
46
26
|
};
|
|
47
27
|
class DbMigratorAndSeeder {
|
|
48
28
|
knexHandle;
|
|
@@ -2,6 +2,7 @@ import { DbFieldAddDefaultInterface } from './interfaces';
|
|
|
2
2
|
import { FIELDS } from './constants';
|
|
3
3
|
export declare const dbFieldAddDefaults: (table: any, opt?: DbFieldAddDefaultInterface) => void;
|
|
4
4
|
export declare const addOrderNo: (table: any, opt?: any) => any;
|
|
5
|
+
export declare const addOrderNoNum: (table: any, opt?: any) => any;
|
|
5
6
|
export declare const addAmount: (table: any, fieldName: string) => any;
|
|
6
7
|
export declare const addSpaceId: (table: any, opt?: any) => any;
|
|
7
8
|
export declare const addUserId: (table: any, opt?: any) => any;
|
|
@@ -26,7 +26,7 @@ export const dbFieldAddDefaults = (table, opt) => {
|
|
|
26
26
|
.dateTime(FIELDS.REMOVED_AT)
|
|
27
27
|
.comment('Date and time of removal. As it is nullable it cannot be used in any unique index');
|
|
28
28
|
if (skipRemovedAtStr !== true) {
|
|
29
|
-
table.
|
|
29
|
+
table.string(FIELDS.REMOVED_AT_STR, 32).defaultTo('').comment('Used to create unique indexes.');
|
|
30
30
|
}
|
|
31
31
|
table.index([FIELDS.CREATED_AT]);
|
|
32
32
|
table.index([FIELDS.UPDATED_AT]);
|
|
@@ -45,11 +45,18 @@ export const addOrderNo = (table, opt) => {
|
|
|
45
45
|
}
|
|
46
46
|
return chain;
|
|
47
47
|
};
|
|
48
|
+
export const addOrderNoNum = (table, opt) => {
|
|
49
|
+
const chain = table.decimal(FIELDS.ORDER_NO, 30, 15).notNullable().defaultTo(1000000).comment('Display order');
|
|
50
|
+
if (opt?.addIndex === true) {
|
|
51
|
+
table.index([FIELDS.ORDER_NO]);
|
|
52
|
+
}
|
|
53
|
+
return chain;
|
|
54
|
+
};
|
|
48
55
|
export const addAmount = (table, fieldName) => {
|
|
49
56
|
return table.decimal(fieldName, 19, 4);
|
|
50
57
|
};
|
|
51
58
|
export const addSpaceId = (table, opt) => {
|
|
52
|
-
const chain = table.
|
|
59
|
+
const chain = table.string(FIELDS.SPACE_ID, 128).notNullable().comment('Reference to the space table');
|
|
53
60
|
if (opt?.addForeignKey === true) {
|
|
54
61
|
table.foreign(FIELDS.SPACE_ID).references(`space.${FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
|
|
55
62
|
}
|
|
@@ -66,7 +73,7 @@ export const addUserId = (table, opt) => {
|
|
|
66
73
|
return chain;
|
|
67
74
|
};
|
|
68
75
|
export const addAccountId = (table, opt) => {
|
|
69
|
-
const chain = table.uuid(FIELDS.ACCOUNT_ID).notNullable().comment('Reference to the
|
|
76
|
+
const chain = table.uuid(FIELDS.ACCOUNT_ID).notNullable().comment('Reference to the account table');
|
|
70
77
|
if (opt?.addForeignKey === true) {
|
|
71
78
|
table.foreign(FIELDS.ACCOUNT_ID).references(`account.${FIELDS.ID}`).onUpdate('CASCADE').onDelete('CASCADE');
|
|
72
79
|
}
|
package/build/esm/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export * from './interfaces';
|
|
|
3
3
|
export * from './configBulder';
|
|
4
4
|
export * from './Database';
|
|
5
5
|
export * from './dbHelpers';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './DbMigratorAndSeeder';
|
|
7
7
|
export * from './dbSeeder';
|
|
8
8
|
export * from './knexConfigBuilder';
|
|
9
9
|
export * from './redisClient';
|
package/build/esm/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export * from './interfaces';
|
|
|
3
3
|
export * from './configBulder';
|
|
4
4
|
export * from './Database';
|
|
5
5
|
export * from './dbHelpers';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './DbMigratorAndSeeder';
|
|
7
7
|
export * from './dbSeeder';
|
|
8
8
|
export * from './knexConfigBuilder';
|
|
9
9
|
export * from './redisClient';
|
package/build/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export * from './interfaces';
|
|
|
3
3
|
export * from './configBulder';
|
|
4
4
|
export * from './Database';
|
|
5
5
|
export * from './dbHelpers';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './DbMigratorAndSeeder';
|
|
7
7
|
export * from './dbSeeder';
|
|
8
8
|
export * from './knexConfigBuilder';
|
|
9
9
|
export * from './redisClient';
|
package/build/index.js
CHANGED
|
@@ -19,7 +19,7 @@ __exportStar(require("./interfaces"), exports);
|
|
|
19
19
|
__exportStar(require("./configBulder"), exports);
|
|
20
20
|
__exportStar(require("./Database"), exports);
|
|
21
21
|
__exportStar(require("./dbHelpers"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./DbMigratorAndSeeder"), exports);
|
|
23
23
|
__exportStar(require("./dbSeeder"), exports);
|
|
24
24
|
__exportStar(require("./knexConfigBuilder"), exports);
|
|
25
25
|
__exportStar(require("./redisClient"), exports);
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|