Skip to content

Commit

Permalink
#13 fix: added error handler for insert record
Browse files Browse the repository at this point in the history
  • Loading branch information
GayathriSrividya committed Mar 2, 2023
1 parent 801f8d5 commit bbe3875
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/connectors/DbConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export class DbConnector implements IConnector {
}

private async insertRecord(table: string, fields: any) {
await this.pool(table).insert(fields)
let fetchedRecords = await this.pool(table).select().where('id', '=', fields.id)
return fetchedRecords.length > 0 ? (() => { throw new Error('Record already exists') })() : await this.pool(table).insert(fields)
}

private async updateRecord(table: string, fields: any) {
Expand Down

0 comments on commit bbe3875

Please sign in to comment.