ticket-booking-be/src/timeSlot/timeSlot.service.ts
2025-04-11 13:14:06 +05:30

44 lines
1.3 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import TimeSlot from './timeSlot.entity';
import { firstValueFrom } from 'rxjs';
import { HttpService } from "@nestjs/axios";
import { Utility } from 'src/common/Utility';
@Injectable()
export class TimeSlotService {
constructor(private readonly httpService: HttpService) { }
async findAll(): Promise<{ rows: TimeSlot[], count: number }> {
return TimeSlot.findAndCountAll();
}
async findByPk(id: number): Promise<TimeSlot> {
return TimeSlot.findByPk(id);
}
findOne(timeSlot: TimeSlot): Promise<TimeSlot> {
return TimeSlot.findOne({ where: timeSlot as any, })
}
filter(timeSlot: TimeSlot): Promise<TimeSlot[]> {
return TimeSlot.findAll({ where: timeSlot as any, })
}
async remove(id: number): Promise<number> {
return TimeSlot.destroy({ where: { id: id } });
}
async upsert(timeSlot: any, insertIfNotFound: boolean): Promise<TimeSlot | [affectedCount: number]> {
if (timeSlot.id) {
const existingTimeSlot = await this.findByPk(timeSlot.id);
if (existingTimeSlot) {
return TimeSlot.update(timeSlot, { where: { id: timeSlot.id } });
}
}
if (insertIfNotFound) {
return TimeSlot.create(timeSlot as any)
}
}
}