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