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