@digione/node-custom-api 0.0.1
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/constants/header.d.ts +10 -0
- package/constants/header.js +2 -0
- package/constants/http.d.ts +44 -0
- package/constants/http.js +2 -0
- package/database/index.d.ts +3 -0
- package/database/index.js +34 -0
- package/database/redis.d.ts +15 -0
- package/database/redis.js +68 -0
- package/errors/authError.d.ts +55 -0
- package/errors/authError.js +57 -0
- package/errors/index.d.ts +32 -0
- package/errors/index.js +113 -0
- package/index.d.ts +1 -0
- package/index.js +4 -0
- package/interface/param.d.ts +41 -0
- package/interface/param.js +2 -0
- package/middlewares/accessToken.d.ts +13 -0
- package/middlewares/accessToken.js +200 -0
- package/middlewares/coreSite.d.ts +4 -0
- package/middlewares/coreSite.js +52 -0
- package/middlewares/paramQuery.d.ts +16 -0
- package/middlewares/paramQuery.js +220 -0
- package/middlewares/refSite.d.ts +2 -0
- package/middlewares/refSite.js +58 -0
- package/middlewares/refreshToken.d.ts +2 -0
- package/middlewares/refreshToken.js +56 -0
- package/middlewares/systemSite.d.ts +6 -0
- package/middlewares/systemSite.js +106 -0
- package/middlewares/webSite.d.ts +7 -0
- package/middlewares/webSite.js +109 -0
- package/models/core/city.d.ts +66 -0
- package/models/core/city.js +79 -0
- package/models/core/country.d.ts +35 -0
- package/models/core/country.js +44 -0
- package/models/core/district.d.ts +17 -0
- package/models/core/district.js +23 -0
- package/models/core/domain.d.ts +57 -0
- package/models/core/domain.js +75 -0
- package/models/core/site.d.ts +60 -0
- package/models/core/site.js +70 -0
- package/models/core/state.d.ts +49 -0
- package/models/core/state.js +58 -0
- package/models/core/zipcode.d.ts +5 -0
- package/models/core/zipcode.js +28 -0
- package/models/stream/field.d.ts +60 -0
- package/models/stream/field.js +66 -0
- package/models/stream/field_section.d.ts +33 -0
- package/models/stream/field_section.js +39 -0
- package/models/stream/stream.d.ts +89 -0
- package/models/stream/stream.js +97 -0
- package/models/system/currency.d.ts +5 -0
- package/models/system/currency.js +32 -0
- package/models/system/email_log.d.ts +5 -0
- package/models/system/email_log.js +54 -0
- package/models/system/email_sender.d.ts +22 -0
- package/models/system/email_sender.js +53 -0
- package/models/system/email_template.d.ts +5 -0
- package/models/system/email_template.js +49 -0
- package/models/system/file.d.ts +98 -0
- package/models/system/file.js +111 -0
- package/models/system/folder.d.ts +59 -0
- package/models/system/folder.js +78 -0
- package/models/system/language.d.ts +44 -0
- package/models/system/language.js +50 -0
- package/models/system/metadata.d.ts +5 -0
- package/models/system/metadata.js +24 -0
- package/models/system/module.d.ts +5 -0
- package/models/system/module.js +35 -0
- package/models/system/notification_log.d.ts +25 -0
- package/models/system/notification_log.js +76 -0
- package/models/system/notification_module.d.ts +5 -0
- package/models/system/notification_module.js +35 -0
- package/models/system/notification_setting.d.ts +22 -0
- package/models/system/notification_setting.js +44 -0
- package/models/system/notification_template.d.ts +5 -0
- package/models/system/notification_template.js +49 -0
- package/models/system/notification_type.d.ts +5 -0
- package/models/system/notification_type.js +38 -0
- package/models/system/payment_transaction.d.ts +5 -0
- package/models/system/payment_transaction.js +46 -0
- package/models/system/pdf_page.d.ts +5 -0
- package/models/system/pdf_page.js +39 -0
- package/models/system/pdf_template.d.ts +22 -0
- package/models/system/pdf_template.js +67 -0
- package/models/system/review_template.d.ts +5 -0
- package/models/system/review_template.js +35 -0
- package/models/system/review_vote.d.ts +5 -0
- package/models/system/review_vote.js +36 -0
- package/models/system/session.d.ts +5 -0
- package/models/system/session.js +19 -0
- package/models/system/setting.d.ts +15 -0
- package/models/system/setting.js +22 -0
- package/models/system/site_token.d.ts +25 -0
- package/models/system/site_token.js +31 -0
- package/models/system/sms_log.d.ts +4 -0
- package/models/system/sms_log.js +52 -0
- package/models/system/sms_setting.d.ts +4 -0
- package/models/system/sms_setting.js +39 -0
- package/models/system/sms_template.d.ts +5 -0
- package/models/system/sms_template.js +48 -0
- package/models/system/tax.d.ts +5 -0
- package/models/system/tax.js +33 -0
- package/models/system/website.d.ts +56 -0
- package/models/system/website.js +66 -0
- package/models/system/zone.d.ts +57 -0
- package/models/system/zone.js +141 -0
- package/models/user/access_token.d.ts +37 -0
- package/models/user/access_token.js +46 -0
- package/models/user/address.d.ts +69 -0
- package/models/user/address.js +119 -0
- package/models/user/b2b_group.d.ts +57 -0
- package/models/user/b2b_group.js +63 -0
- package/models/user/group.d.ts +28 -0
- package/models/user/group.js +34 -0
- package/models/user/group_permission.d.ts +4 -0
- package/models/user/group_permission.js +27 -0
- package/models/user/notification_token.d.ts +32 -0
- package/models/user/notification_token.js +39 -0
- package/models/user/organ.d.ts +85 -0
- package/models/user/organ.js +100 -0
- package/models/user/profile.d.ts +31 -0
- package/models/user/profile.js +37 -0
- package/models/user/refresh_token.d.ts +41 -0
- package/models/user/refresh_token.js +51 -0
- package/models/user/team.d.ts +59 -0
- package/models/user/team.js +71 -0
- package/models/user/user.d.ts +79 -0
- package/models/user/user.js +100 -0
- package/models/user/user_organ.d.ts +52 -0
- package/models/user/user_organ.js +87 -0
- package/package.json +59 -0
- package/utils/auth.d.ts +25 -0
- package/utils/auth.js +137 -0
- package/utils/config.d.ts +8 -0
- package/utils/config.js +6 -0
- package/utils/core.d.ts +6 -0
- package/utils/core.js +39 -0
- package/utils/currency.d.ts +16 -0
- package/utils/currency.js +38 -0
- package/utils/db.d.ts +94 -0
- package/utils/db.js +399 -0
- package/utils/file.d.ts +232 -0
- package/utils/file.js +772 -0
- package/utils/helper.d.ts +113 -0
- package/utils/helper.js +508 -0
- package/utils/index.d.ts +10 -0
- package/utils/index.js +13 -0
- package/utils/language.d.ts +18 -0
- package/utils/language.js +48 -0
- package/utils/metadata.d.ts +18 -0
- package/utils/metadata.js +50 -0
- package/utils/session.d.ts +37 -0
- package/utils/session.js +60 -0
- package/utils/setting.d.ts +14 -0
- package/utils/setting.js +70 -0
- package/utils/stream.d.ts +303 -0
- package/utils/stream.js +1893 -0
- package/utils/user.d.ts +61 -0
- package/utils/user.js +282 -0
- package/utils/validator.d.ts +56 -0
- package/utils/validator.js +269 -0
package/utils/user.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as sequelize from "sequelize";
|
|
2
|
+
export declare const getUser: (ref: string, index: any, { attributes, attributes_profile, profile, stream_field }?: {
|
|
3
|
+
attributes?: string[];
|
|
4
|
+
attributes_profile?: string[];
|
|
5
|
+
profile?: boolean;
|
|
6
|
+
stream_field?: any[];
|
|
7
|
+
}) => Promise<sequelize.Model<any, any>>;
|
|
8
|
+
export declare const getOrganMemberId: (ref: string, organ_id: any) => Promise<{
|
|
9
|
+
member_id: number;
|
|
10
|
+
setting_user: any;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const createOrgan: (ref: string, input: any, { organ_id, attributes }?: {
|
|
13
|
+
organ_id?: any;
|
|
14
|
+
attributes?: string[];
|
|
15
|
+
}) => Promise<{
|
|
16
|
+
[x: string]: any;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const upsertProfile: (ref: string, user_id: any, input: any, { attributes }?: {
|
|
19
|
+
attributes?: any[];
|
|
20
|
+
}) => Promise<void>;
|
|
21
|
+
export declare const createUser: (ref: string, input: any, { organ_id, provider, type, attributes, attributes_organ, attributes_profile }?: {
|
|
22
|
+
organ_id?: string;
|
|
23
|
+
provider?: string;
|
|
24
|
+
type?: string;
|
|
25
|
+
attributes?: any[];
|
|
26
|
+
attributes_organ?: any;
|
|
27
|
+
attributes_profile?: any[];
|
|
28
|
+
}) => Promise<{
|
|
29
|
+
success: number;
|
|
30
|
+
id: any;
|
|
31
|
+
organ_id: any;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const getUserInOrgan: (ref: string, { where, organ_id, attributes, parent }?: {
|
|
34
|
+
where?: {};
|
|
35
|
+
organ_id?: string;
|
|
36
|
+
attributes?: string[];
|
|
37
|
+
parent?: boolean;
|
|
38
|
+
}) => Promise<sequelize.Model<any, any>>;
|
|
39
|
+
export declare const convertAddress: (data: any, { lang_code }?: {
|
|
40
|
+
lang_code?: string;
|
|
41
|
+
}) => Promise<any>;
|
|
42
|
+
export declare const getCountry: (ref: string, { organ_id, lang_code, setting }?: {
|
|
43
|
+
organ_id?: string;
|
|
44
|
+
lang_code?: string;
|
|
45
|
+
setting?: {};
|
|
46
|
+
}) => Promise<{
|
|
47
|
+
data: sequelize.Model<any, any>[];
|
|
48
|
+
default_country: any;
|
|
49
|
+
}>;
|
|
50
|
+
export declare const getGroupSetting: (ref: string, id: any, { attributes }?: {
|
|
51
|
+
attributes?: string[];
|
|
52
|
+
}) => Promise<any>;
|
|
53
|
+
export declare const getGroupPermission: (ref: string, id: any, module: string, { permission, group_shared, organ_id, attributes }?: {
|
|
54
|
+
permission?: {};
|
|
55
|
+
group_shared?: any;
|
|
56
|
+
organ_id?: number;
|
|
57
|
+
attributes?: string[];
|
|
58
|
+
}) => Promise<{}>;
|
|
59
|
+
export declare const getB2bSetting: (ref: string, id: any, { attributes }?: {
|
|
60
|
+
attributes?: string[];
|
|
61
|
+
}) => Promise<any>;
|
package/utils/user.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getB2bSetting = exports.getGroupPermission = exports.getGroupSetting = exports.getCountry = exports.convertAddress = exports.getUserInOrgan = exports.createUser = exports.upsertProfile = exports.createOrgan = exports.getOrganMemberId = exports.getUser = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const user_1 = require("../models/user/user");
|
|
6
|
+
const organ_1 = require("../models/user/organ");
|
|
7
|
+
const profile_1 = require("../models/user/profile");
|
|
8
|
+
const group_1 = require("../models/user/group");
|
|
9
|
+
const group_permission_1 = require("../models/user/group_permission");
|
|
10
|
+
const b2b_group_1 = require("../models/user/b2b_group");
|
|
11
|
+
const country_1 = require("../models/core/country");
|
|
12
|
+
const city_1 = require("../models/core/city");
|
|
13
|
+
const state_1 = require("../models/core/state");
|
|
14
|
+
const district_1 = require("../models/core/district");
|
|
15
|
+
const stream_1 = require("./stream");
|
|
16
|
+
const helper_1 = require("./helper");
|
|
17
|
+
const redis_1 = require("../database/redis");
|
|
18
|
+
const db_1 = require("./db");
|
|
19
|
+
const errors_1 = require("../errors");
|
|
20
|
+
const sequelize = require("sequelize");
|
|
21
|
+
const _ = require("lodash");
|
|
22
|
+
const sequelize_1 = require("sequelize");
|
|
23
|
+
const sha1 = require('js-sha1');
|
|
24
|
+
const getUser = (ref, index, { attributes = ['id', 'email', 'username', 'group_id'], attributes_profile = ['first_name', 'last_name', 'display_name'], profile = true, stream_field = [] } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
let include = [];
|
|
26
|
+
if (profile) {
|
|
27
|
+
if (stream_field.length)
|
|
28
|
+
attributes_profile = attributes_profile.concat(['id']);
|
|
29
|
+
include.push(yield user_1.UserAssociation.profile.join(ref, { attributes: attributes_profile }));
|
|
30
|
+
}
|
|
31
|
+
let query = yield user_1.UserModel.schema(ref, "_").findOne({
|
|
32
|
+
attributes,
|
|
33
|
+
where: { id: index },
|
|
34
|
+
include
|
|
35
|
+
});
|
|
36
|
+
if (query) {
|
|
37
|
+
let item = query.toJSON();
|
|
38
|
+
if (item['parent'] && !item['email']) {
|
|
39
|
+
let parent = yield user_1.UserModel.schema(ref, "_").findOne({ where: { id: item['parent'] }, raw: true, attributes: ['email'] });
|
|
40
|
+
if (parent)
|
|
41
|
+
item['email'] = parent['email'];
|
|
42
|
+
}
|
|
43
|
+
if (stream_field.length && item['profile'] && item['profile']['id']) {
|
|
44
|
+
let query = yield (new stream_1.StreamUtil(ref).getStreamFile('profiles', 'users', {
|
|
45
|
+
where: { id: item['profile']['id'] }, field_slug: stream_field, img_kit: true
|
|
46
|
+
}));
|
|
47
|
+
if (query && query[0])
|
|
48
|
+
item['profile'] = Object.assign(Object.assign({}, item['profile']), query[0]);
|
|
49
|
+
delete item['profile']['id'];
|
|
50
|
+
}
|
|
51
|
+
let user = _.omit(item, ['profile']);
|
|
52
|
+
query = Object.assign(Object.assign({}, user), item['profile']);
|
|
53
|
+
}
|
|
54
|
+
return query;
|
|
55
|
+
});
|
|
56
|
+
exports.getUser = getUser;
|
|
57
|
+
const getOrganMemberId = (ref, organ_id) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
+
let query = yield organ_1.UserOrganModel.schema(ref, "_").findOne({ where: { id: organ_id }, attributes: ['setting_user'], raw: true });
|
|
59
|
+
let setting_user = query ? (query['setting_user'] || {}) : {};
|
|
60
|
+
let member_id = Number(setting_user['member_id'] || '99999');
|
|
61
|
+
return { member_id, setting_user };
|
|
62
|
+
});
|
|
63
|
+
exports.getOrganMemberId = getOrganMemberId;
|
|
64
|
+
const createOrgan = (ref, input, { organ_id = null, attributes = ['organ_name', 'organ_email', 'organ_phone', 'member_id'] } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
+
let organ = _.pick(input, attributes), username = "";
|
|
66
|
+
if (organ_id) {
|
|
67
|
+
username = organ_id + "_";
|
|
68
|
+
organ['parent_id'] = organ_id;
|
|
69
|
+
if (!organ['member_id']) {
|
|
70
|
+
let { member_id, setting_user } = yield (0, exports.getOrganMemberId)(ref, organ_id);
|
|
71
|
+
member_id += 1;
|
|
72
|
+
setting_user['member_id'] = member_id;
|
|
73
|
+
organ['member_id'] = member_id;
|
|
74
|
+
yield (0, db_1.update)(ref, organ_1.UserOrganModel.getTableName().toString(), { setting_user: JSON.stringify(setting_user) }, { where: { id: organ_id } });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
organ['created'] = (0, helper_1.getDateMysql)();
|
|
78
|
+
let res = yield (0, db_1.insert)(ref, organ_1.UserOrganModel.getTableName().toString(), organ);
|
|
79
|
+
username = Buffer.from(username + res['id']).toString('base64');
|
|
80
|
+
yield (0, db_1.update)(ref, organ_1.UserOrganModel.getTableName().toString(), { username }, { where: { id: res['id'] } });
|
|
81
|
+
return res;
|
|
82
|
+
});
|
|
83
|
+
exports.createOrgan = createOrgan;
|
|
84
|
+
const upsertProfile = (ref, user_id, input, { attributes = [] } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
+
let exist = yield profile_1.UserProfileModel.schema(ref, "_").count({ where: { user_id } });
|
|
86
|
+
if (attributes.length) {
|
|
87
|
+
input = _.pick(input, attributes);
|
|
88
|
+
}
|
|
89
|
+
if (exist) {
|
|
90
|
+
input['updated'] = (0, helper_1.getDateMysql)();
|
|
91
|
+
input['dob'] = input['dob'] ? input['dob'] : null;
|
|
92
|
+
yield (0, db_1.update)(ref, profile_1.UserProfileModel.getTableName().toString(), input, { where: { user_id } });
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
input['user_id'] = user_id;
|
|
96
|
+
input['created'] = (0, helper_1.getDateMysql)();
|
|
97
|
+
input['dob'] = input['dob'] ? input['dob'] : null;
|
|
98
|
+
yield (0, db_1.insert)(ref, profile_1.UserProfileModel.getTableName().toString(), input);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
exports.upsertProfile = upsertProfile;
|
|
102
|
+
const createUser = (ref, input, { organ_id = "", provider = "email", type = "", attributes = [], attributes_organ = undefined, attributes_profile = [] } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
+
const field_join = ['profile', 'organ'];
|
|
104
|
+
let join = _.pick(input, field_join), new_organ, raw_password;
|
|
105
|
+
input = _.omit(input, field_join);
|
|
106
|
+
if (attributes.length) {
|
|
107
|
+
input = _.pick(input, attributes);
|
|
108
|
+
}
|
|
109
|
+
if (!input['password']) {
|
|
110
|
+
input['password'] = Math.random().toString(36).substring(9);
|
|
111
|
+
raw_password = input['password'];
|
|
112
|
+
}
|
|
113
|
+
input['salt'] = Math.random().toString(36).substring(7);
|
|
114
|
+
input['password'] = sha1(input['password'] + input['salt']);
|
|
115
|
+
let where = {};
|
|
116
|
+
if (organ_id) {
|
|
117
|
+
where[sequelize_1.Op.or] = [{ organ_id, organ_by: 0 }, { organ_id, organ_by: { [sequelize_1.Op.not]: 0 } }, { organ_by: organ_id }];
|
|
118
|
+
}
|
|
119
|
+
if (provider) {
|
|
120
|
+
where['provider'] = provider;
|
|
121
|
+
}
|
|
122
|
+
let exist = yield user_1.UserModel.schema(ref, "_").count({
|
|
123
|
+
where: Object.assign({ email: input['email'] }, where)
|
|
124
|
+
});
|
|
125
|
+
if (exist)
|
|
126
|
+
return Promise.reject(errors_1.generalError.EMAIL_DUPLICATE);
|
|
127
|
+
// create organ
|
|
128
|
+
if (!join['organ'])
|
|
129
|
+
join['organ'] = { organ_name: input['email'].split('@')[0] };
|
|
130
|
+
let organ = yield (0, exports.createOrgan)(ref, join['organ'], { organ_id, attributes: attributes_organ });
|
|
131
|
+
new_organ = organ['id'];
|
|
132
|
+
input['organ_id'] = new_organ;
|
|
133
|
+
if (input['email'] && !input['username']) {
|
|
134
|
+
input['username'] = input['email'].split('@')[0];
|
|
135
|
+
}
|
|
136
|
+
if (!input['active']) {
|
|
137
|
+
input['active'] = 0;
|
|
138
|
+
}
|
|
139
|
+
if (!input['group_id']) {
|
|
140
|
+
let group = yield group_1.UserGroupModel.schema(ref, "_").findOne({
|
|
141
|
+
where: { shared: 1 }, attributes: ['id'], raw: true
|
|
142
|
+
});
|
|
143
|
+
input['group_id'] = group ? group['id'] : 0;
|
|
144
|
+
}
|
|
145
|
+
if (provider) {
|
|
146
|
+
input['provider'] = provider;
|
|
147
|
+
}
|
|
148
|
+
input['organ_by'] = organ_id;
|
|
149
|
+
input['created_on'] = Number((0, helper_1.getDateTime)().format('X'));
|
|
150
|
+
input['last_login'] = 0;
|
|
151
|
+
let res = yield (0, db_1.insert)(ref, user_1.UserModel.getTableName().toString(), input);
|
|
152
|
+
if (join['profile']) {
|
|
153
|
+
yield (0, exports.upsertProfile)(ref, res['id'], join['profile'], { attributes: attributes_profile });
|
|
154
|
+
}
|
|
155
|
+
return { success: 1, id: res['id'], organ_id: new_organ };
|
|
156
|
+
});
|
|
157
|
+
exports.createUser = createUser;
|
|
158
|
+
const getUserInOrgan = (ref, { where = {}, organ_id = "", attributes = ['id', 'organ_id'], parent = true } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
159
|
+
let include = [];
|
|
160
|
+
if (parent && organ_id) {
|
|
161
|
+
include.push(yield organ_1.UserOrganAssociation.organ.join(ref, { attributes: [] }));
|
|
162
|
+
let or = { [sequelize_1.Op.or]: where[sequelize_1.Op.or] };
|
|
163
|
+
let organ = [{ organ_id }, sequelize.literal(`organ.parent_id = '${organ_id}'`)];
|
|
164
|
+
if (where[sequelize_1.Op.or]) {
|
|
165
|
+
delete where[sequelize_1.Op.or];
|
|
166
|
+
where[sequelize_1.Op.and] = [{ [sequelize_1.Op.or]: organ }].concat(or);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
where[sequelize_1.Op.or] = organ;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else if (organ_id) {
|
|
173
|
+
where['organ_id'] = organ_id;
|
|
174
|
+
}
|
|
175
|
+
return yield user_1.UserModel.schema(ref, "_").findOne({
|
|
176
|
+
where, attributes, raw: true, include
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
exports.getUserInOrgan = getUserInOrgan;
|
|
180
|
+
const convertAddress = (data, { lang_code = "en" } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
181
|
+
let where = { lang_code: [lang_code, "en"], status: '1' };
|
|
182
|
+
let order = [sequelize.literal(`FIELD(lang_code,${'\'' + where['lang_code'].join('\',\'') + '\''})`)];
|
|
183
|
+
if (data['country_id']) {
|
|
184
|
+
let country = yield country_1.CountryModel.schema("core", "_").findOne({
|
|
185
|
+
raw: true, where: Object.assign(Object.assign({}, where), { id: data['country_id'] }), attributes: ['country_name'], order
|
|
186
|
+
});
|
|
187
|
+
if (country)
|
|
188
|
+
data['country'] = country['country_name'];
|
|
189
|
+
}
|
|
190
|
+
if (data['state_id']) {
|
|
191
|
+
let state = yield state_1.StateModel.schema("core", "_").findOne({
|
|
192
|
+
raw: true, where: Object.assign(Object.assign({}, where), { id: data['state_id'] }), attributes: ['state_name'], order
|
|
193
|
+
});
|
|
194
|
+
if (state)
|
|
195
|
+
data['state'] = state['state_name'];
|
|
196
|
+
}
|
|
197
|
+
if (data['city_id']) {
|
|
198
|
+
let city = yield city_1.CityModel.schema("core", "_").findOne({
|
|
199
|
+
raw: true, where: Object.assign(Object.assign({}, where), { id: data['city_id'] }), attributes: ['city_name'], order
|
|
200
|
+
});
|
|
201
|
+
if (city)
|
|
202
|
+
data['city'] = city['city_name'];
|
|
203
|
+
}
|
|
204
|
+
if (data['district_id']) {
|
|
205
|
+
let district = yield district_1.DistrictModel.schema("core", "_").findOne({
|
|
206
|
+
raw: true, where: Object.assign(Object.assign({}, where), { id: data['district_id'] }), attributes: ['district_name'], order
|
|
207
|
+
});
|
|
208
|
+
if (district)
|
|
209
|
+
data['district'] = district['district_name'];
|
|
210
|
+
}
|
|
211
|
+
return data;
|
|
212
|
+
});
|
|
213
|
+
exports.convertAddress = convertAddress;
|
|
214
|
+
const getCountry = (ref, { organ_id = "", lang_code = "en", setting = {} } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
215
|
+
let where = { status: 1, lang_code }, default_country;
|
|
216
|
+
if (setting['country_id']) {
|
|
217
|
+
where['id'] = setting['country_id'].split(",");
|
|
218
|
+
}
|
|
219
|
+
let data = yield country_1.CountryModel.schema("core", "_").findAll({
|
|
220
|
+
where, attributes: [['id', 'country_id'], ['mobilecode', 'key'], ['country_name', 'value'], [sequelize.literal('LOWER(country_code)'), 'country_code']], raw: true
|
|
221
|
+
});
|
|
222
|
+
if (setting['default_country']) {
|
|
223
|
+
default_country = data.find(i => i['country_id'] == setting['default_country']);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
default_country = data[0];
|
|
227
|
+
}
|
|
228
|
+
return { data, default_country };
|
|
229
|
+
});
|
|
230
|
+
exports.getCountry = getCountry;
|
|
231
|
+
const getGroupSetting = (ref, id, { attributes = ['id', 'shared', 'setting'] } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
232
|
+
let index = ref.toLowerCase() + '_' + group_1.UserGroupModel.getTableName();
|
|
233
|
+
if (redis_1.redisReady) {
|
|
234
|
+
let setting = yield (0, redis_1.redisHMGet)(index + "_" + id, "setting");
|
|
235
|
+
if (setting && setting[0]) {
|
|
236
|
+
return JSON.parse(setting[0]);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
let data = yield group_1.UserGroupModel.schema(ref, "_").findOne({
|
|
240
|
+
raw: true, where: { id }, attributes
|
|
241
|
+
});
|
|
242
|
+
if (data && redis_1.redisReady) {
|
|
243
|
+
yield (0, redis_1.redisHSet)(index + "_" + id, "setting", JSON.stringify(data));
|
|
244
|
+
}
|
|
245
|
+
return data;
|
|
246
|
+
});
|
|
247
|
+
exports.getGroupSetting = getGroupSetting;
|
|
248
|
+
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* () {
|
|
249
|
+
if (typeof group_shared == "undefined") {
|
|
250
|
+
let setting = yield (0, exports.getGroupSetting)(ref, id, { attributes });
|
|
251
|
+
if (setting)
|
|
252
|
+
group_shared = setting['shared'];
|
|
253
|
+
}
|
|
254
|
+
if (typeof group_shared != "undefined" && group_shared == 0) {
|
|
255
|
+
let query = yield group_permission_1.UserGroupPermissionModel.schema(ref, "_").findOne({
|
|
256
|
+
where: { organ_id, group_id: id, module }, raw: true, attributes: ['roles']
|
|
257
|
+
});
|
|
258
|
+
if (query && query['roles']) {
|
|
259
|
+
let roles = String(query['roles'] || '').split(',').reduce((total, item) => item ? Object.assign(total, { [item]: true }) : total, {});
|
|
260
|
+
permission = Object.assign(Object.assign({}, permission), roles);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return permission;
|
|
264
|
+
});
|
|
265
|
+
exports.getGroupPermission = getGroupPermission;
|
|
266
|
+
const getB2bSetting = (ref, id, { attributes = ['id', 'discount', 'discount_type', 'credit_limit'] } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
267
|
+
let index = ref.toLowerCase() + '_' + b2b_group_1.B2bGroupModel.getTableName();
|
|
268
|
+
if (redis_1.redisReady) {
|
|
269
|
+
let setting = yield (0, redis_1.redisHMGet)(index + "_" + id, "setting");
|
|
270
|
+
if (setting && setting[0]) {
|
|
271
|
+
return JSON.parse(setting[0]);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
let data = yield b2b_group_1.B2bGroupModel.schema(ref, "_").findOne({
|
|
275
|
+
raw: true, where: { id }, attributes
|
|
276
|
+
});
|
|
277
|
+
if (data && redis_1.redisReady) {
|
|
278
|
+
yield (0, redis_1.redisHSet)(index + "_" + id, "setting", JSON.stringify(data));
|
|
279
|
+
}
|
|
280
|
+
return data;
|
|
281
|
+
});
|
|
282
|
+
exports.getB2bSetting = getB2bSetting;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as Joi from 'joi';
|
|
2
|
+
interface OptionFile {
|
|
3
|
+
userfiles?: boolean;
|
|
4
|
+
required?: boolean;
|
|
5
|
+
fileSize?: number;
|
|
6
|
+
fileTypes?: string;
|
|
7
|
+
maxCount?: number;
|
|
8
|
+
qualityImage?: number;
|
|
9
|
+
resizeImage?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const validate: (schema: Joi.AnySchema, body?: any, { arrayIndex, prefixMessage }?: {
|
|
12
|
+
arrayIndex?: boolean;
|
|
13
|
+
prefixMessage?: string;
|
|
14
|
+
}) => Promise<any>;
|
|
15
|
+
export declare const validateService: (schema: Joi.ObjectSchema, { organ_id, created_by, web_id, purgeUpdate }?: {
|
|
16
|
+
organ_id?: boolean;
|
|
17
|
+
created_by?: boolean;
|
|
18
|
+
web_id?: boolean;
|
|
19
|
+
purgeUpdate?: boolean;
|
|
20
|
+
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
21
|
+
export declare const paramService: (schema: Joi.AnySchema) => (req: any, res: any, next: any) => Promise<any>;
|
|
22
|
+
export declare const fileService: (setup: any, { userfiles, required, fileSize, fileTypes, maxCount, qualityImage, resizeImage }?: OptionFile) => (req: any, res: any, next: any) => any;
|
|
23
|
+
export declare const multiService: ({ field, record, record_addition, schema }?: {
|
|
24
|
+
field?: any;
|
|
25
|
+
record?: any;
|
|
26
|
+
record_addition?: any;
|
|
27
|
+
schema?: {};
|
|
28
|
+
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
29
|
+
export declare const streamService: ({ slug, name_space, param }?: {
|
|
30
|
+
slug?: string;
|
|
31
|
+
name_space?: string;
|
|
32
|
+
param?: string;
|
|
33
|
+
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
34
|
+
export declare const importService: ({ import_type, schema }?: {
|
|
35
|
+
import_type?: any[];
|
|
36
|
+
schema?: {};
|
|
37
|
+
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
38
|
+
export declare const exportService: ({ file_type, export_type, limit, schema }?: {
|
|
39
|
+
file_type?: any;
|
|
40
|
+
export_type?: any[];
|
|
41
|
+
limit?: number;
|
|
42
|
+
schema?: {};
|
|
43
|
+
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
44
|
+
export declare const printService: ({ print_type, schema }?: {
|
|
45
|
+
print_type?: any[];
|
|
46
|
+
schema?: {};
|
|
47
|
+
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
48
|
+
export declare const dataService: ({ schema }?: {
|
|
49
|
+
schema?: {};
|
|
50
|
+
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
51
|
+
export declare const fieldService: ({ field, schema }?: {
|
|
52
|
+
field?: any[];
|
|
53
|
+
schema?: {};
|
|
54
|
+
}) => (req: any, res: any, next: any) => Promise<any>;
|
|
55
|
+
export declare const createdByValidate: (req: any, res: any, next: any) => Promise<any>;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createdByValidate = 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
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Joi = require("joi");
|
|
6
|
+
const errors_1 = require("../errors");
|
|
7
|
+
const helper_1 = require("./helper");
|
|
8
|
+
const stream_1 = require("../models/stream/stream");
|
|
9
|
+
const file_1 = require("./file");
|
|
10
|
+
const jimp = require("jimp/dist");
|
|
11
|
+
const _ = require("lodash");
|
|
12
|
+
const validate = (schema, body = {}, { arrayIndex = false, prefixMessage = "" } = {}) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
const errors = {};
|
|
14
|
+
const result = schema.validate(body, { abortEarly: false });
|
|
15
|
+
if (result && result.error && result.error.details) {
|
|
16
|
+
result.error.details.forEach((v) => {
|
|
17
|
+
let message = v.message;
|
|
18
|
+
if (arrayIndex && v.path.length >= 2) {
|
|
19
|
+
let indexPath = v.path.length - 2, index;
|
|
20
|
+
if (/^\d+$/.test(String(v.path[indexPath]))) {
|
|
21
|
+
index = Number(v.path[indexPath]) + 1;
|
|
22
|
+
}
|
|
23
|
+
if (typeof index != "undefined") {
|
|
24
|
+
prefixMessage = (prefixMessage || "at row") + ` ${index} `;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
errors[`${v.path[0]}`] = {
|
|
28
|
+
code: `${v.path.join('.')}.${v.type}${v.context.limit ? `.${v.context.limit}` : ''}`,
|
|
29
|
+
message: `${prefixMessage}${message}`
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (!_.isEmpty(errors)) {
|
|
34
|
+
return Promise.reject({
|
|
35
|
+
code: 400 /* HTTP.BAD_REQUEST */,
|
|
36
|
+
message: 'INVALID_PARAMS',
|
|
37
|
+
fields: errors
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return result.value;
|
|
41
|
+
});
|
|
42
|
+
exports.validate = validate;
|
|
43
|
+
const validateService = (schema, { organ_id = true, created_by = true, web_id = true, purgeUpdate = true } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
if (created_by) {
|
|
45
|
+
const token = req.headers['authorization'] ? req.headers['authorization'].split(' ')[1] : null;
|
|
46
|
+
if (token && !res.locals.user_id) {
|
|
47
|
+
try {
|
|
48
|
+
const data = yield (0, helper_1.getTokenDataFromTokenBySecret)(token, (0, helper_1.getENV)('JWT_SECRET'));
|
|
49
|
+
if (data && data.id) {
|
|
50
|
+
req.body['created_by'] = data.id;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (err) { }
|
|
54
|
+
}
|
|
55
|
+
else if (res.locals.user_id) {
|
|
56
|
+
req.body['created_by'] = res.locals.user_id;
|
|
57
|
+
}
|
|
58
|
+
if (purgeUpdate && (req.method == "PUT" || req.method == "PATCH")) {
|
|
59
|
+
schema = schema.keys({ created_by: Joi.any() });
|
|
60
|
+
delete req.body['created_by'];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (organ_id && res.locals.organ_id) {
|
|
64
|
+
req.body['organ_id'] = res.locals.organ_id;
|
|
65
|
+
if (purgeUpdate && (req.method == "PUT" || req.method == "PATCH")) {
|
|
66
|
+
schema = schema.keys({ organ_id: Joi.any() });
|
|
67
|
+
delete req.body['organ_id'];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (web_id && res.locals.web_id) {
|
|
71
|
+
req.body['web_id'] = res.locals.web_id;
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
req.body = yield (0, exports.validate)(schema, req.body);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
let e = new errors_1.CustomError(err);
|
|
78
|
+
return res.status(e.code).send(e);
|
|
79
|
+
}
|
|
80
|
+
return next();
|
|
81
|
+
});
|
|
82
|
+
exports.validateService = validateService;
|
|
83
|
+
const paramService = (schema) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
try {
|
|
85
|
+
let data = Object.assign(Object.assign({}, req.query), req.params);
|
|
86
|
+
yield (0, exports.validate)(schema, data);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
let e = new errors_1.CustomError(err);
|
|
90
|
+
return res.status(e.code).send(e);
|
|
91
|
+
}
|
|
92
|
+
return next();
|
|
93
|
+
});
|
|
94
|
+
exports.paramService = paramService;
|
|
95
|
+
const fileService = (setup, { userfiles = false, required = false, fileSize = 0, fileTypes = "", maxCount = undefined, qualityImage = 0, resizeImage = 0 } = {}) => (req, res, next) => {
|
|
96
|
+
let validate = {}, size = 0;
|
|
97
|
+
fileSize = Number(fileSize || (0, helper_1.getENV)('LIMIT_FILE_SIZE', '0'));
|
|
98
|
+
if (fileSize) {
|
|
99
|
+
size = Math.floor(fileSize * 1024 * 1024);
|
|
100
|
+
validate["limits"] = { fileSize: size };
|
|
101
|
+
}
|
|
102
|
+
let option = setup(validate);
|
|
103
|
+
let upload = userfiles ? option.array("userfiles", maxCount) : option.any();
|
|
104
|
+
return upload(req, res, (err) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
+
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* () {
|
|
106
|
+
try {
|
|
107
|
+
let field = userfiles ? "userfiles" : undefined;
|
|
108
|
+
if (err) {
|
|
109
|
+
let code = err['code'];
|
|
110
|
+
let message = "upload file not working";
|
|
111
|
+
if (err['code'] == "LIMIT_FILE_SIZE") {
|
|
112
|
+
const unit = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
113
|
+
const i = Math.floor(Math.log(size) / Math.log(1024));
|
|
114
|
+
const filesize = parseFloat((size / Math.pow(1024, i)).toFixed(2));
|
|
115
|
+
message = `file size limit is ${filesize} ${unit[i]}`;
|
|
116
|
+
}
|
|
117
|
+
else if (err['code'] == "LIMIT_UNEXPECTED_FILE") {
|
|
118
|
+
message = `file max total is ${maxCount}`;
|
|
119
|
+
}
|
|
120
|
+
yield (0, errors_1.paramError)(message, { field, code });
|
|
121
|
+
}
|
|
122
|
+
if (required && (!req.files || !req.files.length)) {
|
|
123
|
+
yield (0, errors_1.paramError)(`${field || 'file'} is required`, { field });
|
|
124
|
+
}
|
|
125
|
+
if (req.files && (fileTypes || qualityImage || resizeImage)) {
|
|
126
|
+
const regxType = fileTypes ? new RegExp('\\b' + fileTypes + '\\b') : null;
|
|
127
|
+
const regxImage = (qualityImage || resizeImage) ? new RegExp('\\b' + 'jpeg|jpg|png|bmp' + '\\b') : null;
|
|
128
|
+
let errorType = false;
|
|
129
|
+
for (let file of req.files) {
|
|
130
|
+
if (regxType && !regxType.test(file.mimetype)) {
|
|
131
|
+
field = file['fieldname'];
|
|
132
|
+
errorType = true;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (regxImage && regxImage.test(file.mimetype)) {
|
|
136
|
+
try {
|
|
137
|
+
let image = yield jimp.read(file.buffer);
|
|
138
|
+
if (resizeImage && image.bitmap.width > resizeImage) {
|
|
139
|
+
image.resize(resizeImage, jimp.AUTO);
|
|
140
|
+
}
|
|
141
|
+
else if (qualityImage) {
|
|
142
|
+
image.resize((image.bitmap.width * (qualityImage / 100)), jimp.AUTO);
|
|
143
|
+
}
|
|
144
|
+
if (qualityImage)
|
|
145
|
+
image.quality(qualityImage);
|
|
146
|
+
let buffer = yield (0, file_1.getBuffer)(image, { mimetype: file.mimetype });
|
|
147
|
+
file.buffer = buffer;
|
|
148
|
+
file.size = buffer.toString().length;
|
|
149
|
+
}
|
|
150
|
+
catch (err) { }
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (errorType)
|
|
154
|
+
yield (0, errors_1.paramError)(`file require type ${fileTypes}`, { field, code: "FILE_TYPE_NOT_ALLOW" });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
let e = new errors_1.CustomError(err);
|
|
159
|
+
return res.status(e.code).send(e);
|
|
160
|
+
}
|
|
161
|
+
return next();
|
|
162
|
+
}));
|
|
163
|
+
}));
|
|
164
|
+
};
|
|
165
|
+
exports.fileService = fileService;
|
|
166
|
+
const multiService = ({ field = undefined, record = undefined, record_addition = undefined, schema = {} } = {}) => {
|
|
167
|
+
let value_schema = Joi.any().when('field', { is: Joi.exist(), then: Joi.required() });
|
|
168
|
+
let field_schema = (field || {});
|
|
169
|
+
record = record || Object.assign({ ordering_count: Joi.number().min(0) }, (record_addition || {}));
|
|
170
|
+
field = Object.keys(field_schema);
|
|
171
|
+
if (field.length) {
|
|
172
|
+
value_schema = Joi.any().when('field', {
|
|
173
|
+
switch: field.map((key) => {
|
|
174
|
+
return { is: key, then: field_schema[key].required() };
|
|
175
|
+
})
|
|
176
|
+
});
|
|
177
|
+
schema['field'] = Joi.string().valid(...field);
|
|
178
|
+
schema['value'] = value_schema;
|
|
179
|
+
}
|
|
180
|
+
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 }));
|
|
181
|
+
};
|
|
182
|
+
exports.multiService = multiService;
|
|
183
|
+
const streamService = ({ slug = "", name_space = "", param = "index" } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
184
|
+
try {
|
|
185
|
+
let ref = res.locals.ref, post_stream = (req.query[param] || '');
|
|
186
|
+
if (req.body)
|
|
187
|
+
post_stream = req.body[param] || post_stream;
|
|
188
|
+
let stream_slug = slug + post_stream;
|
|
189
|
+
let stream_namespace = name_space || stream_slug;
|
|
190
|
+
let query = yield stream_1.StreamModel.schema(ref, "_").findOne({
|
|
191
|
+
where: { stream_slug, stream_namespace }, attributes: ['id'], raw: true
|
|
192
|
+
});
|
|
193
|
+
if (query) {
|
|
194
|
+
let stream_id = query['id'];
|
|
195
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { stream_id });
|
|
196
|
+
if (req.body)
|
|
197
|
+
req.body['stream_id'] = stream_id;
|
|
198
|
+
return next();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (err) { }
|
|
202
|
+
let e = new errors_1.CustomError(errors_1.generalError.NOT_FOUND);
|
|
203
|
+
return res.status(e.code).send(e);
|
|
204
|
+
});
|
|
205
|
+
exports.streamService = streamService;
|
|
206
|
+
const importService = ({ import_type = [], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
207
|
+
return (0, exports.validateService)(Joi.object().keys(Object.assign({ import_type: Joi.string().valid(...import_type) }, schema)).unknown())(req, res, next);
|
|
208
|
+
});
|
|
209
|
+
exports.importService = importService;
|
|
210
|
+
const exportService = ({ file_type = undefined, export_type = [], limit = 200, schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
211
|
+
res.locals.option = (res.locals.option || {});
|
|
212
|
+
res.locals.option['limit'] = res.locals.option['limit'] || limit;
|
|
213
|
+
if (req.query.all_data) {
|
|
214
|
+
res.locals.option['all_data'] = req.query.all_data;
|
|
215
|
+
}
|
|
216
|
+
if (file_type) {
|
|
217
|
+
if (!req.query.file_type) {
|
|
218
|
+
req.query.file_type = file_type[0];
|
|
219
|
+
}
|
|
220
|
+
schema['file_type'] = Joi.string().valid(...file_type);
|
|
221
|
+
}
|
|
222
|
+
if (req.query.file_type) {
|
|
223
|
+
res.locals.option['file_type'] = req.query.file_type;
|
|
224
|
+
}
|
|
225
|
+
if (export_type && !req.query.export_type) {
|
|
226
|
+
req.query.export_type = export_type[0];
|
|
227
|
+
}
|
|
228
|
+
if (req.query.export_type) {
|
|
229
|
+
res.locals.option['export_type'] = req.query.export_type;
|
|
230
|
+
}
|
|
231
|
+
return (0, exports.paramService)(Joi.object().keys(Object.assign({ all_data: Joi.number().allow(null, ''), export_type: Joi.string().valid(...export_type), limit: Joi.number().max(limit) }, schema)).unknown())(req, res, next);
|
|
232
|
+
});
|
|
233
|
+
exports.exportService = exportService;
|
|
234
|
+
const printService = ({ print_type = [], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
235
|
+
if (req.query.ids) {
|
|
236
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { ids: String(req.query.ids).split(',') });
|
|
237
|
+
}
|
|
238
|
+
if (print_type && !req.query.print_type) {
|
|
239
|
+
req.query.print_type = print_type[0];
|
|
240
|
+
}
|
|
241
|
+
if (req.query.print_type) {
|
|
242
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { print_type: req.query.print_type });
|
|
243
|
+
}
|
|
244
|
+
if (req.query.preset) {
|
|
245
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { preset: req.query.preset });
|
|
246
|
+
}
|
|
247
|
+
return (0, exports.paramService)(Joi.object().keys(Object.assign({ ids: Joi.string().required(), print_type: Joi.string().valid(...print_type), preset: Joi.string() }, schema)).unknown())(req, res, next);
|
|
248
|
+
});
|
|
249
|
+
exports.printService = printService;
|
|
250
|
+
const dataService = ({ schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
251
|
+
if (req.query.ids) {
|
|
252
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { ids: String(req.query.ids).split(',') });
|
|
253
|
+
}
|
|
254
|
+
return (0, exports.paramService)(Joi.object().keys(Object.assign({ ids: Joi.string().required(), preset: Joi.string() }, schema)).unknown())(req, res, next);
|
|
255
|
+
});
|
|
256
|
+
exports.dataService = dataService;
|
|
257
|
+
const fieldService = ({ field = [], schema = {} } = {}) => (req, res, next) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
258
|
+
if (field && !req.query.field) {
|
|
259
|
+
req.query.field = field[0];
|
|
260
|
+
}
|
|
261
|
+
if (req.query.field) {
|
|
262
|
+
res.locals.option = Object.assign(Object.assign({}, (res.locals.option || {})), { field: req.query.field });
|
|
263
|
+
}
|
|
264
|
+
return (0, exports.paramService)(Joi.object().keys(Object.assign({ field: Joi.string().valid(...field) }, schema)).unknown())(req, res, next);
|
|
265
|
+
});
|
|
266
|
+
exports.fieldService = fieldService;
|
|
267
|
+
exports.createdByValidate = (0, exports.validateService)(Joi.object().keys({
|
|
268
|
+
created_by: Joi.alternatives().try(Joi.string(), Joi.number()).required()
|
|
269
|
+
}).unknown());
|