Skip to content

Commit

Permalink
Merge branch 'feature/contracts' of github.com:code4romania/teo into …
Browse files Browse the repository at this point in the history
…feature/contracts

# Conflicts:
#	backend/src/modules/documents/documents.module.ts
  • Loading branch information
radulescuandrew committed Sep 24, 2024
2 parents 098cbe6 + 0890a4d commit a8e5e73
Show file tree
Hide file tree
Showing 29 changed files with 1,170 additions and 433 deletions.
28 changes: 28 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.3.10",
"@nestjs/schedule": "^4.1.1",
"@nestjs/swagger": "^7.4.0",
"@nestjs/throttler": "^6.0.0",
"@nestjs/typeorm": "^10.0.2",
Expand Down
3 changes: 3 additions & 0 deletions backend/src/modules/documents/documents.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { DocumentSignatureRepository } from './repositories/document-signature.r
import { DocumentSignatureFacade } from './services/document-signature.facade';
import { DocumentContractWebItemView } from './entities/document-contract-web-item.entity';
import { DocumentContractWebItemRepository } from './repositories/document-contract-web-item.repository';
import { CronsService } from './services/crons.service';

@Module({
imports: [
Expand Down Expand Up @@ -54,6 +55,8 @@ import { DocumentContractWebItemRepository } from './repositories/document-contr
DocumentSignatureFacade,
// Services
DocumentPDFGenerator,
// CRONS
CronsService,
],
exports: [
// Export only facades!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export type FindOneDocumentContractOptions = Partial<
| 'status'
| 'documentTemplateId'
| 'documentNumber'
| 'createdOn'
>
>;

Expand Down
45 changes: 45 additions & 0 deletions backend/src/modules/documents/services/crons.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Injectable } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import { In, LessThan, Not, Repository } from 'typeorm';
import { DocumentContractStatus } from '../enums/contract-status.enum';
import { InjectRepository } from '@nestjs/typeorm';
import { DocumentContractEntity } from '../entities/document-contract.entity';

@Injectable()
export class CronsService {
constructor(
@InjectRepository(DocumentContractEntity)
private readonly documentContractRepository: Repository<DocumentContractEntity>,
) {}

/**
* At 01:00 (Server Time) every day.
*/
@Cron('0 1 * * *')
async checkForExpiredContracts() {
// Get contracts that have a pending status and the contract's starting date is past.
const contracts = await this.documentContractRepository.find({
where: {
status: Not(
In([
DocumentContractStatus.APPROVED,
DocumentContractStatus.REJECTED_VOLUNTEER,
DocumentContractStatus.REJECTED_NGO,
DocumentContractStatus.ACTION_EXPIRED,
]),
),
documentStartDate: LessThan(new Date()),
},
});

for (const contract of contracts) {
// 1. Update each contract with ACTION_EXPIRED status
await this.documentContractRepository.update(contract.id, {
status: DocumentContractStatus.ACTION_EXPIRED,
});

// 2. Send notification to volunteer
// TODO: Send notification to volunteer
}
}
}
42 changes: 42 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"react-router-dom": "6.24.1",
"react-select": "^5.8.0",
"react-select-async-paginate": "0.7.4",
"react-signature-canvas": "^1.0.6",
"react-toastify": "^10.0.5",
"react-tooltip": "^5.28.0",
"recharts": "^2.13.0-alpha.4",
Expand Down Expand Up @@ -68,6 +69,7 @@
"@types/react": "^18.3.3",
"@types/react-datepicker": "^6.2.0",
"@types/react-dom": "^18.3.0",
"@types/react-signature-canvas": "^1.0.5",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
"@vitejs/plugin-react": "^4.3.1",
Expand Down
46 changes: 46 additions & 0 deletions frontend/src/assets/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,52 @@
"back_alert": "Are you sure you want to go back? All your progress will be lost.",
"dont_refresh": "To ensure that no progress will not be lost, please do not refresh the page during the contract generation process"
},
"document_contract": {
"contract": {
"period": "Contract period",
"generated_by": "Generated by",
"generated_on": "Generation date",
"signed_on": "Signing date",
"template": "Template used",
"actions": {
"sign": "Sign",
"reject": "Reject"
},
"status": {
"CREATED": "Saved",
"SCHEDULED": "Scheduled",
"PENDING_VOLUNTEER_SIGNATURE": "Volunteer signature pending",
"PENDING_APPROVAL_NGO": "NGO verification pending",
"PENDING_NGO_REPRESENTATIVE_SIGNATURE": "NGO signature pending",
"APPROVED": {
"ACTIVE": "Active",
"DONE": "Completed",
"NOT_STARTED": "Not started"
},
"REJECTED_VOLUNTEER": "Rejected by volunteer",
"REJECTED_NGO": "Rejected by NGO",
"ACTION_EXPIRED": "Expired"
}
},
"sign": {
"title": "Sign contract {{value}}",
"warning": "Attention! Only the legal representative of the organization, whose details are mentioned in the contract, can sign the document. Once saved, you can no longer modify the signature or the document.",
"draw": "Draw your signature below to sign the document.",
"confirm": "By applying the signature, you confirm that you have read, verified, and agree with the content of the contract. Once signed, the contract becomes valid and can no longer be modified.",
"actions": {
"apply": "Apply signature",
"reset": "Reset"
},
"success": {
"title": "Successfully signed!",
"description": "The document has been sent to the volunteer and can no longer be modified. In case of an error, you can generate a new document for this volunteer.",
"see_contract_details": "See contract details"
},
"error": {
"empty_signature": "The signature is required"
}
}
},
"doc_templates": {
"title": "Create template",
"subheading": {
Expand Down
54 changes: 51 additions & 3 deletions frontend/src/assets/locales/ro/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,60 @@
"back_alert": "Esti sigur ca vrei sa te intorci? Tot progresul tau se va pierde.",
"dont_refresh": "Pentru a te asigura că progresul tău nu se pierde, te rugăm să nu reîncarci pagina în timpul generării contractelor"
},
"document_contract": {
"contract": {
"period": "Perioada contract",
"generated_by": "Generat de",
"generated_on": "Data generare",
"signed_on": "Data semnare",
"template": "Template utilizat",
"actions": {
"sign": "Semnează",
"reject": "Refuză"
},
"status": {
"CREATED": "Salvat",
"SCHEDULED": "Planificat",
"PENDING_VOLUNTEER_SIGNATURE": "Semnare voluntar",
"PENDING_APPROVAL_NGO": "Verificare ONG",
"PENDING_NGO_REPRESENTATIVE_SIGNATURE": "Semnare ONG",
"APPROVED": {
"ACTIVE": "Activ",
"DONE": "Încheiat",
"NOT_STARTED": "Neînceput"
},
"REJECTED_VOLUNTEER": "Refuzat",
"REJECTED_NGO": "Refuzat",
"ACTION_EXPIRED": "Expirat"
}
},
"sign": {
"title": "Semnează contract {{value}}",
"warning": "Atenție! Doar reprezentantul legal al organizației, ale cărui date sunt menționate în contract, poate semna documentul. Odată ce ai salvat, nu mai poți modifica semnătura sau documentul.",
"draw": "Desenează semnătura mai jos pentru a semna documentul.",
"confirm": "Prin aplicarea semnăturii, confirmi că ai citit, verificat și ești de acord cu conținutul contractului. Odată semnat, contractul devine valid și nu mai poate fi modificat.",
"actions": {
"apply": "Aplică semnătura",
"reset": "Resetează"
},
"success": {
"title": "Ai semnat cu succes!",
"description": "Documentul a fost trimis către voluntar și nu mai poate fi modificat. În cazul în care s-a produs o eroare, poți genera un document nou pentru acest voluntar.",
"see_contract_details": "Vezi detaliile contractului"
},
"error": {
"empty_signature": "Semnătura este obligatorie"
}
}
},
"doc_templates": {
"title": "Creează template",
"view_title": "Vizualizează template",
"edit_title": "Editează template",
"success_add": "Template-ul a fost adaugat!",
"success_edit": "Template-ul a fost actualizat!",
"error_add": "Eroare la adaugarea template-ului!",
"error_edit": "Eroare la actualizarea template-ului!",
"subheading": {
"p1": "Acest template a fost realizat respectând normele din domeniu.",
"p1_link": "Află mai multe",
Expand All @@ -1032,7 +1082,6 @@
"download_uncompleted": "Descarcă necompletat",
"save": "Salvează"
},

"table": {
"title": "Template-uri de contracte",
"table_actions": {
Expand All @@ -1046,7 +1095,6 @@
"download_all": "Descarcă toate"
}
},

"tooltip": "Datele contractului (Numărul, perioada contractului și data întemeierii) se completează în momentul atribuirii contractului către unul sau mai mulți voluntari.",
"template_name": "Numele template-ului",
"organization": {
Expand Down Expand Up @@ -1207,4 +1255,4 @@
"clear": "Șterge",
"apply_all": "Aplică pentru toate"
}
}
}
Loading

0 comments on commit a8e5e73

Please sign in to comment.