import { Injectable } from '@nestjs/common'; import Resources from './resources.entity'; @Injectable() export class ResourcesService { constructor() { } async findAll(): Promise<{ rows: Resources[], count: number }> { return Resources.findAndCountAll(); } findByPk(id: number): Promise { return Resources.findByPk(id,) } findOne(resources: Resources): Promise { return Resources.findOne({ where: resources as any, }) } filter(resources: Resources): Promise { return Resources.findAll({ where: resources as any, }) } async remove(id: number): Promise { return Resources.destroy({ where: { id: id } }); } async upsert(resources: any, insertIfNotFound: boolean): Promise { if (resources.id) { const existingResources = await this.findByPk(resources.id); if (existingResources) { return Resources.update(resources, { where: { id: resources.id } }); } } if (insertIfNotFound) { return Resources.create(resources as any) } } }