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

44 lines
1.3 KiB
TypeScript

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