48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import Seat from './seat.entity';
|
|
import { firstValueFrom } from 'rxjs';
|
|
import { HttpService } from "@nestjs/axios";
|
|
import { Utility } from 'src/common/Utility';
|
|
|
|
@Injectable()
|
|
export class SeatService {
|
|
constructor(private readonly httpService: HttpService) { }
|
|
|
|
async findAll(): Promise<{ rows: Seat[], count: number }> {
|
|
return Seat.findAndCountAll();
|
|
}
|
|
|
|
async findByPk(id: number): Promise<Seat> {
|
|
return Seat.findByPk(id);
|
|
}
|
|
|
|
findOne(seat: Seat): Promise<Seat> {
|
|
return Seat.findOne({ where: seat as any, })
|
|
}
|
|
|
|
filter(seat: Seat): Promise<Seat[]> {
|
|
return Seat.findAll({ where: seat as any, })
|
|
}
|
|
|
|
async remove(id: number): Promise<number> {
|
|
return Seat.destroy({ where: { id: id } });
|
|
}
|
|
|
|
async bookSeat(eventId: number, seatNumber: string) {
|
|
return Seat.update({ available: 'booked' }, { where: { eventId: eventId, seatNumber: seatNumber } });
|
|
}
|
|
|
|
async upsert(seat: any, insertIfNotFound: boolean): Promise<Seat | [affectedCount: number]> {
|
|
if (seat.id) {
|
|
const existingSeat = await this.findByPk(seat.id);
|
|
if (existingSeat) {
|
|
return Seat.update(seat, { where: { id: seat.id } });
|
|
}
|
|
}
|
|
if (insertIfNotFound) {
|
|
return Seat.create(seat as any)
|
|
}
|
|
}
|
|
|
|
}
|