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