Files
toir-light-v17/backend/src/category-resource/category-resource.service.ts
2026-04-25 16:21:27 +00:00

74 lines
1.9 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { CategoryResource, Prisma } from '@prisma/client';
@Injectable()
export class CategoryResourceService {
constructor(private prisma: PrismaService) {}
async findAll(params: {
skip?: number;
take?: number;
where?: Prisma.CategoryResourceWhereInput;
orderBy?: Prisma.CategoryResourceOrderByWithRelationInput;
}): Promise<{ data: CategoryResource[]; total: number }> {
const { skip, take, where, orderBy } = params;
const [data, total] = await this.prisma.$transaction([
this.prisma.categoryResource.findMany({
skip,
take,
where,
orderBy,
include: {
part: true,
employee: true,
},
}),
this.prisma.categoryResource.count({ where }),
]);
return { data, total };
}
async findOne(where: Prisma.CategoryResourceWhereUniqueInput): Promise<CategoryResource | null> {
return this.prisma.categoryResource.findUnique({
where,
include: {
part: true,
employee: true,
},
});
}
async create(data: Prisma.CategoryResourceCreateInput): Promise<CategoryResource> {
return this.prisma.categoryResource.create({
data,
include: {
part: true,
employee: true,
},
});
}
async update(params: {
where: Prisma.CategoryResourceWhereUniqueInput;
data: Prisma.CategoryResourceUpdateInput;
}): Promise<CategoryResource> {
return this.prisma.categoryResource.update({
...params,
include: {
part: true,
employee: true,
},
});
}
async remove(where: Prisma.CategoryResourceWhereUniqueInput): Promise<CategoryResource> {
return this.prisma.categoryResource.delete({
where,
include: {
part: true,
employee: true,
},
});
}
}