change status reserve if passed
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user