38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
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<PlanUsage> {
|
|
return PlanUsage.findByPk(id)
|
|
}
|
|
|
|
findOne(planUsage: PlanUsage): Promise<PlanUsage> {
|
|
return PlanUsage.findOne({where: planUsage as any})
|
|
}
|
|
|
|
async remove(id: number): Promise<number> {
|
|
return PlanUsage.destroy({where: {id: id}});
|
|
}
|
|
|
|
filter(item: PlanUsage) : Promise<PlanUsage[]> {
|
|
return PlanUsage.findAll({where: item as any})
|
|
}
|
|
|
|
async upsert(planUsage: PlanUsage, insertIfNotFound: boolean): Promise<PlanUsage | [affectedCount: number]> {
|
|
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)
|
|
}
|
|
}
|
|
}
|