@digione/node-custom-api 0.1.9 → 0.2.0-alpha2
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/middlewares/paramQuery.d.ts +3 -0
- package/middlewares/paramQuery.js +13 -2
- package/models/system/file.d.ts +1 -0
- package/models/system/file.js +1 -0
- package/models/user/user.d.ts +0 -3
- package/models/user/user.js +0 -4
- package/package.json +1 -1
- package/utils/auth.d.ts +3 -1
- package/utils/auth.js +8 -3
- package/utils/db.js +4 -4
- package/utils/file.d.ts +22 -10
- package/utils/file.js +65 -45
- package/utils/helper.d.ts +10 -1
- package/utils/helper.js +31 -4
- package/utils/metadata.js +2 -2
- package/utils/stream.d.ts +12 -2
- package/utils/stream.js +44 -7
- package/utils/user.d.ts +2 -2
- package/utils/user.js +20 -11
- package/utils/validator.d.ts +8 -0
- package/utils/validator.js +23 -7
|
@@ -14,3 +14,6 @@ export declare const changeBodyParam: (value?: {}, { skipSystem, omit }?: {
|
|
|
14
14
|
skipSystem?: boolean;
|
|
15
15
|
omit?: any[];
|
|
16
16
|
}) => (req: Request, res: Response, next: any) => any;
|
|
17
|
+
export declare const changeConfigParam: (value?: {}, { skipSystem }?: {
|
|
18
|
+
skipSystem?: boolean;
|
|
19
|
+
}) => (req: Request, res: Response, next: any) => any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.changeBodyParam = exports.changeOptionParam = exports.changeQueryParam = exports.getQueryParamFile = exports.getQueryParamCUD = exports.getQueryParam = exports.getStremParam = exports.getAuthParam = void 0;
|
|
3
|
+
exports.changeConfigParam = exports.changeBodyParam = exports.changeOptionParam = exports.changeQueryParam = exports.getQueryParamFile = exports.getQueryParamCUD = exports.getQueryParam = exports.getStremParam = exports.getAuthParam = void 0;
|
|
4
4
|
const helper_1 = require("../utils/helper");
|
|
5
5
|
const _ = require("lodash");
|
|
6
6
|
const getAuthParam = (req, res, next) => {
|
|
@@ -127,6 +127,7 @@ const getQueryParam = (req, res, next) => {
|
|
|
127
127
|
};
|
|
128
128
|
exports.getQueryParam = getQueryParam;
|
|
129
129
|
const getQueryParamCUD = (req, res, next) => {
|
|
130
|
+
let config = res.locals.config || {};
|
|
130
131
|
res.locals.option = res.locals.option || {};
|
|
131
132
|
if (req.query.include) {
|
|
132
133
|
try {
|
|
@@ -144,7 +145,7 @@ const getQueryParamCUD = (req, res, next) => {
|
|
|
144
145
|
res.locals.option['records'] = String(req.query.records).split(',');
|
|
145
146
|
}
|
|
146
147
|
if (req.query.ids) {
|
|
147
|
-
res.locals.option['ids'] = String(req.query.ids).split(',').slice(0, 25);
|
|
148
|
+
res.locals.option['ids'] = String(req.query.ids).split(',').slice(0, (config['maxQueryIds'] || 25));
|
|
148
149
|
}
|
|
149
150
|
return (0, exports.getAuthParam)(req, res, () => {
|
|
150
151
|
if (req.query.lang_code) {
|
|
@@ -218,3 +219,13 @@ const changeBodyParam = (value = {}, { skipSystem = false, omit = [] } = {}) =>
|
|
|
218
219
|
return next();
|
|
219
220
|
};
|
|
220
221
|
exports.changeBodyParam = changeBodyParam;
|
|
222
|
+
const changeConfigParam = (value = {}, { skipSystem = false } = {}) => (req, res, next) => {
|
|
223
|
+
if (skipSystem && req.params.web_system_token) {
|
|
224
|
+
let bol = (typeof req.params.web != "undefined") || (req.params.web_system == req.params.web);
|
|
225
|
+
if (bol)
|
|
226
|
+
return next();
|
|
227
|
+
}
|
|
228
|
+
res.locals.config = Object.assign(Object.assign({}, res.locals.config || {}), value);
|
|
229
|
+
return next();
|
|
230
|
+
};
|
|
231
|
+
exports.changeConfigParam = changeConfigParam;
|
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/models/user/user.d.ts
CHANGED
|
@@ -50,9 +50,6 @@ export declare const UserAttr: {
|
|
|
50
50
|
organ_id: {
|
|
51
51
|
type: sequelize.IntegerDataType;
|
|
52
52
|
};
|
|
53
|
-
member_id: {
|
|
54
|
-
type: sequelize.StringDataType;
|
|
55
|
-
};
|
|
56
53
|
provider: sequelize.StringDataType;
|
|
57
54
|
mobile: sequelize.StringDataType;
|
|
58
55
|
mobile_code: sequelize.StringDataType;
|
package/models/user/user.js
CHANGED
|
@@ -58,10 +58,6 @@ exports.UserAttr = {
|
|
|
58
58
|
organ_id: {
|
|
59
59
|
type: sequelize.INTEGER({ length: 11 })
|
|
60
60
|
},
|
|
61
|
-
// points:sequelize.INTEGER({length:11}),
|
|
62
|
-
member_id: {
|
|
63
|
-
type: sequelize.STRING(100)
|
|
64
|
-
},
|
|
65
61
|
provider: sequelize.STRING(40),
|
|
66
62
|
mobile: sequelize.STRING(20),
|
|
67
63
|
mobile_code: sequelize.STRING(10)
|
package/package.json
CHANGED
package/utils/auth.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ export declare const getTokenFromReq: (req: any) => any;
|
|
|
3
3
|
export declare class AuthUtil {
|
|
4
4
|
ref: string;
|
|
5
5
|
constructor(ref: string);
|
|
6
|
-
create(id: any, { include }?: {
|
|
6
|
+
create(id: any, { include, include_token, setting }?: {
|
|
7
7
|
include?: {};
|
|
8
|
+
include_token?: {};
|
|
9
|
+
setting?: {};
|
|
8
10
|
}): Promise<{
|
|
9
11
|
refresh_token: string;
|
|
10
12
|
access_token: string;
|
package/utils/auth.js
CHANGED
|
@@ -11,7 +11,7 @@ const authError_1 = require("../errors/authError");
|
|
|
11
11
|
const jwt = require("jsonwebtoken");
|
|
12
12
|
const signToken = (id, expIn, opt = {}) => {
|
|
13
13
|
const date = (0, helper_1.getDateTime)();
|
|
14
|
-
return jwt.sign(Object.assign({ id: id, createAt: date, expAt: date.add(expIn, 'days') }, opt), (0, helper_1.getENV)('JWT_SECRET'));
|
|
14
|
+
return jwt.sign(Object.assign({ id: id, createAt: date, expAt: date.clone().add(expIn, 'days') }, opt), (0, helper_1.getENV)('JWT_SECRET'));
|
|
15
15
|
};
|
|
16
16
|
const getIdFromReq = (req) => {
|
|
17
17
|
try {
|
|
@@ -30,14 +30,19 @@ class AuthUtil {
|
|
|
30
30
|
constructor(ref) {
|
|
31
31
|
this.ref = ref;
|
|
32
32
|
}
|
|
33
|
-
create(id, { include = {} } = {}) {
|
|
33
|
+
create(id, { include = {}, include_token = {}, setting = {} } = {}) {
|
|
34
34
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
35
35
|
let refreshTokenUUID = (0, helper_1.getUUID)();
|
|
36
36
|
let include_access = {};
|
|
37
37
|
if (Object.keys(include).length) {
|
|
38
38
|
include_access['setting'] = JSON.stringify(include);
|
|
39
39
|
}
|
|
40
|
-
let
|
|
40
|
+
let rf_expire_in = Number(setting['expire_in'] || (0, helper_1.getENV)('REFRESH_TOKEN_AGE', 1));
|
|
41
|
+
let ac_expire_in = Number((0, helper_1.getENV)('ACCESS_TOKEN_AGE', 1));
|
|
42
|
+
if (rf_expire_in < ac_expire_in) {
|
|
43
|
+
ac_expire_in = rf_expire_in;
|
|
44
|
+
}
|
|
45
|
+
let input = Object.assign({ id: refreshTokenUUID, user_id: id, expired_at: (0, helper_1.getDateTime)().add(rf_expire_in, 'days'), token: signToken(id, rf_expire_in, Object.assign({ refresh_token_id: refreshTokenUUID }, include_token)), accessToken: Object.assign({ user_id: id, expired_at: (0, helper_1.getDateTime)().add(ac_expire_in, 'days'), token: signToken(id, ac_expire_in, Object.assign({ refresh_token_id: refreshTokenUUID }, include_token)) }, include_access) }, include);
|
|
41
46
|
yield refresh_token_1.RefreshTokenModel.schema(this.ref, "_").create(input, {
|
|
42
47
|
include: [
|
|
43
48
|
{
|
package/utils/db.js
CHANGED
|
@@ -32,12 +32,12 @@ const getWhereVal = (smth) => {
|
|
|
32
32
|
return [key, value].join(` ${smth.comparator} `);
|
|
33
33
|
};
|
|
34
34
|
const genWhere = (where = {}, { as = "", delimiter = ".", prefix = true, bracket = false } = {}) => {
|
|
35
|
-
|
|
35
|
+
let keyPrefix = as ? "`" + as + "`" + delimiter : as;
|
|
36
36
|
let symbolKeys = Object.getOwnPropertySymbols(where);
|
|
37
37
|
let rawWhere = (Object.keys(where).concat(symbolKeys)).reduce((result, key) => {
|
|
38
38
|
let value = where[key];
|
|
39
39
|
if (typeof value !== 'undefined') {
|
|
40
|
-
key = typeof (
|
|
40
|
+
key = typeof (key) == "string" ? keyPrefix + "`" + (key.split('.').join("`.`")) + "`" : key;
|
|
41
41
|
if (typeof (value) == "string") {
|
|
42
42
|
value = SqlString.escape(value);
|
|
43
43
|
}
|
|
@@ -48,7 +48,7 @@ const genWhere = (where = {}, { as = "", delimiter = ".", prefix = true, bracket
|
|
|
48
48
|
result = `${result}( ${op}) AND `;
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
result =
|
|
51
|
+
result = result + key + ` IN (${value.map(i => "'" + i + "'").join(',')}) AND `;
|
|
52
52
|
}
|
|
53
53
|
return result;
|
|
54
54
|
}
|
|
@@ -62,7 +62,7 @@ const genWhere = (where = {}, { as = "", delimiter = ".", prefix = true, bracket
|
|
|
62
62
|
return result;
|
|
63
63
|
}
|
|
64
64
|
else if (typeof value == "object" && value['val']) {
|
|
65
|
-
result =
|
|
65
|
+
result = result + key + `=${value['val']} AND `;
|
|
66
66
|
return result;
|
|
67
67
|
}
|
|
68
68
|
result = result + key + "=" + value + " AND ";
|
package/utils/file.d.ts
CHANGED
|
@@ -62,16 +62,23 @@ export declare class FileUtil {
|
|
|
62
62
|
width?: number;
|
|
63
63
|
height?: number;
|
|
64
64
|
}): Promise<any>;
|
|
65
|
-
beforeFindFile(where?: {}, { tags, group }?: {
|
|
65
|
+
beforeFindFile(where?: {}, { attributes, tags, group, verify }?: {
|
|
66
|
+
attributes?: any;
|
|
66
67
|
tags?: TagFile;
|
|
67
68
|
group?: any;
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
verify?: boolean;
|
|
70
|
+
}): {
|
|
71
|
+
where: {};
|
|
72
|
+
attributes: any;
|
|
73
|
+
order: any[];
|
|
74
|
+
};
|
|
75
|
+
findAllFile({ where, folder, full, file_link, thumb, verify, width, height, parent_folder, attributes, limit, offset, tag, tags, group }?: {
|
|
70
76
|
where?: {};
|
|
71
77
|
folder?: boolean;
|
|
72
78
|
full?: boolean;
|
|
73
79
|
file_link?: boolean;
|
|
74
80
|
thumb?: boolean;
|
|
81
|
+
verify?: boolean;
|
|
75
82
|
width?: number;
|
|
76
83
|
height?: number;
|
|
77
84
|
parent_folder?: string;
|
|
@@ -124,11 +131,12 @@ export declare class FileUtil {
|
|
|
124
131
|
tags?: TagFile;
|
|
125
132
|
group?: any;
|
|
126
133
|
}): 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 }?: {
|
|
134
|
+
uploadByReq(req: Request, slug: string, user_id: any, { parent_id, parent_slug, name, root, format, thumb, width, height, input, is_hidden, tags, group }?: {
|
|
128
135
|
parent_id?: number;
|
|
129
136
|
parent_slug?: string;
|
|
130
137
|
name?: any;
|
|
131
138
|
root?: boolean;
|
|
139
|
+
format?: boolean;
|
|
132
140
|
thumb?: boolean;
|
|
133
141
|
width?: number;
|
|
134
142
|
height?: number;
|
|
@@ -146,7 +154,7 @@ export declare class FileUtil {
|
|
|
146
154
|
hidden?: number;
|
|
147
155
|
input?: {};
|
|
148
156
|
}): Promise<any>;
|
|
149
|
-
createFileByPath(files: Array<
|
|
157
|
+
createFileByPath(files: Array<any>, slug: string, user_id: any, { parent_slug, type, name, root, upload, tags, group }?: {
|
|
150
158
|
parent_slug?: string;
|
|
151
159
|
type?: string;
|
|
152
160
|
name?: any;
|
|
@@ -156,7 +164,8 @@ export declare class FileUtil {
|
|
|
156
164
|
group?: any;
|
|
157
165
|
}): Promise<any>;
|
|
158
166
|
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 }?: {
|
|
167
|
+
formatFile(folder_id: any, user_id: any, reqs: Array<any>, files: Array<any>, { format, use_id, field, formatDateTime, input, is_hidden, tags, group }?: {
|
|
168
|
+
format?: boolean;
|
|
160
169
|
use_id?: boolean;
|
|
161
170
|
field?: any[];
|
|
162
171
|
formatDateTime?: string;
|
|
@@ -169,7 +178,7 @@ export declare class FileUtil {
|
|
|
169
178
|
user_id: any;
|
|
170
179
|
organ_id: any;
|
|
171
180
|
organ_by: any;
|
|
172
|
-
sort:
|
|
181
|
+
sort: any;
|
|
173
182
|
date_added: string;
|
|
174
183
|
name: any;
|
|
175
184
|
filename: any;
|
|
@@ -179,15 +188,18 @@ export declare class FileUtil {
|
|
|
179
188
|
extension: string;
|
|
180
189
|
type: any;
|
|
181
190
|
is_hidden: any;
|
|
182
|
-
tags:
|
|
191
|
+
tags: any;
|
|
192
|
+
custom: any;
|
|
183
193
|
group: any;
|
|
184
194
|
}[]>;
|
|
185
|
-
insertFileUnique(results: Array<any>, { thumb, width, height }?: {
|
|
195
|
+
insertFileUnique(results: Array<any>, { format, thumb, width, height }?: {
|
|
196
|
+
format?: boolean;
|
|
186
197
|
thumb?: boolean;
|
|
187
198
|
width?: number;
|
|
188
199
|
height?: number;
|
|
189
200
|
}): any;
|
|
190
|
-
uploadRawFormat(files: Array<any>, { field }?: {
|
|
201
|
+
uploadRawFormat(files: Array<any>, { format, field }?: {
|
|
202
|
+
format?: boolean;
|
|
191
203
|
field?: string[];
|
|
192
204
|
}): Promise<any>;
|
|
193
205
|
updateFile(id: string, input?: any, { paths }?: {
|
package/utils/file.js
CHANGED
|
@@ -108,6 +108,7 @@ class FileUtil {
|
|
|
108
108
|
}
|
|
109
109
|
afterQueryFile(data = {}, { tag = {}, file_link = false } = {}) {
|
|
110
110
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
delete data['thumbnail'];
|
|
111
112
|
data['custom'] = data['custom'] || {};
|
|
112
113
|
data['tags'] = data['tags'] || [];
|
|
113
114
|
if (data['filename'] == data['path']) {
|
|
@@ -133,6 +134,7 @@ class FileUtil {
|
|
|
133
134
|
let reqs = [], results = [];
|
|
134
135
|
for (let file of files) {
|
|
135
136
|
let extension = mime.extension(file.mimetype);
|
|
137
|
+
extension = extension ? extension : String(file.mimetype).split('/')[1];
|
|
136
138
|
let input = {
|
|
137
139
|
Bucket: this.bucket,
|
|
138
140
|
Key: this.ref + "/" + (0, helper_1.getDateTime)().format('X') + '.' + (0, helper_1.getSlug)(32) + '.' + extension,
|
|
@@ -256,7 +258,7 @@ class FileUtil {
|
|
|
256
258
|
result[width + 'x' + height] = thumb;
|
|
257
259
|
yield (0, db_1.update)(this.ref, file_1.FileModel.getTableName().toString(), { thumb: JSON.stringify(result) }, { where: { id: item['id'] } });
|
|
258
260
|
}
|
|
259
|
-
if (item['filename'] == path) {
|
|
261
|
+
if (thumb && item['filename'] == path) {
|
|
260
262
|
yield this.getStorage();
|
|
261
263
|
let data = yield this.afterQueryFile({ filename: thumb, path: thumb });
|
|
262
264
|
thumb = data.path;
|
|
@@ -275,12 +277,12 @@ class FileUtil {
|
|
|
275
277
|
return null;
|
|
276
278
|
where['$folder.parent_id$'] = query['id'];
|
|
277
279
|
}
|
|
278
|
-
|
|
280
|
+
let option = this.beforeFindFile(where, { attributes: ['id', 'extension', 'filename', 'path', 'thumb'], tags, group });
|
|
279
281
|
let result = yield file_1.FileModel.schema(this.ref, "_").findOne({
|
|
280
|
-
raw: true, attributes:
|
|
281
|
-
where: Object.assign({ '$folder.slug$': slug }, where),
|
|
282
|
+
raw: true, attributes: option.attributes,
|
|
283
|
+
where: Object.assign({ '$folder.slug$': slug }, option.where),
|
|
282
284
|
include: [{ as: 'folder', model: folder_1.FolderModel.schema(this.ref, "_"), attributes: [] }],
|
|
283
|
-
order:
|
|
285
|
+
order: option.order
|
|
284
286
|
});
|
|
285
287
|
return this.findImageThumb(result, { width, height });
|
|
286
288
|
}
|
|
@@ -298,7 +300,8 @@ class FileUtil {
|
|
|
298
300
|
return this.findImageThumb(item, { width, height });
|
|
299
301
|
});
|
|
300
302
|
}
|
|
301
|
-
beforeFindFile(where = {}, { tags = [], group = undefined } = {}) {
|
|
303
|
+
beforeFindFile(where = {}, { attributes = undefined, tags = [], group = undefined, verify = false } = {}) {
|
|
304
|
+
let order = [['sort', 'asc'], ['tags', 'desc']], thumbnail = false;
|
|
302
305
|
if (this.option.organ_id) {
|
|
303
306
|
where[sequelize_1.Op.and] = (where[sequelize_1.Op.and] || []).concat({ [sequelize_1.Op.or]: [{ organ_id: this.option.organ_id }, { organ_by: this.option.organ_id }] });
|
|
304
307
|
}
|
|
@@ -309,9 +312,11 @@ class FileUtil {
|
|
|
309
312
|
let op = tags.reduce((total, tag) => {
|
|
310
313
|
let value = Object.keys(tag).reduce((total, key) => total.concat([`'${key}'`, `"${tag[key]}"`]), []).join(',');
|
|
311
314
|
if (value) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
+
if (tag['slug'] == "thumbnail" && !verify) {
|
|
316
|
+
thumbnail = true;
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
total = total.concat((0, sequelize_1.literal)(`JSON_CONTAINS(tags,JSON_OBJECT(${value}))`));
|
|
315
320
|
}
|
|
316
321
|
}
|
|
317
322
|
return total;
|
|
@@ -320,9 +325,19 @@ class FileUtil {
|
|
|
320
325
|
where[sequelize_1.Op.and] = (where[sequelize_1.Op.and] || []).concat({ [sequelize_1.Op.or]: op });
|
|
321
326
|
}
|
|
322
327
|
}
|
|
323
|
-
|
|
328
|
+
if (thumbnail) {
|
|
329
|
+
let include = [[(0, sequelize_1.literal)(`IF(JSON_CONTAINS(tags,JSON_OBJECT('slug',"thumbnail")),'yes','no')`), 'thumbnail']];
|
|
330
|
+
if (typeof attributes == "undefined") {
|
|
331
|
+
attributes = { include };
|
|
332
|
+
}
|
|
333
|
+
else if (attributes instanceof Array) {
|
|
334
|
+
attributes = attributes.concat(include);
|
|
335
|
+
}
|
|
336
|
+
order = [['thumbnail', 'desc'], ['sort', 'asc']];
|
|
337
|
+
}
|
|
338
|
+
return { where, attributes, order };
|
|
324
339
|
}
|
|
325
|
-
findAllFile({ where = {}, folder = false, full = false, file_link = false, thumb = false, width = 0, height = 0, parent_folder = "", attributes = undefined, limit = undefined, offset = undefined, tag = {}, tags = [], group = undefined } = {}) {
|
|
340
|
+
findAllFile({ where = {}, folder = false, full = false, file_link = false, thumb = false, verify = true, width = 0, height = 0, parent_folder = "", attributes = undefined, limit = undefined, offset = undefined, tag = {}, tags = [], group = undefined } = {}) {
|
|
326
341
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
327
342
|
try {
|
|
328
343
|
let include = [];
|
|
@@ -334,10 +349,10 @@ class FileUtil {
|
|
|
334
349
|
return [];
|
|
335
350
|
where['$folder.parent_id$'] = query['id'];
|
|
336
351
|
}
|
|
337
|
-
where = this.beforeFindFile(where, { tags, group });
|
|
338
352
|
where['is_hidden'] = where['is_hidden'] || "no";
|
|
353
|
+
let option = this.beforeFindFile(where, { attributes, tags, group, verify });
|
|
339
354
|
let result = yield file_1.FileModel.schema(this.ref, "_").findAll({
|
|
340
|
-
attributes, raw: true, where, limit, offset, include, order:
|
|
355
|
+
attributes: option.attributes, raw: true, where: option.where, limit, offset, include, order: option.order
|
|
341
356
|
});
|
|
342
357
|
result.length && (yield this.getStorage());
|
|
343
358
|
result = yield Promise.all(result.map((item) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -371,9 +386,9 @@ class FileUtil {
|
|
|
371
386
|
if (!folder)
|
|
372
387
|
return { rows: [], count: 0 };
|
|
373
388
|
where['folder_id'] = folder['id'];
|
|
374
|
-
where = this.beforeFindFile(where, { tags, group });
|
|
375
389
|
where['is_hidden'] = where['is_hidden'] || "no";
|
|
376
|
-
let
|
|
390
|
+
let option = this.beforeFindFile(where, { tags, group, verify: true });
|
|
391
|
+
let data = yield Promise.all([this.findAllFile({ where, full: true, file_link, limit, offset, tag, group }), file_1.FileModel.schema(this.ref, "_").count({ where: option.where })]);
|
|
377
392
|
return { rows: data[0], count: data[1] };
|
|
378
393
|
});
|
|
379
394
|
}
|
|
@@ -384,7 +399,7 @@ class FileUtil {
|
|
|
384
399
|
}
|
|
385
400
|
findOneFileByFolder(slug, { where = {}, full = false, file_link = false, parent_folder = "", tags = [], group = null } = {}) {
|
|
386
401
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
387
|
-
return (yield this.findAllFile({ where: Object.assign({ '$folder.slug$': slug }, where), folder: true, full, file_link, parent_folder, limit: 1, tags, group }))[0] || null;
|
|
402
|
+
return (yield this.findAllFile({ where: Object.assign({ '$folder.slug$': slug }, where), folder: true, full, file_link, verify: false, parent_folder, limit: 1, tags, group }))[0] || null;
|
|
388
403
|
});
|
|
389
404
|
}
|
|
390
405
|
findOneFileById(id, { where = {}, full = true, file_link = false, parent_folder = "", tags = [], group = null } = {}) {
|
|
@@ -392,7 +407,7 @@ class FileUtil {
|
|
|
392
407
|
return (yield this.findAllFile({ where: Object.assign({ id }, where), full, file_link, parent_folder, limit: 1, tags, group }))[0] || null;
|
|
393
408
|
});
|
|
394
409
|
}
|
|
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 } = {}) {
|
|
410
|
+
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
411
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
397
412
|
req.files = req.file ? [req.file] : (req.files || []);
|
|
398
413
|
if (req.files.length && slug) {
|
|
@@ -406,6 +421,7 @@ class FileUtil {
|
|
|
406
421
|
let folder = yield this.createFolder(slug, { parent_id, root, name });
|
|
407
422
|
for (let file of req.files) {
|
|
408
423
|
let extension = mime.extension(file.mimetype);
|
|
424
|
+
extension = extension ? extension : String(file.mimetype).split('/')[1];
|
|
409
425
|
let input = {
|
|
410
426
|
Bucket: this.bucket,
|
|
411
427
|
Key: this.ref + "/" + (0, helper_1.getDateTime)().format('X') + '.' + (0, helper_1.getSlug)(32) + '.' + extension,
|
|
@@ -419,7 +435,7 @@ class FileUtil {
|
|
|
419
435
|
}
|
|
420
436
|
let results = yield this.upload(files);
|
|
421
437
|
results = yield this.formatFile(folder['id'], user_id, reqs, results, { input, is_hidden, tags, group });
|
|
422
|
-
return yield this.insertFileUnique(results, { thumb, width, height });
|
|
438
|
+
return yield this.insertFileUnique(results, { format, thumb, width, height });
|
|
423
439
|
}
|
|
424
440
|
return Promise.reject(errors_1.generalError.BAD_REQUEST);
|
|
425
441
|
});
|
|
@@ -470,8 +486,13 @@ class FileUtil {
|
|
|
470
486
|
let folder = yield this.createFolder(slug, { parent_id, root, name });
|
|
471
487
|
let results = [], reqs = [];
|
|
472
488
|
files.forEach((item) => {
|
|
473
|
-
|
|
474
|
-
|
|
489
|
+
let addition = {}, path = item;
|
|
490
|
+
if (typeof item == "object") {
|
|
491
|
+
addition = item;
|
|
492
|
+
path = item['path'];
|
|
493
|
+
}
|
|
494
|
+
results.push({ Location: path, Key: path });
|
|
495
|
+
reqs.push(Object.assign({ originalname: (0, helper_1.getSlug)(32), mimetype: null, size: 0, type }, addition));
|
|
475
496
|
});
|
|
476
497
|
results = yield this.formatFile(folder['id'], user_id, reqs, results, { input, tags, group });
|
|
477
498
|
return yield this.insertFileUnique(results);
|
|
@@ -557,7 +578,7 @@ class FileUtil {
|
|
|
557
578
|
return type;
|
|
558
579
|
});
|
|
559
580
|
}
|
|
560
|
-
formatFile(folder_id, user_id, reqs, files, { use_id = true, field = [], formatDateTime = "X", input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
|
|
581
|
+
formatFile(folder_id, user_id, reqs, files, { format = false, use_id = true, field = [], formatDateTime = "X", input = {}, is_hidden = undefined, tags = undefined, group = undefined } = {}) {
|
|
561
582
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
562
583
|
try {
|
|
563
584
|
let result = yield Promise.all(files.map((file, key) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -574,30 +595,30 @@ class FileUtil {
|
|
|
574
595
|
path = (index < 0) ? protocol + path : path;
|
|
575
596
|
}
|
|
576
597
|
let extension = mime.extension(reqs[key].mimetype);
|
|
577
|
-
|
|
598
|
+
extension = extension ? extension : String(reqs[key].mimetype).split('/')[1];
|
|
599
|
+
let item = Object.assign(Object.assign({}, input), { folder_id,
|
|
578
600
|
user_id,
|
|
579
601
|
organ_id,
|
|
580
|
-
organ_by,
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
group });
|
|
602
|
+
organ_by, sort: reqs[key].sort || sort, 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, custom: reqs[key].custom || input['custom'], group });
|
|
603
|
+
if (format) {
|
|
604
|
+
item = yield this.afterQueryFile(item);
|
|
605
|
+
}
|
|
585
606
|
if (use_id) {
|
|
586
|
-
|
|
607
|
+
item['id'] = id;
|
|
587
608
|
}
|
|
588
609
|
if (reqs[key].mimetype && reqs[key].mimetype.split('/')[0] == "image") {
|
|
589
610
|
try {
|
|
590
611
|
let body = reqs[key].Body || reqs[key].buffer;
|
|
591
612
|
let image = yield jimp.read(body);
|
|
592
|
-
|
|
593
|
-
|
|
613
|
+
item['height'] = image.bitmap.height;
|
|
614
|
+
item['width'] = image.bitmap.width;
|
|
594
615
|
}
|
|
595
616
|
catch (err) { }
|
|
596
617
|
}
|
|
597
618
|
if (field.length) {
|
|
598
|
-
|
|
619
|
+
item = _.pick(item, field);
|
|
599
620
|
}
|
|
600
|
-
return
|
|
621
|
+
return item;
|
|
601
622
|
})));
|
|
602
623
|
return result;
|
|
603
624
|
}
|
|
@@ -606,7 +627,7 @@ class FileUtil {
|
|
|
606
627
|
}
|
|
607
628
|
});
|
|
608
629
|
}
|
|
609
|
-
insertFileUnique(results, { thumb = false, width = 0, height = 0 } = {}) {
|
|
630
|
+
insertFileUnique(results, { format = false, thumb = false, width = 0, height = 0 } = {}) {
|
|
610
631
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
611
632
|
try {
|
|
612
633
|
let data = yield file_1.FileModel.schema(this.ref, "_").bulkCreate(results);
|
|
@@ -614,15 +635,14 @@ class FileUtil {
|
|
|
614
635
|
return Promise.reject(errors_1.generalError.BAD_REQUEST);
|
|
615
636
|
}
|
|
616
637
|
let result = data.map(item => item.toJSON());
|
|
617
|
-
if (thumb) {
|
|
618
|
-
// create thumb
|
|
638
|
+
if (format || thumb) {
|
|
639
|
+
// format or create thumb
|
|
619
640
|
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 });
|
|
641
|
+
let include = (yield this.afterQueryFile(item)) || {};
|
|
642
|
+
if (thumb && item['type'] == 'i') {
|
|
643
|
+
include['thumb'] = yield this.findImageThumb(item, { width, height });
|
|
624
644
|
}
|
|
625
|
-
return item;
|
|
645
|
+
return Object.assign(Object.assign({}, item), include);
|
|
626
646
|
})));
|
|
627
647
|
}
|
|
628
648
|
return result;
|
|
@@ -630,16 +650,16 @@ class FileUtil {
|
|
|
630
650
|
catch (err) {
|
|
631
651
|
if (err.errors && err.errors[0].validatorKey == "not_unique") {
|
|
632
652
|
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 });
|
|
653
|
+
return yield this.insertFileUnique(results, { format, thumb, width, height });
|
|
634
654
|
}
|
|
635
655
|
return Promise.reject(errors_1.generalError.BAD_REQUEST);
|
|
636
656
|
}
|
|
637
657
|
});
|
|
638
658
|
}
|
|
639
|
-
uploadRawFormat(files, { field = ['name', 'filename', 'path', 'mimetype', 'filesize', 'extension', 'type', 'height', 'width'] } = {}) {
|
|
659
|
+
uploadRawFormat(files, { format = false, field = ['name', 'filename', 'path', 'mimetype', 'filesize', 'extension', 'type', 'height', 'width'] } = {}) {
|
|
640
660
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
641
661
|
let query = yield this.uploadRaw(files);
|
|
642
|
-
return yield this.formatFile(0, 0, files, query, { field });
|
|
662
|
+
return yield this.formatFile(0, 0, files, query, { format, field });
|
|
643
663
|
});
|
|
644
664
|
}
|
|
645
665
|
updateFile(id, input = {}, { paths = [] } = {}) {
|
|
@@ -672,8 +692,8 @@ class FileUtil {
|
|
|
672
692
|
}
|
|
673
693
|
remove({ where = {}, delete_object = false, error = true, tags = [], group = undefined } = {}) {
|
|
674
694
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
675
|
-
|
|
676
|
-
let files = yield file_1.FileModel.schema(this.ref, "_").findAll({ where, attributes: ['id', 'path', 'thumb'], raw: true });
|
|
695
|
+
let option = this.beforeFindFile(where, { tags, group, verify: true });
|
|
696
|
+
let files = yield file_1.FileModel.schema(this.ref, "_").findAll({ where: option.where, attributes: ['id', 'path', 'thumb'], raw: true });
|
|
677
697
|
if (files.length) {
|
|
678
698
|
let paths = [], id = files.map(i => { paths = paths.concat(this.getFilePath(i)); return i['id']; });
|
|
679
699
|
yield file_1.FileModel.schema(this.ref, "_").destroy({ where: { id } });
|
package/utils/helper.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ export declare const getDaysBetweenDates: (startDate: any, endDate: any, { utc }
|
|
|
12
12
|
}) => any[];
|
|
13
13
|
export declare const Joi_date: any;
|
|
14
14
|
export declare const getENV: (str: string, def?: any) => any;
|
|
15
|
+
export declare const getENVIndex: (index: string, { prefix, force }?: {
|
|
16
|
+
prefix?: string;
|
|
17
|
+
force?: boolean;
|
|
18
|
+
}) => string;
|
|
15
19
|
export declare const getSlug: (length?: number) => string;
|
|
16
20
|
export declare const getDateMysql: (date?: any) => any;
|
|
17
21
|
export declare const getTimestampMysql: (date?: any) => number;
|
|
@@ -50,6 +54,9 @@ export declare const removeHyphen: (str: string, replace?: string, { encode, rep
|
|
|
50
54
|
export declare const getMobileNumber: (str: string, { prefix }?: {
|
|
51
55
|
prefix?: string;
|
|
52
56
|
}) => string;
|
|
57
|
+
export declare const formatMobileNumber: (str: string, { prefix }?: {
|
|
58
|
+
prefix?: string;
|
|
59
|
+
}) => string;
|
|
53
60
|
export declare const removeSpace: (str: string, replace?: string) => string;
|
|
54
61
|
export declare const removeAt: (str: string, replace?: string) => string;
|
|
55
62
|
export declare const isNumber: (val: any, { negative }?: {
|
|
@@ -64,7 +71,7 @@ export declare const randomRef: ({ length_digital, length_alphabet }?: {
|
|
|
64
71
|
length_alphabet?: number;
|
|
65
72
|
}) => string;
|
|
66
73
|
export declare const treeToArray: (items: Array<any>, array?: Array<any>, level?: number) => Promise<any[]>;
|
|
67
|
-
export declare const buildTree: (nodes: Array<any>, { index, field_children, json_convert, key_index, key_parent, root, to_array }?: {
|
|
74
|
+
export declare const buildTree: (nodes: Array<any>, { index, field_children, json_convert, key_index, key_parent, root, to_array, notfound_parent }?: {
|
|
68
75
|
index?: any;
|
|
69
76
|
field_children?: string;
|
|
70
77
|
json_convert?: boolean;
|
|
@@ -72,6 +79,7 @@ export declare const buildTree: (nodes: Array<any>, { index, field_children, jso
|
|
|
72
79
|
key_parent?: string;
|
|
73
80
|
root?: any;
|
|
74
81
|
to_array?: boolean;
|
|
82
|
+
notfound_parent?: boolean;
|
|
75
83
|
}) => Promise<any[]>;
|
|
76
84
|
export declare const expandTree: (items: Array<any>, { array, parent, level, prefix, field_index, field_children, key_value }?: {
|
|
77
85
|
array?: any[];
|
|
@@ -88,6 +96,7 @@ export declare const slugify: (string?: any, { lowercase }?: {
|
|
|
88
96
|
}) => any;
|
|
89
97
|
export declare const slugifyField: (string?: any) => any;
|
|
90
98
|
export declare const stripHtml: (string: string) => string;
|
|
99
|
+
export declare const stripEmoji: (string: string) => string;
|
|
91
100
|
export declare const replaceColon: (string: string, { decode }?: {
|
|
92
101
|
decode?: boolean;
|
|
93
102
|
}) => string;
|
package/utils/helper.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertCurrency = exports.xorMerge = exports.xorDecode = exports.xorEncode = exports.getInstanceNumber = exports.getDomain = exports.getParent = exports.replaceColon = exports.stripHtml = exports.slugifyField = exports.slugify = exports.convertToBigEndian = exports.expandTree = exports.buildTree = exports.treeToArray = exports.randomRef = exports.multiExecArray = exports.isBase64 = exports.isNumber = exports.removeAt = exports.removeSpace = exports.getMobileNumber = exports.removeHyphen = exports.signToken = exports.getTokenDataFromTokenBySecret = exports.getUUID32 = exports.getUUID = exports.sleep = exports.getValueByLang = exports.getValueFunctionLang = exports.getValueFunctionFile = exports.getDateTime = exports.getTimestampMysql = exports.getDateMysql = exports.getSlug = exports.getENV = exports.Joi_date = exports.getDaysBetweenDates = exports.getDateFromString = exports.getDateRangeFormat = void 0;
|
|
3
|
+
exports.convertCurrency = exports.xorMerge = exports.xorDecode = exports.xorEncode = exports.getInstanceNumber = exports.getDomain = exports.getParent = exports.replaceColon = exports.stripEmoji = exports.stripHtml = exports.slugifyField = exports.slugify = exports.convertToBigEndian = exports.expandTree = exports.buildTree = exports.treeToArray = exports.randomRef = exports.multiExecArray = exports.isBase64 = exports.isNumber = exports.removeAt = exports.removeSpace = exports.formatMobileNumber = exports.getMobileNumber = exports.removeHyphen = exports.signToken = exports.getTokenDataFromTokenBySecret = exports.getUUID32 = exports.getUUID = exports.sleep = exports.getValueByLang = exports.getValueFunctionLang = exports.getValueFunctionFile = exports.getDateTime = exports.getTimestampMysql = exports.getDateMysql = exports.getSlug = exports.getENVIndex = exports.getENV = exports.Joi_date = exports.getDaysBetweenDates = exports.getDateFromString = exports.getDateRangeFormat = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const crypto = require("crypto");
|
|
6
6
|
const dotenv = require("dotenv");
|
|
@@ -57,6 +57,13 @@ const getENV = (str, def) => {
|
|
|
57
57
|
return process.env[str] || def;
|
|
58
58
|
};
|
|
59
59
|
exports.getENV = getENV;
|
|
60
|
+
const getENVIndex = (index, { prefix = "dev", force = false } = {}) => {
|
|
61
|
+
if (process.env.NODE_ENV == "production" || force) {
|
|
62
|
+
return index;
|
|
63
|
+
}
|
|
64
|
+
return prefix + "_" + index;
|
|
65
|
+
};
|
|
66
|
+
exports.getENVIndex = getENVIndex;
|
|
60
67
|
const getSlug = (length = 8) => {
|
|
61
68
|
return new short_unique_id_1.default().randomUUID(length);
|
|
62
69
|
};
|
|
@@ -154,14 +161,25 @@ exports.removeHyphen = removeHyphen;
|
|
|
154
161
|
const getMobileNumber = (str, { prefix = "+66" } = {}) => {
|
|
155
162
|
if (str) {
|
|
156
163
|
str = str.replace(/_/g, "").replace(/-/g, "").replace(/ /g, "");
|
|
157
|
-
if (str.indexOf("+") == -1 && str.length == 10) {
|
|
158
|
-
str
|
|
164
|
+
if (str.indexOf("+") == -1 && (str.length == 10 || str.length == 9)) {
|
|
165
|
+
if (str.length == 10 && str[0] == "0")
|
|
166
|
+
str = str.substr(1);
|
|
159
167
|
str = prefix + str;
|
|
160
168
|
}
|
|
161
169
|
}
|
|
162
170
|
return str;
|
|
163
171
|
};
|
|
164
172
|
exports.getMobileNumber = getMobileNumber;
|
|
173
|
+
const formatMobileNumber = (str, { prefix = "+66" } = {}) => {
|
|
174
|
+
if (str) {
|
|
175
|
+
str = str.replace(/_/g, "").replace(/-/g, "").replace(/ /g, "").replace(prefix, "");
|
|
176
|
+
if (str.length == 9) {
|
|
177
|
+
str = "0" + str;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return str;
|
|
181
|
+
};
|
|
182
|
+
exports.formatMobileNumber = formatMobileNumber;
|
|
165
183
|
const removeSpace = (str, replace = "") => {
|
|
166
184
|
return str ? str.replace(/ /g, replace) : "";
|
|
167
185
|
};
|
|
@@ -228,7 +246,7 @@ const treeToArray = (items, array = [], level = 1) => tslib_1.__awaiter(void 0,
|
|
|
228
246
|
return array;
|
|
229
247
|
});
|
|
230
248
|
exports.treeToArray = treeToArray;
|
|
231
|
-
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* () {
|
|
249
|
+
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* () {
|
|
232
250
|
if (!nodes) {
|
|
233
251
|
return null;
|
|
234
252
|
}
|
|
@@ -266,11 +284,16 @@ const buildTree = (nodes, { index = undefined, field_children = "children", json
|
|
|
266
284
|
}
|
|
267
285
|
}
|
|
268
286
|
parent[field_children] = results;
|
|
287
|
+
delete children[parent[key_index]];
|
|
269
288
|
}
|
|
270
289
|
};
|
|
271
290
|
for (let i = 0, len = roots.length; i < len; ++i) {
|
|
272
291
|
findChildren(roots[i]);
|
|
273
292
|
}
|
|
293
|
+
if (notfound_parent) {
|
|
294
|
+
let items = Object.keys(children).reduce((total, key) => total.concat(children[key]), []);
|
|
295
|
+
roots.unshift({ [key_index]: -1, [field_children]: items });
|
|
296
|
+
}
|
|
274
297
|
if (index)
|
|
275
298
|
roots = roots[0];
|
|
276
299
|
if (roots && to_array) {
|
|
@@ -350,6 +373,10 @@ const stripHtml = (string) => {
|
|
|
350
373
|
.replace(/\n/g, '');
|
|
351
374
|
};
|
|
352
375
|
exports.stripHtml = stripHtml;
|
|
376
|
+
const stripEmoji = (string) => {
|
|
377
|
+
return String(string).replace(/(?![*#0-9]+)[\p{Emoji}\p{Emoji_Modifier}\p{Emoji_Component}\p{Emoji_Modifier_Base}\p{Emoji_Presentation}]/gu, '').trim();
|
|
378
|
+
};
|
|
379
|
+
exports.stripEmoji = stripEmoji;
|
|
353
380
|
const replaceColon = (string, { decode = false } = {}) => {
|
|
354
381
|
if (!string || typeof (string) != 'string') {
|
|
355
382
|
return string;
|
package/utils/metadata.js
CHANGED
|
@@ -27,11 +27,11 @@ class MetadataUtil {
|
|
|
27
27
|
let value = {}, type = types;
|
|
28
28
|
if (_.isObject(input[key])) {
|
|
29
29
|
let val = {};
|
|
30
|
-
_.each(input[key], (v, k) => { val['value_' + k] = (0, helper_1.stripHtml)(v
|
|
30
|
+
_.each(input[key], (v, k) => { val['value_' + k] = v ? (0, helper_1.stripEmoji)((0, helper_1.stripHtml)(v)).substring(0, str_length) : ""; });
|
|
31
31
|
value = val;
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
|
-
value = { value_en: (0, helper_1.stripHtml)(String(input[key] || "").substring(0, str_length)) };
|
|
34
|
+
value = { value_en: (0, helper_1.stripEmoji)((0, helper_1.stripHtml)(String(input[key] || "")).substring(0, str_length)) };
|
|
35
35
|
}
|
|
36
36
|
if (autoType && !items[key]) {
|
|
37
37
|
let str = key.split(":");
|
package/utils/stream.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export declare class StreamUtil {
|
|
|
40
40
|
private fileUtil;
|
|
41
41
|
private languageUtil;
|
|
42
42
|
constructor(ref?: string, option?: QueryParamOption, fileUtil?: FileUtil);
|
|
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, 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 }?: {
|
|
44
44
|
index?: string;
|
|
45
45
|
option?: {};
|
|
46
46
|
no_lang?: boolean;
|
|
@@ -55,6 +55,7 @@ export declare class StreamUtil {
|
|
|
55
55
|
include?: any;
|
|
56
56
|
include_only?: boolean;
|
|
57
57
|
convert_option?: boolean;
|
|
58
|
+
convert_value?: boolean;
|
|
58
59
|
field_option?: {};
|
|
59
60
|
require?: boolean;
|
|
60
61
|
multiple_table?: boolean;
|
|
@@ -117,7 +118,7 @@ export declare class StreamUtil {
|
|
|
117
118
|
result: {};
|
|
118
119
|
labels: any[];
|
|
119
120
|
}>;
|
|
120
|
-
genField(streams: Array<any>, { index, option, slug, id_stream, prefix, multiple_table, multiple_spread, addition, convert_option, field_option, default_value, default_lang, lang_code, no_lang, lang, country, section }?: {
|
|
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 }?: {
|
|
121
122
|
index?: string;
|
|
122
123
|
option?: {};
|
|
123
124
|
slug?: string;
|
|
@@ -127,6 +128,7 @@ export declare class StreamUtil {
|
|
|
127
128
|
multiple_spread?: boolean;
|
|
128
129
|
addition?: {};
|
|
129
130
|
convert_option?: boolean;
|
|
131
|
+
convert_value?: boolean;
|
|
130
132
|
field_option?: {};
|
|
131
133
|
default_value?: any;
|
|
132
134
|
default_lang?: string;
|
|
@@ -168,6 +170,14 @@ export declare class StreamUtil {
|
|
|
168
170
|
tags?: TagFile;
|
|
169
171
|
group?: any;
|
|
170
172
|
}): Promise<{}>;
|
|
173
|
+
upsertBySlugField(fields: Array<any>, index: string, { ref, req, parent_slug, input, tags, group }?: {
|
|
174
|
+
ref?: string;
|
|
175
|
+
req?: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
176
|
+
parent_slug?: string;
|
|
177
|
+
input?: {};
|
|
178
|
+
tags?: TagFile;
|
|
179
|
+
group?: any;
|
|
180
|
+
}): Promise<{}>;
|
|
171
181
|
findStream(slug: string, namespace: string, { result, lang_code, field_exclude, multiple, relationship, file, image, is_lang, stream, use_param }?: {
|
|
172
182
|
result?: any[];
|
|
173
183
|
lang_code?: string;
|
package/utils/stream.js
CHANGED
|
@@ -101,7 +101,7 @@ class StreamUtil {
|
|
|
101
101
|
this.fileUtil = fileUtil || new file_2.FileUtil(this.ref, this.option);
|
|
102
102
|
this.languageUtil = new language_1.LanguageUtil(this.ref, this.option);
|
|
103
103
|
}
|
|
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, 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 } = {}) {
|
|
105
105
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
106
106
|
let data;
|
|
107
107
|
let where = {};
|
|
@@ -184,7 +184,7 @@ class StreamUtil {
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
if (convert_option) {
|
|
187
|
-
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 });
|
|
188
188
|
}
|
|
189
189
|
if (field_only) {
|
|
190
190
|
return data['fields'];
|
|
@@ -347,7 +347,7 @@ class StreamUtil {
|
|
|
347
347
|
return { result, labels };
|
|
348
348
|
});
|
|
349
349
|
}
|
|
350
|
-
genField(streams, { index = "", option = {}, slug = "", id_stream = "", prefix = "", multiple_table = false, multiple_spread = false, addition = {}, convert_option = true, field_option = {}, default_value = {}, default_lang = "en", lang_code = "en", no_lang = false, lang = [], country = undefined, section = false } = {}) {
|
|
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 } = {}) {
|
|
351
351
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
352
352
|
let fields = [], sections = [];
|
|
353
353
|
let exclude = option['excludeObj'] || {};
|
|
@@ -472,7 +472,9 @@ class StreamUtil {
|
|
|
472
472
|
continue;
|
|
473
473
|
}
|
|
474
474
|
if (convert_option) {
|
|
475
|
+
let obj_value = {};
|
|
475
476
|
if (item['field_type'] == "choice") {
|
|
477
|
+
let opt_empty = false;
|
|
476
478
|
if (field_data['choice_data']) {
|
|
477
479
|
let data = [];
|
|
478
480
|
data = field_data['choice_data'].split('\n');
|
|
@@ -495,12 +497,16 @@ class StreamUtil {
|
|
|
495
497
|
data[k] = { key, value };
|
|
496
498
|
}
|
|
497
499
|
else {
|
|
500
|
+
opt_empty = true;
|
|
498
501
|
data[k] = { key: '', value };
|
|
499
502
|
}
|
|
500
503
|
}
|
|
501
504
|
else {
|
|
502
505
|
data[k] = { key: v, value: v };
|
|
503
506
|
}
|
|
507
|
+
if (convert_value && data[k]) {
|
|
508
|
+
obj_value[data[k]['key']] = data[k]['value'];
|
|
509
|
+
}
|
|
504
510
|
});
|
|
505
511
|
item['data'] = data;
|
|
506
512
|
}
|
|
@@ -510,9 +516,23 @@ class StreamUtil {
|
|
|
510
516
|
if (value && value.indexOf('lang:') > -1) {
|
|
511
517
|
item['value'] = (0, i18n_1.__)({ phrase: value, locale: lang_code });
|
|
512
518
|
}
|
|
519
|
+
if (!item['key'])
|
|
520
|
+
opt_empty = true;
|
|
521
|
+
if (convert_value && item['key']) {
|
|
522
|
+
obj_value[item['key']] = item['value'];
|
|
523
|
+
}
|
|
513
524
|
return item;
|
|
514
525
|
});
|
|
515
526
|
}
|
|
527
|
+
if (field_data['default_value'] && !opt_empty && (item['field_value'] == '' || item['field_value'] == null)) {
|
|
528
|
+
item['field_value'] = field_data['default_value'];
|
|
529
|
+
}
|
|
530
|
+
if (convert_value && typeof item['field_value'] != "undefined") {
|
|
531
|
+
let field_value = item['field_value'];
|
|
532
|
+
if (item['field_value'] == null && opt_empty)
|
|
533
|
+
field_value = '';
|
|
534
|
+
field_data['value'] = obj_value[field_value];
|
|
535
|
+
}
|
|
516
536
|
}
|
|
517
537
|
else if (!field_option[item['field_slug']] && (item['field_type'] == "relationship" || item['field_type'] == "multiple") && field_data['choose_stream']) {
|
|
518
538
|
try {
|
|
@@ -557,6 +577,9 @@ class StreamUtil {
|
|
|
557
577
|
item['title'] = item['title'] ? item['title'] : item[stream['title_column']];
|
|
558
578
|
(0, helper_2.getValueFunctionLang)('title')(item, { result: item, lang_code });
|
|
559
579
|
let value = item['title'] ? item['title'] : item['id'];
|
|
580
|
+
if (convert_value && item['id']) {
|
|
581
|
+
obj_value[item['id']] = value;
|
|
582
|
+
}
|
|
560
583
|
return {
|
|
561
584
|
key: item['id'],
|
|
562
585
|
value
|
|
@@ -567,6 +590,9 @@ class StreamUtil {
|
|
|
567
590
|
}
|
|
568
591
|
}
|
|
569
592
|
item['data'] = data;
|
|
593
|
+
if (convert_value && item['field_value']) {
|
|
594
|
+
field_data['value'] = obj_value[item['field_value']];
|
|
595
|
+
}
|
|
570
596
|
}
|
|
571
597
|
catch (err) { }
|
|
572
598
|
}
|
|
@@ -757,7 +783,7 @@ class StreamUtil {
|
|
|
757
783
|
if (id_stream && (streams && streams.length)) {
|
|
758
784
|
let file_id = [];
|
|
759
785
|
yield Promise.all(streams.map(({ field_type, field_slug, field_data }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
760
|
-
if (field_type == "multiple" && field_data && field_data['choose_stream']) {
|
|
786
|
+
if (field_type == "multiple" && field_data && field_data['choose_stream'] && field_data['self_table'] != "yes") {
|
|
761
787
|
let stream = yield stream_1.StreamModel.schema(this.ref, "_").findOne({ where: { id: field_data['choose_stream'] }, raw: true, attributes: ['stream_slug', 'stream_prefix'] });
|
|
762
788
|
let table_f = stream['stream_prefix'] ? stream['stream_prefix'] + stream['stream_slug'] : stream['stream_slug'];
|
|
763
789
|
yield (0, db_1.remove)(this.ref, `${table}_${table_f}`, { where: { row_id: id } });
|
|
@@ -912,7 +938,14 @@ class StreamUtil {
|
|
|
912
938
|
}
|
|
913
939
|
upsertBySlug(slug, namespace, index, { ref = "", req = {}, parent_slug = "", input = {}, tags = [], group = undefined } = {}) {
|
|
914
940
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
915
|
-
let fields = yield this.getBuilder(slug, namespace, { index: "fields" })
|
|
941
|
+
let fields = yield this.getBuilder(slug, namespace, { index: "fields" });
|
|
942
|
+
return yield this.upsertBySlugField(fields, index, { ref, req, parent_slug, input, tags, group });
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
upsertBySlugField(fields, index, { ref = "", req = {}, parent_slug = "", input = {}, tags = [], group = undefined } = {}) {
|
|
946
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
947
|
+
fields = fields || [];
|
|
948
|
+
let where_folder = {};
|
|
916
949
|
ref = ref || this.ref;
|
|
917
950
|
let files = (req.file ? [req.file] : (req.files || [])).reduce((total, item) => Object.assign(total, { [item['fieldname']]: item }), {});
|
|
918
951
|
let id_files = {}, fileUtil = new file_2.FileUtil(ref, this.option);
|
|
@@ -1636,8 +1669,10 @@ class StreamUtil {
|
|
|
1636
1669
|
}
|
|
1637
1670
|
}
|
|
1638
1671
|
}
|
|
1639
|
-
|
|
1640
|
-
|
|
1672
|
+
if (typeof field['sort_order'] == "undefined") {
|
|
1673
|
+
let sort_order = yield field_1.FieldModel.schema(this.ref, "_").max('sort_order', { where: { stream_id: stream['id'] } });
|
|
1674
|
+
field['sort_order'] = sort_order ? Number(sort_order + 1) : 1;
|
|
1675
|
+
}
|
|
1641
1676
|
if (!field['stream_id']) {
|
|
1642
1677
|
field['stream_id'] = stream['id'];
|
|
1643
1678
|
}
|
|
@@ -1897,11 +1932,13 @@ class StreamUtil {
|
|
|
1897
1932
|
allow_type = new RegExp(/^(image.*)$/).test(file[field_slug]['mimetype']);
|
|
1898
1933
|
if (!allow_type) {
|
|
1899
1934
|
input[field_slug] = mime.extension(file[field_slug]['mimetype']);
|
|
1935
|
+
input[field_slug] = input[field_slug] ? input[field_slug] : String(file[field_slug]['mimetype']).split('/')[1];
|
|
1900
1936
|
field = Joi.string().valid('image/*');
|
|
1901
1937
|
}
|
|
1902
1938
|
}
|
|
1903
1939
|
if (!allow_type && field_data['allowed_types']) {
|
|
1904
1940
|
let extension = String(mime.extension(file[field_slug]['mimetype']));
|
|
1941
|
+
extension = extension ? extension : String(file[field_slug]['mimetype']).split('/')[1];
|
|
1905
1942
|
if (!new RegExp(`^(${field_data['allowed_types']})$`).test(extension)) {
|
|
1906
1943
|
input[field_slug] = extension;
|
|
1907
1944
|
field = Joi.string().valid(...(field_data['allowed_types'].split('|') || []));
|
package/utils/user.d.ts
CHANGED
|
@@ -40,9 +40,9 @@ export declare const convertAddress: (data: any, { lang_code, transform }?: {
|
|
|
40
40
|
lang_code?: string;
|
|
41
41
|
transform?: boolean;
|
|
42
42
|
}) => Promise<any>;
|
|
43
|
-
export declare const getAddressIndex: (data: any, { condition,
|
|
43
|
+
export declare const getAddressIndex: (data: any, { condition, where }?: {
|
|
44
44
|
condition?: {};
|
|
45
|
-
|
|
45
|
+
where?: {};
|
|
46
46
|
}) => Promise<{}>;
|
|
47
47
|
export declare const getCountry: (ref: string, { organ_id, lang_code, setting }?: {
|
|
48
48
|
organ_id?: string;
|
package/utils/user.js
CHANGED
|
@@ -229,12 +229,11 @@ const convertAddress = (data, { lang_code = "en", transform = false } = {}) => t
|
|
|
229
229
|
return data;
|
|
230
230
|
});
|
|
231
231
|
exports.convertAddress = convertAddress;
|
|
232
|
-
const getAddressIndex = (data, { condition = {},
|
|
233
|
-
let result = {},
|
|
234
|
-
let order = [sequelize.literal(`FIELD(lang_code,${'\'' + where['lang_code'].join('\',\'') + '\''})`)];
|
|
232
|
+
const getAddressIndex = (data, { condition = {}, where = {} } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
233
|
+
let result = {}, bol = false;
|
|
235
234
|
if (!bol && data['country'] && !condition['country_id']) {
|
|
236
235
|
let country = yield country_1.CountryModel.schema("core", "_").findOne({
|
|
237
|
-
raw: true, where: Object.assign(Object.assign({}, where), { country_name: data['country'] }), attributes: ['id']
|
|
236
|
+
raw: true, where: Object.assign(Object.assign({}, where), { country_name: data['country'] }), attributes: ['id']
|
|
238
237
|
});
|
|
239
238
|
if (country) {
|
|
240
239
|
result['country_id'] = country['id'];
|
|
@@ -245,7 +244,7 @@ const getAddressIndex = (data, { condition = {}, lang_code = "en" } = {}) => tsl
|
|
|
245
244
|
if (!bol && data['state'] && !condition['state_id']) {
|
|
246
245
|
let country_id = condition['country_id'] || null;
|
|
247
246
|
let state = yield state_1.StateModel.schema("core", "_").findOne({
|
|
248
|
-
raw: true, where: Object.assign(Object.assign({}, where), { country_id, state_name: data['state'] }), attributes: ['id']
|
|
247
|
+
raw: true, where: Object.assign(Object.assign({}, where), { country_id, state_name: data['state'] }), attributes: ['id']
|
|
249
248
|
});
|
|
250
249
|
if (state) {
|
|
251
250
|
result['state_id'] = state['id'];
|
|
@@ -256,7 +255,7 @@ const getAddressIndex = (data, { condition = {}, lang_code = "en" } = {}) => tsl
|
|
|
256
255
|
if (!bol && data['city'] && !condition['city_id']) {
|
|
257
256
|
let state_id = condition['state_id'] || null;
|
|
258
257
|
let city = yield city_1.CityModel.schema("core", "_").findOne({
|
|
259
|
-
raw: true, where: Object.assign(Object.assign({}, where), { state_id, city_name: data['city'] }), attributes: ['id']
|
|
258
|
+
raw: true, where: Object.assign(Object.assign({}, where), { state_id, city_name: data['city'] }), attributes: ['id']
|
|
260
259
|
});
|
|
261
260
|
if (city) {
|
|
262
261
|
result['city_id'] = city['id'];
|
|
@@ -267,7 +266,7 @@ const getAddressIndex = (data, { condition = {}, lang_code = "en" } = {}) => tsl
|
|
|
267
266
|
if (!bol && data['district']) {
|
|
268
267
|
let city_id = condition['city_id'] || null;
|
|
269
268
|
let district = yield district_1.DistrictModel.schema("core", "_").findOne({
|
|
270
|
-
raw: true, where: Object.assign(Object.assign({}, where), { city_id, district_name: data['district'] }), attributes: ['id']
|
|
269
|
+
raw: true, where: Object.assign(Object.assign({}, where), { city_id, district_name: data['district'] }), attributes: ['id']
|
|
271
270
|
});
|
|
272
271
|
if (district)
|
|
273
272
|
result['district_id'] = district['id'];
|
|
@@ -277,7 +276,14 @@ const getAddressIndex = (data, { condition = {}, lang_code = "en" } = {}) => tsl
|
|
|
277
276
|
exports.getAddressIndex = getAddressIndex;
|
|
278
277
|
const getCountry = (ref, { organ_id = "", lang_code = "en", setting = {} } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
279
278
|
let where = { status: 1, lang_code }, default_country;
|
|
280
|
-
if (
|
|
279
|
+
if (organ_id) {
|
|
280
|
+
let query = yield organ_1.UserOrganModel.schema(ref, "_").findOne({ where: { id: organ_id }, attributes: ['setting'], raw: true });
|
|
281
|
+
setting = query ? (query['setting'] || {}) : {};
|
|
282
|
+
}
|
|
283
|
+
if (setting['mobile_code']) {
|
|
284
|
+
where['mobilecode'] = setting['mobile_code'].split(",");
|
|
285
|
+
}
|
|
286
|
+
else if (setting['country_id']) {
|
|
281
287
|
where['id'] = setting['country_id'].split(",");
|
|
282
288
|
}
|
|
283
289
|
let data = yield country_1.CountryModel.schema("core", "_").findAll({
|
|
@@ -311,9 +317,12 @@ const getGroupSetting = (ref, id, { attributes = ['id', 'shared', 'setting'] } =
|
|
|
311
317
|
exports.getGroupSetting = getGroupSetting;
|
|
312
318
|
const getGroupPermission = (ref, id, module, { permission = {}, group_shared = undefined, organ_id = 0, attributes = ['id', 'shared', 'setting'] } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
313
319
|
if (typeof group_shared == "undefined") {
|
|
314
|
-
let
|
|
315
|
-
if (
|
|
316
|
-
|
|
320
|
+
let group = yield (0, exports.getGroupSetting)(ref, id, { attributes });
|
|
321
|
+
if (group) {
|
|
322
|
+
permission['group_setting'] = group['setting'] || {};
|
|
323
|
+
permission['admin'] = group['shared'];
|
|
324
|
+
group_shared = group['shared'];
|
|
325
|
+
}
|
|
317
326
|
}
|
|
318
327
|
if (typeof group_shared != "undefined" && group_shared == 0) {
|
|
319
328
|
let query = yield group_permission_1.UserGroupPermissionModel.schema(ref, "_").findOne({
|
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");
|
|
@@ -105,7 +105,7 @@ const fileService = (setup, { userfiles = false, required = false, fileSize = 0,
|
|
|
105
105
|
let option = setup(validate);
|
|
106
106
|
let upload = userfiles ? option.array("userfiles", maxCount) : option.any();
|
|
107
107
|
return upload(req, res, (err) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
-
return (0, exports.validateService)(Joi.object().keys({ tags: Joi.array().allow('', null).items(Joi.object().keys({ slug: Joi.string(), type: Joi.string() })) }).unknown())(req, res, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
+
return (0, exports.validateService)(Joi.object().keys({ tags: Joi.array().allow('', null).items(Joi.object().keys({ slug: Joi.string(), type: Joi.string() })) }).unknown(), { field_omit: [] })(req, res, () => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
109
109
|
try {
|
|
110
110
|
let field = userfiles ? "userfiles" : undefined;
|
|
111
111
|
if (err) {
|
|
@@ -180,7 +180,7 @@ const multiService = ({ field = undefined, record = undefined, record_addition =
|
|
|
180
180
|
schema['field'] = Joi.string().valid(...field);
|
|
181
181
|
schema['value'] = value_schema;
|
|
182
182
|
}
|
|
183
|
-
return (0, exports.validateService)(Joi.object().keys(Object.assign(Object.assign({}, schema), { records: Joi.array().items(Joi.object().keys(Object.assign({ id: Joi.number().required() }, record)).options({ stripUnknown: true })).min(1).required() })).options({ stripUnknown: true }));
|
|
183
|
+
return (0, exports.validateService)(Joi.object().keys(Object.assign(Object.assign({}, schema), { records: Joi.array().items(Joi.object().keys(Object.assign({ id: Joi.number().required() }, record)).options({ stripUnknown: true })).min(1).required() })).options({ stripUnknown: true }), { field_omit: [] });
|
|
184
184
|
};
|
|
185
185
|
exports.multiService = multiService;
|
|
186
186
|
const streamService = ({ slug = "", name_space = "", param = "index" } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -207,7 +207,7 @@ const streamService = ({ slug = "", name_space = "", param = "index" } = {}) =>
|
|
|
207
207
|
});
|
|
208
208
|
exports.streamService = streamService;
|
|
209
209
|
const importService = ({ import_type = [], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
210
|
-
return (0, exports.validateService)(Joi.object().keys(Object.assign({ import_type: Joi.string().valid(...import_type) }, schema)).unknown())(req, res, next);
|
|
210
|
+
return (0, exports.validateService)(Joi.object().keys(Object.assign({ import_type: Joi.string().valid(...import_type) }, schema)).unknown(), { field_omit: [] })(req, res, next);
|
|
211
211
|
});
|
|
212
212
|
exports.importService = importService;
|
|
213
213
|
const exportService = ({ file_type = undefined, export_type = [], limit = 200, schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -240,8 +240,9 @@ const exportService = ({ file_type = undefined, export_type = [], limit = 200, s
|
|
|
240
240
|
});
|
|
241
241
|
exports.exportService = exportService;
|
|
242
242
|
const printService = ({ print_type = [], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
243
|
+
let config = res.locals.config || {};
|
|
243
244
|
if (req.query.ids) {
|
|
244
|
-
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { ids: String(req.query.ids).split(',') });
|
|
245
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { ids: String(req.query.ids).split(',').slice(0, (config['maxQueryIds'] || 25)) });
|
|
245
246
|
}
|
|
246
247
|
if (print_type && !req.query.print_type) {
|
|
247
248
|
req.query.print_type = print_type[0];
|
|
@@ -261,8 +262,9 @@ const printService = ({ print_type = [], schema = {} } = {}) => (req, res, next)
|
|
|
261
262
|
});
|
|
262
263
|
exports.printService = printService;
|
|
263
264
|
const dataService = ({ schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
265
|
+
let config = res.locals.config || {};
|
|
264
266
|
if (req.query.ids) {
|
|
265
|
-
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { ids: String(req.query.ids).split(',') });
|
|
267
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { ids: String(req.query.ids).split(',').slice(0, (config['maxQueryIds'] || 25)) });
|
|
266
268
|
}
|
|
267
269
|
let option = Object.keys(schema || {});
|
|
268
270
|
if (option.length) {
|
|
@@ -288,9 +290,23 @@ const fieldService = ({ field = [], schema = {} } = {}) => (req, res, next) => t
|
|
|
288
290
|
});
|
|
289
291
|
exports.fieldService = fieldService;
|
|
290
292
|
const convertService = ({ convert_type = [], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
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);
|
|
293
|
+
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(), { field_omit: [] })(req, res, next);
|
|
292
294
|
});
|
|
293
295
|
exports.convertService = convertService;
|
|
296
|
+
const entryValidateService = ({ module = ['contact'], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
297
|
+
return (0, exports.validateService)(Joi.object().keys(Object.assign({ module: Joi.string().valid(...module), entry_id: Joi.number().required() }, schema)).unknown(), { field_omit: [] })(req, res, next);
|
|
298
|
+
});
|
|
299
|
+
exports.entryValidateService = entryValidateService;
|
|
300
|
+
const entryParamService = ({ module = ['contact'], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
301
|
+
if (req.query.module) {
|
|
302
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { module: req.query.module });
|
|
303
|
+
}
|
|
304
|
+
if (req.query.entry_id) {
|
|
305
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { entry_id: req.query.entry_id });
|
|
306
|
+
}
|
|
307
|
+
return (0, exports.paramService)(Joi.object().keys(Object.assign({ module: Joi.string().valid(...module), entry_id: Joi.number().required() }, schema)).unknown())(req, res, next);
|
|
308
|
+
});
|
|
309
|
+
exports.entryParamService = entryParamService;
|
|
294
310
|
exports.createdByValidate = (0, exports.validateService)(Joi.object().keys({
|
|
295
311
|
created_by: Joi.alternatives().try(Joi.string(), Joi.number()).required()
|
|
296
312
|
}).unknown());
|