Skip to content

Commit 6ab1e83

Browse files
Clean up upsert
1 parent 8188a28 commit 6ab1e83

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

packages/server/src/api/rest/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ class RequestHandler extends APIHandlerBase {
848848
return error;
849849
}
850850

851+
const matchFields = (requestBody as any).meta.matchFields;
851852
const uniqueFields = Object.values(modelMeta.models[type].uniqueConstraints || {}).map((uf) => uf.fields);
852853

853854
if (
@@ -856,14 +857,12 @@ class RequestHandler extends APIHandlerBase {
856857
return this.makeError('invalidPayload', 'Match fields must be unique fields', 400);
857858
}
858859

859-
const matchFields = (requestBody as any).meta.matchFields;
860-
861-
const upsertPayload: any = {};
862-
upsertPayload.where = this.makeUpsertWhere(matchFields, attributes, typeInfo);
863-
864-
upsertPayload.create = { ...attributes };
865-
upsertPayload.update = {
866-
...Object.fromEntries(Object.entries(attributes).filter((e) => !matchFields.includes(e[0]))),
860+
const upsertPayload: any = {
861+
where: this.makeUpsertWhere(matchFields, attributes, typeInfo),
862+
create: { ...attributes },
863+
update: {
864+
...Object.fromEntries(Object.entries(attributes).filter((e) => !matchFields.includes(e[0]))),
865+
},
867866
};
868867

869868
if (relationships) {

0 commit comments

Comments
 (0)