-
-
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.
Merge branch 'feature/contracts' of github.com:code4romania/teo into …
…feature/contracts # Conflicts: # backend/src/modules/documents/documents.module.ts
- Loading branch information
Showing
29 changed files
with
1,170 additions
and
433 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.