@digione/node-custom-api 0.1.4 → 0.1.6-beta1
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/package.json +1 -1
- package/utils/stream.js +34 -3
- package/utils/validator.d.ts +2 -1
- package/utils/validator.js +24 -1
package/package.json
CHANGED
package/utils/stream.js
CHANGED
|
@@ -572,6 +572,11 @@ class StreamUtil {
|
|
|
572
572
|
field_data['code']['field_value'] = default_value[field_data['code']['field_target']] || field_data['code']['field_value'];
|
|
573
573
|
}
|
|
574
574
|
}
|
|
575
|
+
else if (item['field_type'] == "map") {
|
|
576
|
+
if (field_data['range'] && field_data['range']['field_target']) {
|
|
577
|
+
field_data['range']['field_value'] = default_value[field_data['range']['field_target']];
|
|
578
|
+
}
|
|
579
|
+
}
|
|
575
580
|
}
|
|
576
581
|
fields.push(Object.assign(Object.assign({}, item), { field_data }));
|
|
577
582
|
}
|
|
@@ -1468,7 +1473,7 @@ class StreamUtil {
|
|
|
1468
1473
|
opt['defaultValue'] = field_data['default_value'];
|
|
1469
1474
|
}
|
|
1470
1475
|
if (changeTable) {
|
|
1471
|
-
let fields = [];
|
|
1476
|
+
let fields = [], range = {};
|
|
1472
1477
|
switch (field['field_type']) {
|
|
1473
1478
|
case (field['is_lang'] == "yes" ? field['field_type'] : ""):
|
|
1474
1479
|
opt['defaultValue'] = undefined;
|
|
@@ -1510,7 +1515,7 @@ class StreamUtil {
|
|
|
1510
1515
|
break;
|
|
1511
1516
|
case "datetime":
|
|
1512
1517
|
fields = [field_slug];
|
|
1513
|
-
|
|
1518
|
+
range = field_data['range'] || {};
|
|
1514
1519
|
if (range['field_target']) {
|
|
1515
1520
|
fields.push(range['field_target']);
|
|
1516
1521
|
}
|
|
@@ -1560,6 +1565,16 @@ class StreamUtil {
|
|
|
1560
1565
|
opt['defaultValue'] = _.isNumber(opt['defaultValue']) ? opt['defaultValue'] : undefined;
|
|
1561
1566
|
yield (0, db_1.addColumn)(`${this.ref}_${table}`, field_slug, Object.assign({ type: sequelize.INTEGER({ length: 11 }) }, opt));
|
|
1562
1567
|
break;
|
|
1568
|
+
case "map":
|
|
1569
|
+
fields = [field_slug];
|
|
1570
|
+
range = field_data['range'] || {};
|
|
1571
|
+
if (range['field_target']) {
|
|
1572
|
+
fields.push(range['field_target']);
|
|
1573
|
+
}
|
|
1574
|
+
for (let field_slug of fields) {
|
|
1575
|
+
yield (0, db_1.addColumn)(`${this.ref}_${table}`, field_slug, Object.assign({ type: sequelize.STRING(20) }, opt));
|
|
1576
|
+
}
|
|
1577
|
+
break;
|
|
1563
1578
|
}
|
|
1564
1579
|
}
|
|
1565
1580
|
}
|
|
@@ -1711,8 +1726,15 @@ class StreamUtil {
|
|
|
1711
1726
|
case "multiple":
|
|
1712
1727
|
field_data = _.pick(field_data, ['choose_stream', 'skip_data', 'self_table', 'regex']);
|
|
1713
1728
|
break;
|
|
1729
|
+
case "map":
|
|
1730
|
+
if (field_data['range.field_target']) {
|
|
1731
|
+
let result = dottie.transform(field_data);
|
|
1732
|
+
field_data['range'] = result['range'];
|
|
1733
|
+
}
|
|
1734
|
+
field_data = _.pick(field_data, ['range']);
|
|
1735
|
+
break;
|
|
1714
1736
|
default:
|
|
1715
|
-
field_data =
|
|
1737
|
+
field_data = {};
|
|
1716
1738
|
break;
|
|
1717
1739
|
}
|
|
1718
1740
|
return field_data;
|
|
@@ -1843,6 +1865,15 @@ class StreamUtil {
|
|
|
1843
1865
|
field = Joi.alternatives(Joi.number(), field);
|
|
1844
1866
|
}
|
|
1845
1867
|
break;
|
|
1868
|
+
case "map":
|
|
1869
|
+
field = Joi.string();
|
|
1870
|
+
if (!is_required)
|
|
1871
|
+
field = field.allow(null, '');
|
|
1872
|
+
if (field_data['range'] && field_data['range']['field_target']) {
|
|
1873
|
+
schema[field_data['range']['field_target']] = field.regex(/^(\+|-)?(?:180(?:(?:\.0{1,6})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\.[0-9]{1,6})?))$/).messages({ 'string.pattern.base': `${field_slug} invalid format` });
|
|
1874
|
+
}
|
|
1875
|
+
field = field.regex(/^(\+|-)?(?:90(?:(?:\.0{1,6})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,6})?))$/).messages({ 'string.pattern.base': `${field_slug} invalid format` });
|
|
1876
|
+
break;
|
|
1846
1877
|
}
|
|
1847
1878
|
field = field || Joi.any();
|
|
1848
1879
|
if (is_required)
|
package/utils/validator.d.ts
CHANGED
|
@@ -12,11 +12,12 @@ export declare const validate: (schema: Joi.AnySchema, body?: any, { arrayIndex,
|
|
|
12
12
|
arrayIndex?: boolean;
|
|
13
13
|
prefixMessage?: string;
|
|
14
14
|
}) => Promise<any>;
|
|
15
|
-
export declare const validateService: (schema: Joi.ObjectSchema, { organ_id, created_by, web_id, purgeUpdate }?: {
|
|
15
|
+
export declare const validateService: (schema: Joi.ObjectSchema, { organ_id, created_by, web_id, purgeUpdate, field_omit }?: {
|
|
16
16
|
organ_id?: boolean;
|
|
17
17
|
created_by?: boolean;
|
|
18
18
|
web_id?: boolean;
|
|
19
19
|
purgeUpdate?: boolean;
|
|
20
|
+
field_omit?: string[];
|
|
20
21
|
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
21
22
|
export declare const paramService: (schema: Joi.AnySchema) => (req: any, res: any, next: any) => Promise<any>;
|
|
22
23
|
export declare const fileService: (setup: any, { userfiles, required, fileSize, fileTypes, maxCount, qualityImage, resizeImage }?: OptionFile) => (req: any, res: any, next: any) => any;
|
package/utils/validator.js
CHANGED
|
@@ -40,7 +40,7 @@ const validate = (schema, body = {}, { arrayIndex = false, prefixMessage = "" }
|
|
|
40
40
|
return result.value;
|
|
41
41
|
});
|
|
42
42
|
exports.validate = validate;
|
|
43
|
-
const validateService = (schema, { organ_id = true, created_by = true, web_id = true, purgeUpdate = true } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
const validateService = (schema, { organ_id = true, created_by = true, web_id = true, purgeUpdate = true, field_omit = ["id"] } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
44
44
|
if (created_by) {
|
|
45
45
|
const token = req.headers['authorization'] ? req.headers['authorization'].split(' ')[1] : null;
|
|
46
46
|
if (token && !res.locals.user_id) {
|
|
@@ -70,6 +70,9 @@ const validateService = (schema, { organ_id = true, created_by = true, web_id =
|
|
|
70
70
|
if (web_id && res.locals.web_id) {
|
|
71
71
|
req.body['web_id'] = res.locals.web_id;
|
|
72
72
|
}
|
|
73
|
+
if (field_omit && field_omit.length) {
|
|
74
|
+
req.body = _.omit(req.body, field_omit);
|
|
75
|
+
}
|
|
73
76
|
try {
|
|
74
77
|
req.body = yield (0, exports.validate)(schema, req.body);
|
|
75
78
|
}
|
|
@@ -228,6 +231,11 @@ const exportService = ({ file_type = undefined, export_type = [], limit = 200, s
|
|
|
228
231
|
if (req.query.export_type) {
|
|
229
232
|
res.locals.option['export_type'] = req.query.export_type;
|
|
230
233
|
}
|
|
234
|
+
let option = Object.keys(schema || {});
|
|
235
|
+
if (option.length) {
|
|
236
|
+
let value = _.pick(req.query, option);
|
|
237
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), value);
|
|
238
|
+
}
|
|
231
239
|
return (0, exports.paramService)(Joi.object().keys(Object.assign({ all_data: Joi.number().allow(null, ''), export_type: Joi.string().valid(...export_type), limit: Joi.number().max(limit) }, schema)).unknown())(req, res, next);
|
|
232
240
|
});
|
|
233
241
|
exports.exportService = exportService;
|
|
@@ -244,6 +252,11 @@ const printService = ({ print_type = [], schema = {} } = {}) => (req, res, next)
|
|
|
244
252
|
if (req.query.preset) {
|
|
245
253
|
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { preset: req.query.preset });
|
|
246
254
|
}
|
|
255
|
+
let option = Object.keys(schema || {});
|
|
256
|
+
if (option.length) {
|
|
257
|
+
let value = _.pick(req.query, option);
|
|
258
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), value);
|
|
259
|
+
}
|
|
247
260
|
return (0, exports.paramService)(Joi.object().keys(Object.assign({ ids: Joi.string().required(), print_type: Joi.string().valid(...print_type), preset: Joi.string() }, schema)).unknown())(req, res, next);
|
|
248
261
|
});
|
|
249
262
|
exports.printService = printService;
|
|
@@ -251,6 +264,11 @@ const dataService = ({ schema = {} } = {}) => (req, res, next) => tslib_1.__awai
|
|
|
251
264
|
if (req.query.ids) {
|
|
252
265
|
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { ids: String(req.query.ids).split(',') });
|
|
253
266
|
}
|
|
267
|
+
let option = Object.keys(schema || {});
|
|
268
|
+
if (option.length) {
|
|
269
|
+
let value = _.pick(req.query, option);
|
|
270
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), value);
|
|
271
|
+
}
|
|
254
272
|
return (0, exports.paramService)(Joi.object().keys(Object.assign({ ids: Joi.string().required(), preset: Joi.string() }, schema)).unknown())(req, res, next);
|
|
255
273
|
});
|
|
256
274
|
exports.dataService = dataService;
|
|
@@ -261,6 +279,11 @@ const fieldService = ({ field = [], schema = {} } = {}) => (req, res, next) => t
|
|
|
261
279
|
if (req.query.field) {
|
|
262
280
|
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { field: req.query.field });
|
|
263
281
|
}
|
|
282
|
+
let option = Object.keys(schema || {});
|
|
283
|
+
if (option.length) {
|
|
284
|
+
let value = _.pick(req.query, option);
|
|
285
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), value);
|
|
286
|
+
}
|
|
264
287
|
return (0, exports.paramService)(Joi.object().keys(Object.assign({ field: Joi.string().valid(...field) }, schema)).unknown())(req, res, next);
|
|
265
288
|
});
|
|
266
289
|
exports.fieldService = fieldService;
|