change status reserve if passed

This commit is contained in:
2026-07-09 21:07:39 +03:30
parent c485ee326c
commit 9dc1728edc
3 changed files with 60 additions and 2 deletions
+31 -1
View File
@@ -5,7 +5,7 @@ import {
NotFoundException,
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { In, LessThan, Repository } from 'typeorm';
import { AuthorizationService } from '../authorization/authorization.service';
import { ReservePolicy } from '../authorization/policies/reserve.policy';
import { AuthUser } from '../auth/interfaces/auth-user.interface';
@@ -292,6 +292,32 @@ export class ReservesService {
});
}
async autoCompletePastReserves(): Promise<number> {
const today = this.getTodayDateString();
const reserves = await this.reservesRepository.find({
where: {
status: In([ReserveStatus.PENDING, ReserveStatus.CONFIRMED]),
appointmentDate: LessThan(today),
},
});
for (const reserve of reserves) {
await this.logStatusChange(
reserve.id,
reserve.status,
ReserveStatus.COMPLETED,
null,
);
reserve.status = ReserveStatus.COMPLETED;
}
if (reserves.length > 0) {
await this.reservesRepository.save(reserves);
}
return reserves.length;
}
async confirmDepositPayment(
reserveId: string,
changedByUserId: string | null,
@@ -359,6 +385,10 @@ export class ReservesService {
return time.length === 5 ? `${time}:00` : time;
}
private getTodayDateString(): string {
return new Date().toISOString().slice(0, 10);
}
private async validateItems(items: CreateReserveDto['items']): Promise<void> {
for (const item of items) {
const serviceExists = await this.servicesRepository.existsBy({