fix: fix T-2879 (#3330)

This commit is contained in:
YANG QIA 2024-01-05 20:12:30 +08:00 committed by GitHub
parent c102655317
commit 33c690b877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,35 +46,26 @@ type QueryParams = Partial<{
}>;
export const postProcess = async (ctx: Context, next: Next) => {
const { sequelize } = ctx.db;
const dialect = sequelize.getDialect();
const { data, fieldMap } = ctx.action.params.values as {
data: any[];
fieldMap: { [source: string]: { type?: string } };
};
switch (dialect) {
case 'postgres':
// https://github.com/sequelize/sequelize/issues/4550
ctx.body = data.map((record) => {
const result = {};
Object.entries(record).forEach(([key, value]) => {
const { type } = fieldMap[key] || {};
switch (type) {
case 'bigInt':
case 'integer':
case 'float':
case 'double':
value = Number(value);
break;
}
result[key] = value;
});
return result;
});
break;
default:
ctx.body = data;
}
ctx.body = data.map((record) => {
const result = {};
Object.entries(record).forEach(([key, value]) => {
const { type } = fieldMap[key] || {};
switch (type) {
case 'bigInt':
case 'integer':
case 'float':
case 'double':
value = Number(value);
break;
}
result[key] = value;
});
return result;
});
await next();
};