Skip to content

Commit

Permalink
Cleanup @fratzinger suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
DaddyWarbucks committed Mar 1, 2024
1 parent d63a7e8 commit 7c78680
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7c78680

Please sign in to comment.