mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 08:20:58 +00:00
feat(contracts): lazily expire lapsed contracts and price fuel surcharge
This commit is contained in:
@@ -140,6 +140,27 @@ export class ContractsRepository extends BaseRepository<Contract> {
|
||||
return result.affected ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same-row version of expireLapsedContracts, for lazy flips on read/booking
|
||||
* paths — flips this one contract to EXPIRED if it's lapsed and not already
|
||||
* terminal. No-op (returns false) if the contract isn't actually lapsed, so
|
||||
* callers can call this unconditionally without a pre-check.
|
||||
*/
|
||||
async expireIfLapsed(id: string): Promise<boolean> {
|
||||
const result = await this.repository
|
||||
.createQueryBuilder()
|
||||
.update(Contract)
|
||||
.set({ status: 'EXPIRED' })
|
||||
.where('id = :id', { id })
|
||||
.andWhere('deleted_at IS NULL')
|
||||
.andWhere('status NOT IN (:...terminal)', { terminal: TERMINAL_CONTRACT_STATUSES })
|
||||
.andWhere('contract_valid_until IS NOT NULL AND contract_valid_until < :now', {
|
||||
now: new Date(),
|
||||
})
|
||||
.execute();
|
||||
return (result.affected ?? 0) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Live contracts whose validity ends between `days` and `days + 1` days from
|
||||
* now — the slice the daily expiry-reminder cron warns about. The window is
|
||||
|
||||
Reference in New Issue
Block a user