remedify-payments-be/src/master-config/master-config.service.ts
2025-02-24 12:46:49 +05:30

44 lines
1.4 KiB
TypeScript

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