Skip to content

Commit

Permalink
update: delete vault doesnt work
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratap2018 committed Jun 24, 2024
1 parent 54b3b01 commit 634a2f4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/user-vault/controllers/user-vault.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ export class UserVaultController {
@Delete(':vaultId/document/:documentId')
@ApiResponse({ status: 200 })
async deleteDocument(@Param() _params, @Req() _req): Promise<any> {
console.log(_params);

const id = _params.vaultId;
const docId = _params.documentId;
const invoker = _req.headers.vermethodid;
Expand All @@ -70,6 +68,15 @@ export class UserVaultController {
invoker,
});
}
@AuthHeader()
@Delete('/:vaultId')
@ApiResponse({ status: 200 })
async deleteVault(@Param() _params, @Req() _req) {
const id = _params.vaultId;
const invoker = _req.headers.vermethodid;

return await this.vaultService.deleteVault({ id, invoker });
}

@AuthHeader()
@ApiResponse({ status: 200, type: DocumentResponseDTO })
Expand Down
1 change: 1 addition & 0 deletions src/user-vault/providers/databaseProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const UserVaultProviders = [
}

const uri = `${BASE_DB_PATH}/${tenantDB}${process.env.DB_CONFIG}`;
Logger.debug('connecting ' + tenantDB, 'DB Provider');
Logger.log(uri, 'tenant-mongoose-connections');
Logger.log(
'Before creating new db connection...',
Expand Down
5 changes: 5 additions & 0 deletions src/user-vault/repository/document.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export class DocumentRepository {
return doc;
}

async deleteVault() {
const deletionResult = await this.documentModel.db.dropDatabase();
return deletionResult;
}

async updateDocument(
documentFilterQuery: FilterQuery<DocSchema>,
document: Partial<DocSchema>,
Expand Down
17 changes: 17 additions & 0 deletions src/user-vault/services/user-vault.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,21 @@ export class UserVaultService {
return { message: 'document deleted', result: result };
}
}

async deleteVault({ id, invoker }) {
const vault = await this.vaultRepository.getVault({
id,
invoker,
});

if (vault == undefined || vault == null) {
throw new HttpException(
{
message: `Vault with given id : ${id} with invocationCapability : ${invoker} does not exists`,
},
HttpStatus.NOT_FOUND,
);
}
return this.documentRepository.deleteVault();
}
}

0 comments on commit 634a2f4

Please sign in to comment.