diff --git a/Credentials/controllers/receiving/Create.ts b/Credentials/controllers/receiving/Create.ts index 6dd7e58..281df96 100644 --- a/Credentials/controllers/receiving/Create.ts +++ b/Credentials/controllers/receiving/Create.ts @@ -1,4 +1,4 @@ -import { checkIfRequestBodyExists, checkIfPositiveIntegerNumber, checkIfTypeIsString } from "../../../_common/utils/Request.utils"; +import { checkIfPositiveIntegerNumber, checkIfRequestBodyExists, checkIfTypeIsString } from "../../../_common/utils/Request.utils"; import { HttpRequest } from "@azure/functions"; import ReceivingCredential from '../../../_common/models/ReceivingCredential.model'; @@ -21,11 +21,17 @@ export const createReceive = async (req: HttpRequest) => { checkIfTypeIsString(username, 'username'); // Check if row with id_account already exists - const response_from_db = await ReceivingCredential.get(id_account); + let response_from_db = await ReceivingCredential.get(id_account); // If exists throw error 409 - Conflict throwIfDatabaseResourceExists(response_from_db, 'id_account'); + // Check if row with uuid already exists + response_from_db = await ReceivingCredential.getUUID(uuid); + + // If exists throw error 409 - Conflict + throwIfDatabaseResourceExists(response_from_db, 'uuid'); + await ReceivingCredential.create(id_account, uuid, username); return { diff --git a/Credentials/index.ts b/Credentials/index.ts index 39cba45..f5803f8 100644 --- a/Credentials/index.ts +++ b/Credentials/index.ts @@ -1,5 +1,6 @@ import { AzureFunction, Context, HttpRequest } from "@azure/functions" +import { ErrorLogs } from "../_common/models/ErrorLogs.model"; import { create } from "./controllers/fetching/Create"; import { createReceive } from "./controllers/receiving/Create"; import { get } from "./controllers/fetching/Get"; @@ -86,6 +87,12 @@ const httpTrigger: AzureFunction = async function (context: Context, req: HttpRe 'Content-Type': 'application/json' } }; + + ErrorLogs.insert( + { error: error, req: req }, + 'Unexpected error occurred.', + '--- Internal error ---' + ); } };