From bbe3875a12b64ad38fc3316b13e52cf30b1537af Mon Sep 17 00:00:00 2001 From: GayathriSrividya Date: Thu, 2 Mar 2023 17:54:25 +0530 Subject: [PATCH] #13 fix: added error handler for insert record --- src/connectors/DbConnector.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/connectors/DbConnector.ts b/src/connectors/DbConnector.ts index 4b0b1efe..8cc323ff 100644 --- a/src/connectors/DbConnector.ts +++ b/src/connectors/DbConnector.ts @@ -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) {