42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
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<UserWatchlist> {
|
|
return UserWatchlist.findByPk(id);
|
|
}
|
|
|
|
findOne(userWatchlist: UserWatchlist): Promise<UserWatchlist> {
|
|
return UserWatchlist.findOne({ where: userWatchlist as any });
|
|
}
|
|
|
|
filter(userWatchlist: UserWatchlist): Promise<UserWatchlist[]> {
|
|
return UserWatchlist.findAll({ where: userWatchlist as any });
|
|
}
|
|
|
|
async remove(id: number): Promise<number> {
|
|
return UserWatchlist.destroy({ where: { id: id } });
|
|
}
|
|
|
|
async upsert(userWatchlist: any, insertIfNotFound: boolean): Promise<UserWatchlist | [affectedCount: number]> {
|
|
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);
|
|
}
|
|
}
|
|
}
|