From 7c786803220479605804a80cc3dbb3657b48685c Mon Sep 17 00:00:00 2001 From: DaddyWarbucks Date: Fri, 1 Mar 2024 16:22:46 -0600 Subject: [PATCH] Cleanup @fratzinger suggestions --- src/adapter.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/adapter.ts b/src/adapter.ts index 50151dc..818d65f 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -484,6 +484,14 @@ export class SequelizeAdapter< const sequelize = this.paramsToAdapter(id, params); const select = selector(params, this.id); + const total = await Model + .count({ ...sequelize, attributes: undefined }) + .catch(errorHandler); + + if (!total) { + throw new NotFound(`No record found for id '${id}'`); + } + const values = Object.values(Model.getAttributes()) .reduce((values, attribute: any) => { const key = attribute.fieldName as string; @@ -497,14 +505,6 @@ export class SequelizeAdapter< return values; }, {}); - const total = await Model - .count({ ...sequelize, attributes: undefined }) - .catch(errorHandler); - - if (!total) { - throw new NotFound(`No record found for id '${id}'`); - } - const instance = await Model .build(values, { isNewRecord: false }) .update(_.omit(values, this.id), sequelize) @@ -560,7 +560,6 @@ export class SequelizeAdapter< const ids: Id[] = current.map((item: any) => item[this.id]); await Model.destroy({ - raw: this.raw, ...params.sequelize, where: { [this.id]: ids.length === 1 ? ids[0] : { [this.Op.in]: ids } } }).catch(errorHandler);