修复insertParam 当body为数组时导致的错误

This commit is contained in:
xiaopeng 2024-11-21 19:46:18 +08:00
parent 50079fb816
commit 2afd61606b
3 changed files with 21 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/core",
"version": "7.1.20",
"version": "7.1.21",
"description": "",
"main": "dist/index.js",
"typings": "index.d.ts",

View File

@ -65,11 +65,25 @@ export abstract class BaseController {
if (!curdOption?.insertParam) {
return;
}
this.baseCtx.request.body = {
// @ts-ignore
...this.baseCtx.request.body,
...(await curdOption.insertParam(this.baseCtx, this.baseApp)),
};
const body = this.baseCtx.request.body;
if (body) {
// 判断body是否是数组
if (Array.isArray(body)) {
for (let i = 0; i < body.length; i++) {
body[i] = {
...body[i],
...(await curdOption.insertParam(this.baseCtx, this.baseApp)),
};
}
this.baseCtx.request.body = body;
return;
}
this.baseCtx.request.body = {
// @ts-ignore
...this.baseCtx.request.body,
...(await curdOption.insertParam(this.baseCtx, this.baseApp)),
};
}
}
/**

View File

@ -1,6 +1,6 @@
{
"name": "@cool-midway/core",
"version": "7.1.20",
"version": "7.1.21",
"description": "",
"main": "index.js",
"typings": "index.d.ts",