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