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