import { Injectable } from '@nestjs/common'; import PlanUsage from './plan-usage.entity'; @Injectable() export class PlanUsageService { async findAll(): Promise<{rows: PlanUsage[], count: number}> { return PlanUsage.findAndCountAll(); } findByPk(id: number): Promise { return PlanUsage.findByPk(id) } findOne(planUsage: PlanUsage): Promise { return PlanUsage.findOne({where: planUsage as any}) } async remove(id: number): Promise { return PlanUsage.destroy({where: {id: id}}); } filter(item: PlanUsage) : Promise { return PlanUsage.findAll({where: item as any}) } async upsert(planUsage: PlanUsage, insertIfNotFound: boolean): Promise { if(planUsage.id) { const existingUser = await this.findByPk(planUsage.id); if(existingUser) { return PlanUsage.update(planUsage, {where: {id: planUsage.id}}); } } if(insertIfNotFound) { return PlanUsage.create(planUsage as any) } } }