From 8787b934833edd803a0c6a6f6de1f4e9514a8646 Mon Sep 17 00:00:00 2001 From: vishnu vinay Date: Fri, 29 Nov 2024 13:14:01 +0530 Subject: [PATCH] changes for aadhar upload of doc_id --- src/modules/user-docs/user-docs.service.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/modules/user-docs/user-docs.service.ts b/src/modules/user-docs/user-docs.service.ts index 8715d85..1915ae6 100644 --- a/src/modules/user-docs/user-docs.service.ts +++ b/src/modules/user-docs/user-docs.service.ts @@ -6,6 +6,7 @@ import { CreateUserDocDto } from './dto/create-user-doc.dto'; import { ErrorResponse } from 'src/common/responses/error-response'; import { SuccessResponse } from 'src/common/responses/success-response'; import axios from 'axios' +import { v4 as uuidv4 } from 'uuid'; @Injectable() export class UserDocsService { constructor( @@ -37,7 +38,20 @@ export class UserDocsService { createUserDocDto.doc_data = vcJsonData; createUserDocDto.issuer = vcJsonData.issuer; } - + if(createUserDocDto.doc_id == undefined ){ + let uniqueUUID; + let isUnique = false; + while (!isUnique) { + uniqueUUID = 'did:ew:' + uuidv4(); + const existDoc = await this.userDocsRepository.findOne({ + where: { doc_id: uniqueUUID }, + }); + if (!existDoc) { + isUnique = true; // UUID is unique + } + } + createUserDocDto.doc_id = uniqueUUID; + } const existingDoc = await this.userDocsRepository.findOne({ where: { doc_id: createUserDocDto.doc_id }, });