@xrystal/core 3.23.4 → 3.23.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -90,24 +90,19 @@ export default class Controller extends BaseController {
|
|
|
90
90
|
parseMessage(msg, t, isError = false) {
|
|
91
91
|
if (!msg)
|
|
92
92
|
return '';
|
|
93
|
-
|
|
94
|
-
return '';
|
|
95
|
-
let cleanMsg = msg;
|
|
93
|
+
let content = String(msg);
|
|
96
94
|
let useDirect = isError;
|
|
97
|
-
if (
|
|
98
|
-
|
|
95
|
+
if (content.startsWith('@')) {
|
|
96
|
+
content = content.substring(1);
|
|
99
97
|
useDirect = true;
|
|
100
98
|
}
|
|
101
|
-
const parts =
|
|
99
|
+
const parts = content.split(' ');
|
|
102
100
|
const key = parts[0];
|
|
103
|
-
const
|
|
104
|
-
const translatedParams = rawParams.map((p) => t(p));
|
|
101
|
+
const params = parts.slice(1).map(p => t(p));
|
|
105
102
|
if (useDirect) {
|
|
106
|
-
return t(key,
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
return responseMessageHelper.successFully(key, translatedParams.join(' '), t);
|
|
103
|
+
return t(key, params);
|
|
110
104
|
}
|
|
105
|
+
return responseMessageHelper.successfully(t(key), params.join(' '), t);
|
|
111
106
|
}
|
|
112
107
|
async schema({ checks, logic, response }) {
|
|
113
108
|
try {
|
|
@@ -125,13 +120,12 @@ export default class Controller extends BaseController {
|
|
|
125
120
|
if (checks) {
|
|
126
121
|
const checkResult = await checks(p);
|
|
127
122
|
if (checkResult !== true) {
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
return currentRes.status(checkCode).send(new ResponseSchema({
|
|
123
|
+
const code = checkResult?.code || 400;
|
|
124
|
+
const msg = checkResult?.message || (typeof checkResult === 'string' ? checkResult : 'error_validation');
|
|
125
|
+
return currentRes.status(code).send(new ResponseSchema({
|
|
132
126
|
status: false,
|
|
133
|
-
message:
|
|
134
|
-
code
|
|
127
|
+
message: this.parseMessage(msg, currentReq.t, true),
|
|
128
|
+
code
|
|
135
129
|
}).getResponse);
|
|
136
130
|
}
|
|
137
131
|
}
|
|
@@ -143,57 +137,56 @@ export default class Controller extends BaseController {
|
|
|
143
137
|
logicResult = await logicResult.response();
|
|
144
138
|
}
|
|
145
139
|
if (logicResult?.status === false) {
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
return currentRes.status(errorCode).send(new ResponseSchema({
|
|
140
|
+
const code = logicResult.code || 400;
|
|
141
|
+
return currentRes.status(code).send(new ResponseSchema({
|
|
149
142
|
status: false,
|
|
150
|
-
message:
|
|
151
|
-
code
|
|
143
|
+
message: this.parseMessage(logicResult.message || 'error_process', currentReq.t, true),
|
|
144
|
+
code
|
|
152
145
|
}).getResponse);
|
|
153
146
|
}
|
|
154
147
|
const resResult = response ? await response({ ...p, logicResult }) : logicResult;
|
|
155
148
|
if (resResult instanceof Response || resResult instanceof Blob || resResult instanceof Uint8Array || resResult instanceof ArrayBuffer) {
|
|
156
149
|
return currentRes.status(200).send(resResult);
|
|
157
150
|
}
|
|
158
|
-
let
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
let
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
151
|
+
let finalData = undefined;
|
|
152
|
+
let finalExtraData = undefined;
|
|
153
|
+
let messageSource = 'success_process';
|
|
154
|
+
let successCode = this.currentStore?.metadata?._code || 200;
|
|
155
|
+
const source = resResult !== undefined ? resResult : logicResult;
|
|
156
|
+
if (source !== null && typeof source === 'object') {
|
|
157
|
+
if (source.payload && typeof source.payload === 'object') {
|
|
158
|
+
finalData = source.payload.data !== undefined ? source.payload.data : source.payload;
|
|
159
|
+
finalExtraData = source.payload.extraData;
|
|
160
|
+
}
|
|
161
|
+
else if (source.data !== undefined || source.extraData !== undefined) {
|
|
162
|
+
finalData = source.data;
|
|
163
|
+
finalExtraData = source.extraData;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
const hasMetadata = source.status !== undefined || source.message !== undefined || source.code !== undefined;
|
|
167
|
+
if (!hasMetadata && Object.keys(source).length > 0) {
|
|
168
|
+
finalData = source;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (source.message)
|
|
172
|
+
messageSource = source.message;
|
|
173
|
+
if (source.code !== undefined)
|
|
174
|
+
successCode = source.code;
|
|
172
175
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (source.payload) {
|
|
176
|
-
if (source.payload.data !== undefined)
|
|
177
|
-
dataVal = source.payload.data;
|
|
178
|
-
else if (!source.payload.extraData && !source.data)
|
|
179
|
-
dataVal = source.payload;
|
|
180
|
-
if (source.payload.extraData !== undefined)
|
|
181
|
-
extraDataVal = source.payload.extraData;
|
|
176
|
+
else if (source !== undefined) {
|
|
177
|
+
messageSource = source;
|
|
182
178
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
179
|
+
let payload = undefined;
|
|
180
|
+
if (finalData !== undefined || finalExtraData !== undefined) {
|
|
181
|
+
payload = {
|
|
182
|
+
data: finalData ?? {},
|
|
183
|
+
extraData: finalExtraData ?? {}
|
|
184
|
+
};
|
|
187
185
|
}
|
|
188
|
-
const finalPayload = (dataVal !== undefined || extraDataVal !== undefined)
|
|
189
|
-
? { data: dataVal, extraData: extraDataVal }
|
|
190
|
-
: undefined;
|
|
191
|
-
const finalMessage = this.parseMessage(messageSource, currentReq.t, false);
|
|
192
|
-
const successCode = this.currentStore?.metadata?._code || source?.code || 200;
|
|
193
186
|
return currentRes.status(successCode).send(new ResponseSchema({
|
|
194
187
|
status: true,
|
|
195
|
-
message:
|
|
196
|
-
|
|
188
|
+
message: this.parseMessage(messageSource, currentReq.t, false),
|
|
189
|
+
payload,
|
|
197
190
|
code: successCode
|
|
198
191
|
}).getResponse);
|
|
199
192
|
}
|