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