-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [Contracts] API - Delete template and reject contract by NGO
- Loading branch information
1 parent
5ff75d5
commit 78cf3e0
Showing
11 changed files
with
133 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
backend/src/api/documents/dto/reject-document-contract.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { IsOptional, IsString } from 'class-validator'; | ||
|
||
export class RejectDocumentContractByNgoDTO { | ||
@IsString() | ||
@IsOptional() | ||
rejectionReason: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
backend/src/usecases/documents/new_contracts/delete-document-template.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { JSONStringifyError } from 'src/common/helpers/utils'; | ||
import { IUseCaseService } from 'src/common/interfaces/use-case-service.interface'; | ||
import { ExceptionsService } from 'src/infrastructure/exceptions/exceptions.service'; | ||
import { DocumentTemplateExceptionMessages } from 'src/modules/documents/exceptions/documente-template.exceptions'; | ||
import { DocumentContractFacade } from 'src/modules/documents/services/document-contract.facade'; | ||
import { DocumentTemplateFacade } from 'src/modules/documents/services/document-template.facade'; | ||
|
||
@Injectable() | ||
export class DeleteDocumentTemplateUsecase implements IUseCaseService<string> { | ||
private readonly logger = new Logger(DeleteDocumentTemplateUsecase.name); | ||
constructor( | ||
private readonly documentTemplateFacade: DocumentTemplateFacade, | ||
private readonly documentContractFacade: DocumentContractFacade, | ||
private readonly exceptionService: ExceptionsService, | ||
) {} | ||
|
||
public async execute(id: string, organizationId: string): Promise<string> { | ||
try { | ||
// 1. Templates can be deleted if are not linked with a contract | ||
const isUsed = await this.documentContractFacade.exists({ | ||
documentTemplateId: id, | ||
organizationId: organizationId, | ||
}); | ||
|
||
if (isUsed) { | ||
this.exceptionService.badRequestException({ | ||
message: 'Used templates cannot be deleted', | ||
code_error: 'DELETE_DOCUMENT_TEMPLATE_USED', | ||
}); | ||
} | ||
|
||
// 2. Try to delete it | ||
const deleted = await this.documentTemplateFacade.delete({ | ||
id, | ||
organizationId, | ||
}); | ||
|
||
if (!deleted) { | ||
this.exceptionService.badRequestException({ | ||
message: | ||
'The template does not exist or is not part of your organization', | ||
code_error: 'DELETE_TEMPLATE_ERR', | ||
}); | ||
} | ||
|
||
return deleted; | ||
} catch (error) { | ||
if (error.code_error) { | ||
// Rethrow errors that we've thrown above, and catch the others | ||
throw error; | ||
} | ||
|
||
this.logger.error({ | ||
...DocumentTemplateExceptionMessages.TEMPLATE_002, | ||
error: JSONStringifyError(error), | ||
}); | ||
this.exceptionService.internalServerErrorException({ | ||
message: 'Could not delete the template', | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters