@xrystal/core 3.23.6 → 3.23.7

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.23.6",
4
+ "version": "3.23.7",
5
5
  "description": "Project core for xrystal",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -21,19 +21,25 @@ export class BaseController {
21
21
  const req = store?.req || {};
22
22
  const identityT = (k) => k;
23
23
  const body = ctx.body || req.body || {};
24
- const query = ctx.query || req.query || (typeof req.url === 'string' && req.url.includes('?') ? qs.parse(req.url.split('?')[1]) : {});
24
+ let query = ctx.query || req.query || {};
25
+ if (Object.keys(query).length === 0) {
26
+ const urlStr = ctx.url || req.url || ctx.request?.url || '';
27
+ if (typeof urlStr === 'string' && urlStr.includes('?')) {
28
+ query = qs.parse(urlStr.split('?')[1]);
29
+ }
30
+ }
25
31
  const params = ctx.params || req.params || {};
26
- const headers = ctx.headers || req.headers || {};
32
+ const headers = ctx.headers || req.headers || ctx.request?.headers || {};
27
33
  return {
28
- url: ctx.url || req.url || '',
29
- method: ctx.method || req.method || '',
34
+ url: ctx.url || req.url || ctx.request?.url || '',
35
+ method: ctx.method || req.method || ctx.request?.method || '',
30
36
  headers,
31
37
  body,
32
38
  query,
33
39
  params,
34
40
  lang: ctx.lang || req.lang || 'en',
35
41
  t: ctx.t || req.t || identityT,
36
- accounts: ctx.accounts || req.accounts
42
+ accounts: ctx.accounts || req.accounts || ctx.user
37
43
  };
38
44
  }
39
45
  get res() {
@@ -152,29 +158,34 @@ export default class Controller extends BaseController {
152
158
  let finalExtraData = undefined;
153
159
  let messageSource = 'success_process';
154
160
  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;
161
+ const extract = (obj) => {
162
+ if (!obj || typeof obj !== 'object')
163
+ return;
164
+ if (obj.payload && typeof obj.payload === 'object') {
165
+ finalData = obj.payload.data !== undefined ? obj.payload.data : obj.payload;
166
+ finalExtraData = obj.payload.extraData;
160
167
  }
161
- else if (source.data !== undefined || source.extraData !== undefined) {
162
- finalData = source.data;
163
- finalExtraData = source.extraData;
168
+ else if (obj.data !== undefined || obj.extraData !== undefined) {
169
+ finalData = obj.data;
170
+ finalExtraData = obj.extraData;
164
171
  }
165
172
  else {
166
- const hasMetadata = source.status !== undefined || source.message !== undefined || source.code !== undefined;
167
- if (!hasMetadata && Object.keys(source).length > 0) {
168
- finalData = source;
173
+ const hasMetadata = obj.status !== undefined || obj.message !== undefined || obj.code !== undefined;
174
+ if (!hasMetadata && Object.keys(obj).length > 0) {
175
+ finalData = obj;
169
176
  }
170
177
  }
171
- if (source.message)
172
- messageSource = source.message;
173
- if (source.code !== undefined)
174
- successCode = source.code;
178
+ if (obj.message)
179
+ messageSource = obj.message;
180
+ if (obj.code !== undefined)
181
+ successCode = obj.code;
182
+ };
183
+ if (typeof resResult === 'string') {
184
+ messageSource = resResult;
185
+ extract(logicResult);
175
186
  }
176
- else if (source !== undefined) {
177
- messageSource = source;
187
+ else {
188
+ extract(resResult !== undefined ? resResult : logicResult);
178
189
  }
179
190
  let payload = undefined;
180
191
  if (finalData !== undefined || finalExtraData !== undefined) {