feat: add generated code
This commit is contained in:
74
backend/src/product/product.service.ts
Normal file
74
backend/src/product/product.service.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { Product, Prisma } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class ProductService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async findAll(params: {
|
||||
skip?: number;
|
||||
take?: number;
|
||||
where?: Prisma.ProductWhereInput;
|
||||
orderBy?: Prisma.ProductOrderByWithRelationInput;
|
||||
}): Promise<{ data: Product[]; total: number }> {
|
||||
const { skip, take, where, orderBy } = params;
|
||||
const [data, total] = await this.prisma.$transaction([
|
||||
this.prisma.product.findMany({
|
||||
skip,
|
||||
take,
|
||||
where,
|
||||
orderBy,
|
||||
include: {
|
||||
productType: true,
|
||||
parent: true,
|
||||
},
|
||||
}),
|
||||
this.prisma.product.count({ where }),
|
||||
]);
|
||||
return { data, total };
|
||||
}
|
||||
|
||||
async findOne(where: Prisma.ProductWhereUniqueInput): Promise<Product | null> {
|
||||
return this.prisma.product.findUnique({
|
||||
where,
|
||||
include: {
|
||||
productType: true,
|
||||
parent: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async create(data: Prisma.ProductCreateInput): Promise<Product> {
|
||||
return this.prisma.product.create({
|
||||
data,
|
||||
include: {
|
||||
productType: true,
|
||||
parent: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async update(params: {
|
||||
where: Prisma.ProductWhereUniqueInput;
|
||||
data: Prisma.ProductUpdateInput;
|
||||
}): Promise<Product> {
|
||||
return this.prisma.product.update({
|
||||
...params,
|
||||
include: {
|
||||
productType: true,
|
||||
parent: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async remove(where: Prisma.ProductWhereUniqueInput): Promise<Product> {
|
||||
return this.prisma.product.delete({
|
||||
where,
|
||||
include: {
|
||||
productType: true,
|
||||
parent: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user