@digione/node-custom-api 0.1.8-beta1 → 0.1.9-alpha6
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/models/system/file.d.ts +1 -0
- package/models/system/file.js +1 -0
- package/package.json +1 -1
- package/utils/file.d.ts +8 -5
- package/utils/file.js +29 -24
- package/utils/helper.d.ts +4 -2
- package/utils/helper.js +16 -3
- package/utils/stream.d.ts +25 -5
- package/utils/stream.js +95 -16
- package/utils/user.js +8 -1
- package/utils/validator.d.ts +8 -0
- package/utils/validator.js +15 -1
package/models/system/file.d.ts
CHANGED
|
@@ -90,6 +90,7 @@ export declare const FileAttr: {
|
|
|
90
90
|
upload: sequelize.TinyIntegerDataType;
|
|
91
91
|
custom: sequelize.AbstractDataTypeConstructor;
|
|
92
92
|
tags: sequelize.AbstractDataTypeConstructor;
|
|
93
|
+
group: sequelize.StringDataType;
|
|
93
94
|
file_link: sequelize.EnumDataType<"no" | "yes">;
|
|
94
95
|
file_id: sequelize.StringDataType;
|
|
95
96
|
uid: sequelize.StringDataType;
|
package/models/system/file.js
CHANGED
|
@@ -95,6 +95,7 @@ exports.FileAttr = {
|
|
|
95
95
|
upload: sequelize.TINYINT({ length: 1 }),
|
|
96
96
|
custom: sequelize.JSON,
|
|
97
97
|
tags: sequelize.JSON,
|
|
98
|
+
group: sequelize.STRING({ length: 20 }),
|
|
98
99
|
file_link: sequelize.ENUM('no', 'yes'),
|
|
99
100
|
file_id: sequelize.STRING({ length: 15 }),
|
|
100
101
|
uid: sequelize.STRING({ length: 100 })
|
package/package.json
CHANGED
package/utils/file.d.ts
CHANGED
|
@@ -124,11 +124,12 @@ export declare class FileUtil {
|
|
|
124
124
|
tags?: TagFile;
|
|
125
125
|
group?: any;
|
|
126
126
|
}): Promise<any>;
|
|
127
|
-
uploadByReq(req: Request, slug: string, user_id: any, { parent_id, parent_slug, name, root, thumb, width, height, input, is_hidden, tags, group }?: {
|
|
127
|
+
uploadByReq(req: Request, slug: string, user_id: any, { parent_id, parent_slug, name, root, format, thumb, width, height, input, is_hidden, tags, group }?: {
|
|
128
128
|
parent_id?: number;
|
|
129
129
|
parent_slug?: string;
|
|
130
130
|
name?: any;
|
|
131
131
|
root?: boolean;
|
|
132
|
+
format?: boolean;
|
|
132
133
|
thumb?: boolean;
|
|
133
134
|
width?: number;
|
|
134
135
|
height?: number;
|
|
@@ -146,7 +147,7 @@ export declare class FileUtil {
|
|
|
146
147
|
hidden?: number;
|
|
147
148
|
input?: {};
|
|
148
149
|
}): Promise<any>;
|
|
149
|
-
createFileByPath(files: Array<
|
|
150
|
+
createFileByPath(files: Array<any>, slug: string, user_id: any, { parent_slug, type, name, root, upload, tags, group }?: {
|
|
150
151
|
parent_slug?: string;
|
|
151
152
|
type?: string;
|
|
152
153
|
name?: any;
|
|
@@ -156,7 +157,8 @@ export declare class FileUtil {
|
|
|
156
157
|
group?: any;
|
|
157
158
|
}): Promise<any>;
|
|
158
159
|
allowedFileType(extension: any): Promise<any>;
|
|
159
|
-
formatFile(folder_id: any, user_id: any, reqs: Array<any>, files: Array<any>, { use_id, field, formatDateTime, input, is_hidden, tags, group }?: {
|
|
160
|
+
formatFile(folder_id: any, user_id: any, reqs: Array<any>, files: Array<any>, { format, use_id, field, formatDateTime, input, is_hidden, tags, group }?: {
|
|
161
|
+
format?: boolean;
|
|
160
162
|
use_id?: boolean;
|
|
161
163
|
field?: any[];
|
|
162
164
|
formatDateTime?: string;
|
|
@@ -179,10 +181,11 @@ export declare class FileUtil {
|
|
|
179
181
|
extension: string;
|
|
180
182
|
type: any;
|
|
181
183
|
is_hidden: any;
|
|
182
|
-
tags:
|
|
184
|
+
tags: any;
|
|
183
185
|
group: any;
|
|
184
186
|
}[]>;
|
|
185
|
-
insertFileUnique(results: Array<any>, { thumb, width, height }?: {
|
|
187
|
+
insertFileUnique(results: Array<any>, { format, thumb, width, height }?: {
|
|
188
|
+
format?: boolean;
|
|
186
189
|
thumb?: boolean;
|
|
187
190
|
width?: number;
|
|
188
191
|
height?: number;
|
package/utils/file.js
CHANGED
|
@@ -392,7 +392,7 @@ class FileUtil {
|
|
|
392
392
|
return (yield this.findAllFile({ where: Object.assign({ id }, where), full, file_link, parent_folder, limit: 1, tags, group }))[0] || null;
|
|
393
393
|
});
|
|
394
394
|
}
|
|
395
|
-
uploadByReq(req, slug, user_id, { parent_id = 0, parent_slug = "", name = undefined, root = false, thumb = false, width = 0, height = 0, input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
|
|
395
|
+
uploadByReq(req, slug, user_id, { parent_id = 0, parent_slug = "", name = undefined, root = false, format = false, thumb = false, width = 0, height = 0, input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
|
|
396
396
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
397
397
|
req.files = req.file ? [req.file] : (req.files || []);
|
|
398
398
|
if (req.files.length && slug) {
|
|
@@ -419,7 +419,7 @@ class FileUtil {
|
|
|
419
419
|
}
|
|
420
420
|
let results = yield this.upload(files);
|
|
421
421
|
results = yield this.formatFile(folder['id'], user_id, reqs, results, { input, is_hidden, tags, group });
|
|
422
|
-
return yield this.insertFileUnique(results, { thumb, width, height });
|
|
422
|
+
return yield this.insertFileUnique(results, { format, thumb, width, height });
|
|
423
423
|
}
|
|
424
424
|
return Promise.reject(errors_1.generalError.BAD_REQUEST);
|
|
425
425
|
});
|
|
@@ -470,8 +470,13 @@ class FileUtil {
|
|
|
470
470
|
let folder = yield this.createFolder(slug, { parent_id, root, name });
|
|
471
471
|
let results = [], reqs = [];
|
|
472
472
|
files.forEach((item) => {
|
|
473
|
-
|
|
474
|
-
|
|
473
|
+
let addition = {}, path = item;
|
|
474
|
+
if (typeof item == "object") {
|
|
475
|
+
addition = item;
|
|
476
|
+
path = item['path'];
|
|
477
|
+
}
|
|
478
|
+
results.push({ Location: path, Key: path });
|
|
479
|
+
reqs.push(Object.assign({ originalname: (0, helper_1.getSlug)(32), mimetype: null, size: 0, type }, addition));
|
|
475
480
|
});
|
|
476
481
|
results = yield this.formatFile(folder['id'], user_id, reqs, results, { input, tags, group });
|
|
477
482
|
return yield this.insertFileUnique(results);
|
|
@@ -557,7 +562,7 @@ class FileUtil {
|
|
|
557
562
|
return type;
|
|
558
563
|
});
|
|
559
564
|
}
|
|
560
|
-
formatFile(folder_id, user_id, reqs, files, { use_id = true, field = [], formatDateTime = "X", input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
|
|
565
|
+
formatFile(folder_id, user_id, reqs, files, { format = false, use_id = true, field = [], formatDateTime = "X", input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
|
|
561
566
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
562
567
|
try {
|
|
563
568
|
let result = yield Promise.all(files.map((file, key) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -574,30 +579,31 @@ class FileUtil {
|
|
|
574
579
|
path = (index < 0) ? protocol + path : path;
|
|
575
580
|
}
|
|
576
581
|
let extension = mime.extension(reqs[key].mimetype);
|
|
577
|
-
let
|
|
582
|
+
let item = Object.assign(Object.assign({}, input), { folder_id,
|
|
578
583
|
user_id,
|
|
579
584
|
organ_id,
|
|
580
585
|
organ_by,
|
|
581
586
|
sort,
|
|
582
|
-
date_added, name: reqs[key].originalname || (0, helper_1.getSlug)(32), filename: reqs[key].Key || file.Key || input['filename'], path, mimetype: reqs[key].mimetype, filesize: reqs[key].size, extension: (extension ? "." + extension : ''), type: reqs[key].type || file.type || input['type'], is_hidden,
|
|
583
|
-
|
|
584
|
-
|
|
587
|
+
date_added, name: reqs[key].originalname || (0, helper_1.getSlug)(32), filename: reqs[key].Key || file.Key || input['filename'], path, mimetype: reqs[key].mimetype, filesize: reqs[key].size, extension: (extension ? "." + extension : ''), type: reqs[key].type || file.type || input['type'], is_hidden, tags: reqs[key].tags || tags, group });
|
|
588
|
+
if (format) {
|
|
589
|
+
item = yield this.afterQueryFile(item);
|
|
590
|
+
}
|
|
585
591
|
if (use_id) {
|
|
586
|
-
|
|
592
|
+
item['id'] = id;
|
|
587
593
|
}
|
|
588
594
|
if (reqs[key].mimetype && reqs[key].mimetype.split('/')[0] == "image") {
|
|
589
595
|
try {
|
|
590
596
|
let body = reqs[key].Body || reqs[key].buffer;
|
|
591
597
|
let image = yield jimp.read(body);
|
|
592
|
-
|
|
593
|
-
|
|
598
|
+
item['height'] = image.bitmap.height;
|
|
599
|
+
item['width'] = image.bitmap.width;
|
|
594
600
|
}
|
|
595
601
|
catch (err) { }
|
|
596
602
|
}
|
|
597
603
|
if (field.length) {
|
|
598
|
-
|
|
604
|
+
item = _.pick(item, field);
|
|
599
605
|
}
|
|
600
|
-
return
|
|
606
|
+
return item;
|
|
601
607
|
})));
|
|
602
608
|
return result;
|
|
603
609
|
}
|
|
@@ -606,7 +612,7 @@ class FileUtil {
|
|
|
606
612
|
}
|
|
607
613
|
});
|
|
608
614
|
}
|
|
609
|
-
insertFileUnique(results, { thumb = false, width = 0, height = 0 } = {}) {
|
|
615
|
+
insertFileUnique(results, { format = false, thumb = false, width = 0, height = 0 } = {}) {
|
|
610
616
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
611
617
|
try {
|
|
612
618
|
let data = yield file_1.FileModel.schema(this.ref, "_").bulkCreate(results);
|
|
@@ -614,15 +620,14 @@ class FileUtil {
|
|
|
614
620
|
return Promise.reject(errors_1.generalError.BAD_REQUEST);
|
|
615
621
|
}
|
|
616
622
|
let result = data.map(item => item.toJSON());
|
|
617
|
-
if (thumb) {
|
|
618
|
-
// create thumb
|
|
623
|
+
if (format || thumb) {
|
|
624
|
+
// format or create thumb
|
|
619
625
|
result = yield Promise.all(result.map((item) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
return Object.assign(Object.assign({}, item), { thumb });
|
|
626
|
+
let include = (yield this.afterQueryFile(item)) || {};
|
|
627
|
+
if (thumb && item['type'] == 'i') {
|
|
628
|
+
include['thumb'] = yield this.findImageThumb(item, { width, height });
|
|
624
629
|
}
|
|
625
|
-
return item;
|
|
630
|
+
return Object.assign(Object.assign({}, item), include);
|
|
626
631
|
})));
|
|
627
632
|
}
|
|
628
633
|
return result;
|
|
@@ -630,7 +635,7 @@ class FileUtil {
|
|
|
630
635
|
catch (err) {
|
|
631
636
|
if (err.errors && err.errors[0].validatorKey == "not_unique") {
|
|
632
637
|
results = results.map(item => (Object.assign(Object.assign({}, item), { id: (0, uuid_1.v4)().replace(/-/gi, '').substring(0, 15) })));
|
|
633
|
-
return yield this.insertFileUnique(results, { thumb, width, height });
|
|
638
|
+
return yield this.insertFileUnique(results, { format, thumb, width, height });
|
|
634
639
|
}
|
|
635
640
|
return Promise.reject(errors_1.generalError.BAD_REQUEST);
|
|
636
641
|
}
|
|
@@ -639,7 +644,7 @@ class FileUtil {
|
|
|
639
644
|
uploadRawFormat(files, { field = ['name', 'filename', 'path', 'mimetype', 'filesize', 'extension', 'type', 'height', 'width'] } = {}) {
|
|
640
645
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
641
646
|
let query = yield this.uploadRaw(files);
|
|
642
|
-
return yield this.formatFile(0, 0, files, query, { field });
|
|
647
|
+
return yield this.formatFile(0, 0, files, query, { format: true, field });
|
|
643
648
|
});
|
|
644
649
|
}
|
|
645
650
|
updateFile(id, input = {}, { paths = [] } = {}) {
|
package/utils/helper.d.ts
CHANGED
|
@@ -18,8 +18,9 @@ export declare const getTimestampMysql: (date?: any) => number;
|
|
|
18
18
|
export declare const getDateTime: (time?: any, { utc }?: {
|
|
19
19
|
utc?: boolean;
|
|
20
20
|
}) => moment.Moment;
|
|
21
|
-
export declare const getValueFunctionFile: (key: any) => (value: any, { result, fileUtil }?: {
|
|
21
|
+
export declare const getValueFunctionFile: (key: any) => (value: any, { result, json, fileUtil }?: {
|
|
22
22
|
result?: {};
|
|
23
|
+
json?: {};
|
|
23
24
|
fileUtil?: any;
|
|
24
25
|
}) => Promise<void>;
|
|
25
26
|
export declare const getValueFunctionLang: (key: any) => (value?: {}, { result, transform, spread, spread_all, raw, lang_code }?: {
|
|
@@ -63,7 +64,7 @@ export declare const randomRef: ({ length_digital, length_alphabet }?: {
|
|
|
63
64
|
length_alphabet?: number;
|
|
64
65
|
}) => string;
|
|
65
66
|
export declare const treeToArray: (items: Array<any>, array?: Array<any>, level?: number) => Promise<any[]>;
|
|
66
|
-
export declare const buildTree: (nodes: Array<any>, { index, field_children, json_convert, key_index, key_parent, root, to_array }?: {
|
|
67
|
+
export declare const buildTree: (nodes: Array<any>, { index, field_children, json_convert, key_index, key_parent, root, to_array, notfound_parent }?: {
|
|
67
68
|
index?: any;
|
|
68
69
|
field_children?: string;
|
|
69
70
|
json_convert?: boolean;
|
|
@@ -71,6 +72,7 @@ export declare const buildTree: (nodes: Array<any>, { index, field_children, jso
|
|
|
71
72
|
key_parent?: string;
|
|
72
73
|
root?: any;
|
|
73
74
|
to_array?: boolean;
|
|
75
|
+
notfound_parent?: boolean;
|
|
74
76
|
}) => Promise<any[]>;
|
|
75
77
|
export declare const expandTree: (items: Array<any>, { array, parent, level, prefix, field_index, field_children, key_value }?: {
|
|
76
78
|
array?: any[];
|
package/utils/helper.js
CHANGED
|
@@ -79,8 +79,16 @@ const getDateTime = (time = undefined, { utc = true } = {}) => {
|
|
|
79
79
|
};
|
|
80
80
|
exports.getDateTime = getDateTime;
|
|
81
81
|
const getValueFunctionFile = (key) => {
|
|
82
|
-
return (value, { result = {}, fileUtil = undefined } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
-
if (
|
|
82
|
+
return (value, { result = {}, json = {}, fileUtil = undefined } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
if (json[key]) {
|
|
84
|
+
try {
|
|
85
|
+
result[key] = JSON.parse(json[key]);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
result[key] = null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (value[key]) {
|
|
84
92
|
result[key] = yield fileUtil.findOneFileById(value[key]);
|
|
85
93
|
}
|
|
86
94
|
});
|
|
@@ -220,7 +228,7 @@ const treeToArray = (items, array = [], level = 1) => tslib_1.__awaiter(void 0,
|
|
|
220
228
|
return array;
|
|
221
229
|
});
|
|
222
230
|
exports.treeToArray = treeToArray;
|
|
223
|
-
const buildTree = (nodes, { index = undefined, field_children = "children", json_convert = false, key_index = "id", key_parent = "parent", root = undefined, to_array = false } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
231
|
+
const buildTree = (nodes, { index = undefined, field_children = "children", json_convert = false, key_index = "id", key_parent = "parent", root = undefined, to_array = false, notfound_parent = false } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
224
232
|
if (!nodes) {
|
|
225
233
|
return null;
|
|
226
234
|
}
|
|
@@ -258,11 +266,16 @@ const buildTree = (nodes, { index = undefined, field_children = "children", json
|
|
|
258
266
|
}
|
|
259
267
|
}
|
|
260
268
|
parent[field_children] = results;
|
|
269
|
+
delete children[parent[key_index]];
|
|
261
270
|
}
|
|
262
271
|
};
|
|
263
272
|
for (let i = 0, len = roots.length; i < len; ++i) {
|
|
264
273
|
findChildren(roots[i]);
|
|
265
274
|
}
|
|
275
|
+
if (notfound_parent) {
|
|
276
|
+
let items = Object.keys(children).reduce((total, key) => total.concat(children[key]), []);
|
|
277
|
+
roots.unshift({ [key_index]: -1, [field_children]: items });
|
|
278
|
+
}
|
|
266
279
|
if (index)
|
|
267
280
|
roots = roots[0];
|
|
268
281
|
if (roots && to_array) {
|
package/utils/stream.d.ts
CHANGED
|
@@ -5,16 +5,20 @@ import { Request } from 'express';
|
|
|
5
5
|
import * as Joi from 'joi';
|
|
6
6
|
export declare const getValueFunctionRelationship: (key: any, { field_data }?: {
|
|
7
7
|
field_data?: {};
|
|
8
|
-
}) => (value: any, { result, ref, lang_code }?: {
|
|
8
|
+
}) => (value: any, { result, json, ref, raw, lang_code }?: {
|
|
9
9
|
result?: {};
|
|
10
|
+
json?: {};
|
|
10
11
|
ref?: string;
|
|
12
|
+
raw?: boolean;
|
|
11
13
|
lang_code?: string;
|
|
12
14
|
}) => Promise<void>;
|
|
13
15
|
export declare const getValueFunctionMultiple: (key: any, { field_data }?: {
|
|
14
16
|
field_data?: {};
|
|
15
|
-
}) => (value: any, { result, ref, lang_code }?: {
|
|
17
|
+
}) => (value: any, { result, json, ref, raw, lang_code }?: {
|
|
16
18
|
result?: {};
|
|
19
|
+
json?: {};
|
|
17
20
|
ref?: string;
|
|
21
|
+
raw?: boolean;
|
|
18
22
|
lang_code?: string;
|
|
19
23
|
}) => Promise<void>;
|
|
20
24
|
interface Field {
|
|
@@ -36,7 +40,7 @@ export declare class StreamUtil {
|
|
|
36
40
|
private fileUtil;
|
|
37
41
|
private languageUtil;
|
|
38
42
|
constructor(ref?: string, option?: QueryParamOption, fileUtil?: FileUtil);
|
|
39
|
-
findField(slug: string, namespace: string, { index, option, no_lang, field_slug, field_only, field_required, lang, lang_code, is_required, default_value, addition, include, include_only, convert_option, field_option, require, multiple_table, multiple_spread, text, bullets, multiple, relationship, file, image, field_exclude, section }?: {
|
|
43
|
+
findField(slug: string, namespace: string, { index, option, no_lang, field_slug, field_only, field_required, lang, lang_code, is_required, default_value, addition, include, include_only, convert_option, convert_value, field_option, require, multiple_table, multiple_spread, text, bullets, multiple, relationship, file, image, field_exclude, section }?: {
|
|
40
44
|
index?: string;
|
|
41
45
|
option?: {};
|
|
42
46
|
no_lang?: boolean;
|
|
@@ -51,6 +55,7 @@ export declare class StreamUtil {
|
|
|
51
55
|
include?: any;
|
|
52
56
|
include_only?: boolean;
|
|
53
57
|
convert_option?: boolean;
|
|
58
|
+
convert_value?: boolean;
|
|
54
59
|
field_option?: {};
|
|
55
60
|
require?: boolean;
|
|
56
61
|
multiple_table?: boolean;
|
|
@@ -71,14 +76,16 @@ export declare class StreamUtil {
|
|
|
71
76
|
include?: any;
|
|
72
77
|
include_only?: boolean;
|
|
73
78
|
}): any;
|
|
74
|
-
buildStream(slug: string, namespace: string, { query, builder, fetch, attribute, attributes, field_exclude, include }?: {
|
|
79
|
+
buildStream(slug: string, namespace: string, { query, builder, fetch, label, attribute, attributes, field_exclude, include, include_all }?: {
|
|
75
80
|
query?: boolean;
|
|
76
81
|
builder?: boolean;
|
|
77
82
|
fetch?: boolean;
|
|
83
|
+
label?: boolean;
|
|
78
84
|
attribute?: boolean;
|
|
79
85
|
attributes?: any;
|
|
80
86
|
field_exclude?: any[];
|
|
81
87
|
include?: {};
|
|
88
|
+
include_all?: boolean;
|
|
82
89
|
}): Promise<{
|
|
83
90
|
stream: any;
|
|
84
91
|
fields: any;
|
|
@@ -99,7 +106,19 @@ export declare class StreamUtil {
|
|
|
99
106
|
raw?: boolean;
|
|
100
107
|
lang_code?: any;
|
|
101
108
|
}): Promise<{}>;
|
|
102
|
-
|
|
109
|
+
getValueByJson(slug: string, namespace: string, value: any, json: any, { query, lang_code }?: {
|
|
110
|
+
query?: boolean;
|
|
111
|
+
lang_code?: any;
|
|
112
|
+
}): Promise<{}>;
|
|
113
|
+
getStoreJson(slug: string, namespace: string, value: any, { query, lang_code, exclude_type }?: {
|
|
114
|
+
query?: boolean;
|
|
115
|
+
lang_code?: any;
|
|
116
|
+
exclude_type?: {};
|
|
117
|
+
}): Promise<{
|
|
118
|
+
result: {};
|
|
119
|
+
labels: any[];
|
|
120
|
+
}>;
|
|
121
|
+
genField(streams: Array<any>, { index, option, slug, id_stream, prefix, multiple_table, multiple_spread, addition, convert_option, convert_value, field_option, default_value, default_lang, lang_code, no_lang, lang, country, section }?: {
|
|
103
122
|
index?: string;
|
|
104
123
|
option?: {};
|
|
105
124
|
slug?: string;
|
|
@@ -109,6 +128,7 @@ export declare class StreamUtil {
|
|
|
109
128
|
multiple_spread?: boolean;
|
|
110
129
|
addition?: {};
|
|
111
130
|
convert_option?: boolean;
|
|
131
|
+
convert_value?: boolean;
|
|
112
132
|
field_option?: {};
|
|
113
133
|
default_value?: any;
|
|
114
134
|
default_lang?: string;
|
package/utils/stream.js
CHANGED
|
@@ -24,10 +24,22 @@ const i18n_1 = require("i18n");
|
|
|
24
24
|
const _ = require("lodash");
|
|
25
25
|
const Joi = require("joi");
|
|
26
26
|
const getValueFunctionRelationship = (key, { field_data = {} } = {}) => {
|
|
27
|
-
return (value, { result = {}, ref = '', lang_code = '' } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
if (
|
|
27
|
+
return (value, { result = {}, json = {}, ref = '', raw = false, lang_code = '' } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
if (field_data['table']) {
|
|
29
29
|
let title_column = field_data['title_column'] || "title";
|
|
30
|
-
|
|
30
|
+
if (json[key]) {
|
|
31
|
+
try {
|
|
32
|
+
result[key] = JSON.parse(json[key]);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
result[key] = null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else if (value[key]) {
|
|
39
|
+
result[key] = yield (0, db_1.findOne)(ref + '_' + field_data['table'], { where: { id: value[key] }, attributes: ['*'] });
|
|
40
|
+
}
|
|
41
|
+
if (raw)
|
|
42
|
+
return;
|
|
31
43
|
if (result[key]) {
|
|
32
44
|
(0, helper_2.getValueFunctionLang)(title_column)(result[key], { result: result[key], lang_code });
|
|
33
45
|
}
|
|
@@ -36,10 +48,22 @@ const getValueFunctionRelationship = (key, { field_data = {} } = {}) => {
|
|
|
36
48
|
};
|
|
37
49
|
exports.getValueFunctionRelationship = getValueFunctionRelationship;
|
|
38
50
|
const getValueFunctionMultiple = (key, { field_data = {} } = {}) => {
|
|
39
|
-
return (value, { result = {}, ref = '', lang_code = '' } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
if (field_data['
|
|
51
|
+
return (value, { result = {}, json = {}, ref = '', raw = false, lang_code = '' } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
if (field_data['table']) {
|
|
41
53
|
let title_column = field_data['title_column'] || "title";
|
|
42
|
-
|
|
54
|
+
if (json[key]) {
|
|
55
|
+
try {
|
|
56
|
+
result[key] = JSON.parse(json[key]);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
result[key] = [];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if (field_data['association']) {
|
|
63
|
+
result[key] = yield (0, db_1.findAll)(ref + '_' + field_data['table'], { where: { [`m.row_id`]: { [sequelize_1.Op.eq]: value['id'] } }, attributes: [`${ref + '_' + field_data['table']}.*`], association: [`INNER JOIN ${ref}_${field_data['association']} m ON ${ref + '_' + field_data['table']}.id = m.${field_data['table'] + '_id'}`] });
|
|
64
|
+
}
|
|
65
|
+
if (raw)
|
|
66
|
+
return;
|
|
43
67
|
if (result[key] && result[key].length) {
|
|
44
68
|
result[key] = result[key].map(i => (0, helper_2.getValueByLang)(i, { result: i, field: [title_column], lang_code }));
|
|
45
69
|
}
|
|
@@ -77,7 +101,7 @@ class StreamUtil {
|
|
|
77
101
|
this.fileUtil = fileUtil || new file_2.FileUtil(this.ref, this.option);
|
|
78
102
|
this.languageUtil = new language_1.LanguageUtil(this.ref, this.option);
|
|
79
103
|
}
|
|
80
|
-
findField(slug, namespace, { index = "", option = {}, no_lang = false, field_slug = [], field_only = true, field_required = true, lang = [], lang_code = "en", is_required = "", default_value = {}, addition = {}, include = undefined, include_only = false, convert_option = false, field_option = {}, require = false, multiple_table = false, multiple_spread = false, text = false, bullets = false, multiple = false, relationship = false, file = false, image = false, field_exclude = [], section = false } = {}) {
|
|
104
|
+
findField(slug, namespace, { index = "", option = {}, no_lang = false, field_slug = [], field_only = true, field_required = true, lang = [], lang_code = "en", is_required = "", default_value = {}, addition = {}, include = undefined, include_only = false, convert_option = false, convert_value = false, field_option = {}, require = false, multiple_table = false, multiple_spread = false, text = false, bullets = false, multiple = false, relationship = false, file = false, image = false, field_exclude = [], section = false } = {}) {
|
|
81
105
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
82
106
|
let data;
|
|
83
107
|
let where = {};
|
|
@@ -160,7 +184,7 @@ class StreamUtil {
|
|
|
160
184
|
}
|
|
161
185
|
}
|
|
162
186
|
if (convert_option) {
|
|
163
|
-
data['fields'] = yield this.genField(data['fields'], { index, option, slug, id_stream: data['id'], prefix: data['stream_prefix'], multiple_table, multiple_spread, addition, field_option, default_value, lang_code, no_lang, lang, section });
|
|
187
|
+
data['fields'] = yield this.genField(data['fields'], { index, option, slug, id_stream: data['id'], prefix: data['stream_prefix'], multiple_table, multiple_spread, addition, convert_value, field_option, default_value, lang_code, no_lang, lang, section });
|
|
164
188
|
}
|
|
165
189
|
if (field_only) {
|
|
166
190
|
return data['fields'];
|
|
@@ -211,7 +235,7 @@ class StreamUtil {
|
|
|
211
235
|
}
|
|
212
236
|
return data;
|
|
213
237
|
}
|
|
214
|
-
buildStream(slug, namespace, { query = true, builder = true, fetch = false, attribute = false, attributes = null, field_exclude = [], include = {} } = {}) {
|
|
238
|
+
buildStream(slug, namespace, { query = true, builder = true, fetch = false, label = false, attribute = false, attributes = null, field_exclude = [], include = {}, include_all = false } = {}) {
|
|
215
239
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
216
240
|
let build = this.builder[slug + "_" + namespace] || { stream: null, fields: null, fetchFn: [], attributes: null };
|
|
217
241
|
if (!build['fields']) {
|
|
@@ -222,7 +246,7 @@ class StreamUtil {
|
|
|
222
246
|
build['stream'] = _.omit(data, ['fields']);
|
|
223
247
|
}
|
|
224
248
|
if ((fetch || attribute) && build['fields'].length) {
|
|
225
|
-
let fetchFn = [];
|
|
249
|
+
let fetchFn = [], fetchLabel = [];
|
|
226
250
|
attributes = attributes || {};
|
|
227
251
|
for (let field of build['fields']) {
|
|
228
252
|
let field_data = field['field_data'] || {};
|
|
@@ -232,24 +256,30 @@ class StreamUtil {
|
|
|
232
256
|
}
|
|
233
257
|
if (fetch) {
|
|
234
258
|
if (field['is_lang'] == "yes") {
|
|
259
|
+
label && fetchLabel.push(field);
|
|
235
260
|
fetchFn.push((0, helper_2.getValueFunctionLang)(field['field_slug']));
|
|
236
261
|
}
|
|
237
262
|
else {
|
|
238
263
|
switch (field['field_type']) {
|
|
239
264
|
case "file":
|
|
240
265
|
case "image":
|
|
241
|
-
include[field['field_slug']]
|
|
266
|
+
if (include[field['field_slug']] || include_all) {
|
|
267
|
+
label && fetchLabel.push(field);
|
|
268
|
+
fetchFn.push((0, helper_2.getValueFunctionFile)(field['field_slug']));
|
|
269
|
+
}
|
|
242
270
|
break;
|
|
243
271
|
case "relationship":
|
|
244
272
|
case "multiple":
|
|
245
|
-
if (include[field['field_slug']] && field_data['choose_stream']) {
|
|
273
|
+
if ((include[field['field_slug']] || include_all) && field_data['choose_stream']) {
|
|
246
274
|
let stream = yield stream_1.StreamModel.schema(this.ref, "_").findOne({ where: { id: field_data['choose_stream'] }, raw: true, attributes: ['stream_slug', 'stream_prefix', 'title_column'] });
|
|
247
275
|
if (stream['stream_slug']) {
|
|
248
276
|
field_data['table'] = stream['stream_prefix'] ? stream['stream_prefix'] + stream['stream_slug'] : stream['stream_slug'];
|
|
249
277
|
if (field['field_type'] == "relationship") {
|
|
278
|
+
label && fetchLabel.push(field);
|
|
250
279
|
fetchFn.push((0, exports.getValueFunctionRelationship)(field['field_slug'], { field_data }));
|
|
251
280
|
}
|
|
252
281
|
else if (field['field_type'] == "multiple") {
|
|
282
|
+
label && fetchLabel.push(field);
|
|
253
283
|
field_data['association'] = (build['stream']['stream_prefix'] ? build['stream']['stream_prefix'] + build['stream']['stream_slug'] : build['stream']['stream_slug']) + "_" + field_data['table'];
|
|
254
284
|
fetchFn.push((0, exports.getValueFunctionMultiple)(field['field_slug'], { field_data }));
|
|
255
285
|
}
|
|
@@ -259,11 +289,12 @@ class StreamUtil {
|
|
|
259
289
|
}
|
|
260
290
|
}
|
|
261
291
|
}
|
|
262
|
-
if (field['field_type'] == "multiple" || field['field_type'] == "any") {
|
|
292
|
+
if ((field['field_type'] == "multiple" && field_data['self_table'] != "yes") || field['field_type'] == "any") {
|
|
263
293
|
delete attributes[field['field_slug']];
|
|
264
294
|
}
|
|
265
295
|
}
|
|
266
296
|
build['fetchFn'] = fetchFn;
|
|
297
|
+
build['fetchLabel'] = fetchLabel;
|
|
267
298
|
}
|
|
268
299
|
if (attributes)
|
|
269
300
|
build['attributes'] = attributes;
|
|
@@ -289,7 +320,34 @@ class StreamUtil {
|
|
|
289
320
|
return result;
|
|
290
321
|
});
|
|
291
322
|
}
|
|
292
|
-
|
|
323
|
+
getValueByJson(slug, namespace, value, json, { query = false, lang_code = undefined } = {}) {
|
|
324
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
325
|
+
let result = {};
|
|
326
|
+
let fetchFn = yield this.getBuilder(slug, namespace, { query, index: "fetchFn" });
|
|
327
|
+
lang_code = lang_code || this.option.lang_code;
|
|
328
|
+
for (let f of fetchFn || []) {
|
|
329
|
+
yield f(value, { result, json, ref: this.ref, lang_code, fileUtil: this.fileUtil });
|
|
330
|
+
}
|
|
331
|
+
return result;
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
getStoreJson(slug, namespace, value, { query = false, lang_code = undefined, exclude_type = {} } = {}) {
|
|
335
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
336
|
+
let result = {}, labels = [];
|
|
337
|
+
let fetchLabel = yield this.getBuilder(slug, namespace, { query, index: "fetchLabel" });
|
|
338
|
+
lang_code = lang_code || this.option.lang_code;
|
|
339
|
+
for (let f of fetchLabel || []) {
|
|
340
|
+
let field_slug = f['field_slug'];
|
|
341
|
+
let field_type = f['field_type'];
|
|
342
|
+
if (field_slug && !exclude_type[field_type] && typeof value[field_slug] != "undefined") {
|
|
343
|
+
labels.push(field_slug);
|
|
344
|
+
result[field_slug] = JSON.stringify(value[field_slug]);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return { result, labels };
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
genField(streams, { index = "", option = {}, slug = "", id_stream = "", prefix = "", multiple_table = false, multiple_spread = false, addition = {}, convert_option = true, convert_value = false, field_option = {}, default_value = {}, default_lang = "en", lang_code = "en", no_lang = false, lang = [], country = undefined, section = false } = {}) {
|
|
293
351
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
294
352
|
let fields = [], sections = [];
|
|
295
353
|
let exclude = option['excludeObj'] || {};
|
|
@@ -414,6 +472,7 @@ class StreamUtil {
|
|
|
414
472
|
continue;
|
|
415
473
|
}
|
|
416
474
|
if (convert_option) {
|
|
475
|
+
let obj_value = {};
|
|
417
476
|
if (item['field_type'] == "choice") {
|
|
418
477
|
if (field_data['choice_data']) {
|
|
419
478
|
let data = [];
|
|
@@ -443,6 +502,9 @@ class StreamUtil {
|
|
|
443
502
|
else {
|
|
444
503
|
data[k] = { key: v, value: v };
|
|
445
504
|
}
|
|
505
|
+
if (convert_value && data[k]) {
|
|
506
|
+
obj_value[data[k]['key']] = data[k]['value'];
|
|
507
|
+
}
|
|
446
508
|
});
|
|
447
509
|
item['data'] = data;
|
|
448
510
|
}
|
|
@@ -452,9 +514,18 @@ class StreamUtil {
|
|
|
452
514
|
if (value && value.indexOf('lang:') > -1) {
|
|
453
515
|
item['value'] = (0, i18n_1.__)({ phrase: value, locale: lang_code });
|
|
454
516
|
}
|
|
517
|
+
if (convert_value && item['key']) {
|
|
518
|
+
obj_value[item['key']] = item['value'];
|
|
519
|
+
}
|
|
455
520
|
return item;
|
|
456
521
|
});
|
|
457
522
|
}
|
|
523
|
+
if (convert_value && typeof item['field_value'] != "undefined") {
|
|
524
|
+
let field_value = item['field_value'];
|
|
525
|
+
if (item['field_value'] == null)
|
|
526
|
+
field_value = '';
|
|
527
|
+
field_data['value'] = obj_value[field_value];
|
|
528
|
+
}
|
|
458
529
|
}
|
|
459
530
|
else if (!field_option[item['field_slug']] && (item['field_type'] == "relationship" || item['field_type'] == "multiple") && field_data['choose_stream']) {
|
|
460
531
|
try {
|
|
@@ -499,6 +570,9 @@ class StreamUtil {
|
|
|
499
570
|
item['title'] = item['title'] ? item['title'] : item[stream['title_column']];
|
|
500
571
|
(0, helper_2.getValueFunctionLang)('title')(item, { result: item, lang_code });
|
|
501
572
|
let value = item['title'] ? item['title'] : item['id'];
|
|
573
|
+
if (convert_value && item['id']) {
|
|
574
|
+
obj_value[item['id']] = value;
|
|
575
|
+
}
|
|
502
576
|
return {
|
|
503
577
|
key: item['id'],
|
|
504
578
|
value
|
|
@@ -509,6 +583,9 @@ class StreamUtil {
|
|
|
509
583
|
}
|
|
510
584
|
}
|
|
511
585
|
item['data'] = data;
|
|
586
|
+
if (convert_value && item['field_value']) {
|
|
587
|
+
field_data['value'] = obj_value[item['field_value']];
|
|
588
|
+
}
|
|
512
589
|
}
|
|
513
590
|
catch (err) { }
|
|
514
591
|
}
|
|
@@ -1578,8 +1655,10 @@ class StreamUtil {
|
|
|
1578
1655
|
}
|
|
1579
1656
|
}
|
|
1580
1657
|
}
|
|
1581
|
-
|
|
1582
|
-
|
|
1658
|
+
if (typeof field['sort_order'] == "undefined") {
|
|
1659
|
+
let sort_order = yield field_1.FieldModel.schema(this.ref, "_").max('sort_order', { where: { stream_id: stream['id'] } });
|
|
1660
|
+
field['sort_order'] = sort_order ? Number(sort_order + 1) : 1;
|
|
1661
|
+
}
|
|
1583
1662
|
if (!field['stream_id']) {
|
|
1584
1663
|
field['stream_id'] = stream['id'];
|
|
1585
1664
|
}
|
package/utils/user.js
CHANGED
|
@@ -277,7 +277,14 @@ const getAddressIndex = (data, { condition = {}, lang_code = "en" } = {}) => tsl
|
|
|
277
277
|
exports.getAddressIndex = getAddressIndex;
|
|
278
278
|
const getCountry = (ref, { organ_id = "", lang_code = "en", setting = {} } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
279
279
|
let where = { status: 1, lang_code }, default_country;
|
|
280
|
-
if (
|
|
280
|
+
if (organ_id) {
|
|
281
|
+
let query = yield organ_1.UserOrganModel.schema(ref, "_").findOne({ where: { id: organ_id }, attributes: ['setting'], raw: true });
|
|
282
|
+
setting = query ? (query['setting'] || {}) : {};
|
|
283
|
+
}
|
|
284
|
+
if (setting['mobile_code']) {
|
|
285
|
+
where['mobilecode'] = setting['mobile_code'].split(",");
|
|
286
|
+
}
|
|
287
|
+
else if (setting['country_id']) {
|
|
281
288
|
where['id'] = setting['country_id'].split(",");
|
|
282
289
|
}
|
|
283
290
|
let data = yield country_1.CountryModel.schema("core", "_").findAll({
|
package/utils/validator.d.ts
CHANGED
|
@@ -57,5 +57,13 @@ export declare const convertService: ({ convert_type, schema }?: {
|
|
|
57
57
|
convert_type?: any[];
|
|
58
58
|
schema?: {};
|
|
59
59
|
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
60
|
+
export declare const entryValidateService: ({ module, schema }?: {
|
|
61
|
+
module?: string[];
|
|
62
|
+
schema?: {};
|
|
63
|
+
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
64
|
+
export declare const entryParamService: ({ module, schema }?: {
|
|
65
|
+
module?: string[];
|
|
66
|
+
schema?: {};
|
|
67
|
+
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
60
68
|
export declare const createdByValidate: (req: any, res: any, next: any) => Promise<any>;
|
|
61
69
|
export {};
|
package/utils/validator.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createdByValidate = exports.convertService = exports.fieldService = exports.dataService = exports.printService = exports.exportService = exports.importService = exports.streamService = exports.multiService = exports.fileService = exports.paramService = exports.validateService = exports.validate = void 0;
|
|
3
|
+
exports.createdByValidate = exports.entryParamService = exports.entryValidateService = exports.convertService = exports.fieldService = exports.dataService = exports.printService = exports.exportService = exports.importService = exports.streamService = exports.multiService = exports.fileService = exports.paramService = exports.validateService = exports.validate = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const Joi = require("joi");
|
|
6
6
|
const errors_1 = require("../errors");
|
|
@@ -291,6 +291,20 @@ const convertService = ({ convert_type = [], schema = {} } = {}) => (req, res, n
|
|
|
291
291
|
return (0, exports.validateService)(Joi.object().keys(Object.assign({ ids: Joi.array().items(Joi.number()).min(1), convert_type: Joi.string().valid(...convert_type) }, schema)).unknown())(req, res, next);
|
|
292
292
|
});
|
|
293
293
|
exports.convertService = convertService;
|
|
294
|
+
const entryValidateService = ({ module = ['contact'], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
295
|
+
return (0, exports.validateService)(Joi.object().keys(Object.assign({ module: Joi.string().valid(...module), entry_id: Joi.number().required() }, schema)).unknown())(req, res, next);
|
|
296
|
+
});
|
|
297
|
+
exports.entryValidateService = entryValidateService;
|
|
298
|
+
const entryParamService = ({ module = ['contact'], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
299
|
+
if (req.query.module) {
|
|
300
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { module: req.query.module });
|
|
301
|
+
}
|
|
302
|
+
if (req.query.entry_id) {
|
|
303
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { entry_id: req.query.entry_id });
|
|
304
|
+
}
|
|
305
|
+
return (0, exports.paramService)(Joi.object().keys(Object.assign({ module: Joi.string().valid(...module), entry_id: Joi.number().required() }, schema)).unknown())(req, res, next);
|
|
306
|
+
});
|
|
307
|
+
exports.entryParamService = entryParamService;
|
|
294
308
|
exports.createdByValidate = (0, exports.validateService)(Joi.object().keys({
|
|
295
309
|
created_by: Joi.alternatives().try(Joi.string(), Joi.number()).required()
|
|
296
310
|
}).unknown());
|