-
-
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] Endpoint for Reject Document Contract by volunteer
- Loading branch information
1 parent
566835d
commit 7077b55
Showing
5 changed files
with
181 additions
and
3 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
13 changes: 13 additions & 0 deletions
13
backend/src/api/_mobile/documents/dto/RejectDocumentContractByVolunteer.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,13 @@ | ||
import { IsString, IsOptional } from 'class-validator'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class RejectDocumentContractByVolunteerDto { | ||
@ApiProperty({ description: 'Organization ID' }) | ||
@IsString() | ||
organizationId: string; | ||
|
||
@ApiProperty({ description: 'Reason for rejecting the contract' }) | ||
@IsString() | ||
@IsOptional() | ||
reason?: string; | ||
} |
2 changes: 1 addition & 1 deletion
2
...documents/dto/SignDocumentContract.dto.ts → ...to/SignDocumentContractByVolunteer.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
145 changes: 145 additions & 0 deletions
145
backend/src/usecases/documents/new_contracts/reject-document-contact-by-volunteer.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,145 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { IUseCaseService } from 'src/common/interfaces/use-case-service.interface'; | ||
import { ExceptionsService } from 'src/infrastructure/exceptions/exceptions.service'; | ||
import { DocumentContractStatus } from 'src/modules/documents/enums/contract-status.enum'; | ||
import { ContractExceptionMessages } from 'src/modules/documents/exceptions/contract.exceptions'; | ||
import { DocumentContractFacade } from 'src/modules/documents/services/document-contract.facade'; | ||
import { VolunteerFacade } from 'src/modules/volunteer/services/volunteer.facade'; | ||
|
||
// ┌─────────────────────────────────────────────────────────────────────────┐ | ||
// │ Business Rules for RejectDocumentContractByVolunteerUsecase: │ | ||
// │ │ | ||
// │ 1. Volunteer Authentication: │ | ||
// │ - The volunteer must exist and be associated with the given │ | ||
// │ organization. │ | ||
// │ - If the volunteer is not found or not part of the organization, │ | ||
// │ throw a not found exception. │ | ||
// │ │ | ||
// │ 2. Contract Validation: │ | ||
// │ - The contract must exist and be in the PENDING_VOLUNTEER_SIGNATURE │ | ||
// │ status. │ | ||
// │ - The contract must be assigned to the current volunteer. │ | ||
// │ - The contract must belong to the user's organization. │ | ||
// │ - If any of these conditions are not met, throw a not found │ | ||
// │ exception. │ | ||
// │ │ | ||
// │ 4. Contract Update: │ | ||
// │ - Update the contract status to REJECTED_BY_VOLUNTEER. │ | ||
// │ │ | ||
// │ 5. Error Handling: │ | ||
// │ - Any failures in the process should throw appropriate exceptions. │ | ||
// │ - Use the ExceptionsService to handle and throw standardized │ | ||
// │ exceptions. │ | ||
// │ │ | ||
// │ 6. Transactional Integrity: // TODO: Implement this │ | ||
// │ - Ensure that all database operations are performed atomically. │ | ||
// │ - If any part of the process fails, all changes should be rolled │ | ||
// │ back. │ | ||
// │ │ | ||
// │ 7. Audit Trail: // TODO: Implement this │ | ||
// │ - Track the rejection event in an Actions Archive for auditing │ | ||
// │ purposes. │ | ||
// │ - Store the rejection reason in the Actions Archive. │ | ||
// │ │ | ||
// │ 8. Authorization: │ | ||
// │ - Ensure that only the assigned volunteer can reject their own │ | ||
// │ contract. │ | ||
// │ │ | ||
// │ 9. Notification: │ | ||
// │ - Notify relevant parties (e.g., NGO administrators) about the │ | ||
// │ contract rejection. │ | ||
// │ │ | ||
// │ 10. Data Validation: │ | ||
// │ - Validate the format and content of the rejection reason before │ | ||
// │ processing. │ | ||
// └─────────────────────────────────────────────────────────────────────────┘ | ||
|
||
@Injectable() | ||
export class RejectDocumentContractByVolunteerUsecase | ||
implements IUseCaseService<void> | ||
{ | ||
constructor( | ||
private readonly documentContractFacade: DocumentContractFacade, | ||
private readonly volunteerFacade: VolunteerFacade, | ||
private readonly exceptionService: ExceptionsService, | ||
) {} | ||
|
||
public async execute({ | ||
contractId, | ||
userId, | ||
organizationId, | ||
rejectionReason, | ||
}: { | ||
contractId: string; | ||
userId: string; | ||
organizationId: string; | ||
rejectionReason: string; | ||
}): Promise<void> { | ||
/* ┌─────────────────────────────────────────────────────────────────────┐ | ||
* │ Verify volunteer existence: │ | ||
* │ │ | ||
* │ 1. Volunteer must exist and be part of the organization │ | ||
* │ │ | ||
* │ This ensures that the volunteer is valid and authorized to reject. │ | ||
* └─────────────────────────────────────────────────────────────────────┘ | ||
*/ | ||
const volunteer = await this.volunteerFacade.find({ | ||
userId: userId, | ||
organizationId, | ||
}); | ||
if (!volunteer) { | ||
this.exceptionService.notFoundException({ | ||
message: 'Volunteer is not part of the organization', | ||
code_error: 'VOLUNTEER_NOT_PART_OF_ORGANIZATION', | ||
}); | ||
} | ||
|
||
/* ┌─────────────────────────────────────────────────────────────────────┐ | ||
* │ Verify contract existence and eligibility: │ | ||
* │ │ | ||
* │ 1. Status must be PENDING_VOLUNTEER_SIGNATURE │ | ||
* │ 2. Contract is assigned to the current volunteer │ | ||
* │ 3. Contract belongs to the user's organization │ | ||
* │ │ | ||
* │ This ensures that the contract is valid and authorized to be │ | ||
* │ rejected. │ | ||
* └─────────────────────────────────────────────────────────────────────┘ | ||
*/ | ||
const contractExists = await this.documentContractFacade.exists({ | ||
id: contractId, | ||
volunteerId: volunteer.id, | ||
organizationId, | ||
status: DocumentContractStatus.PENDING_VOLUNTEER_SIGNATURE, | ||
}); | ||
|
||
if (!contractExists) { | ||
this.exceptionService.notFoundException( | ||
ContractExceptionMessages.CONTRACT_002, | ||
); | ||
} | ||
|
||
/* ┌─────────────────────────────────────────────────────────────────────┐ | ||
* │ Update contract status: │ | ||
* │ │ | ||
* │ 1. Update the contract status to REJECTED_VOLUNTEER. │ | ||
* └─────────────────────────────────────────────────────────────────────┘ | ||
*/ | ||
await this.documentContractFacade.update(contractId, { | ||
status: DocumentContractStatus.REJECTED_VOLUNTEER, | ||
}); | ||
|
||
/* ┌─────────────────────────────────────────────────────────────────────┐ | ||
* │ Audit trail logging: │ | ||
* │ │ | ||
* │ 1. Log the contract rejection event in the Actions Archive together │ | ||
* │ with the rejection reason. │ | ||
* └─────────────────────────────────────────────────────────────────────┘ | ||
*/ | ||
// TODO: Implement audit trail logging | ||
console.log('rejectionReason', rejectionReason); | ||
|
||
// TODO: Implement notification to relevant parties | ||
|
||
return; | ||
} | ||
} |
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