a782d61890
- Implemented CreateProductVariantDto and UpdateProductVariantDto for product variant data transfer. - Developed ProductVariantsController to handle CRUD operations for product variants. - Created ProductVariantsService to interact with the database using Prisma. - Added ProductVariantsModule to encapsulate the product variant feature. - Included response mapping for consistent API responses.
34 lines
971 B
TypeScript
34 lines
971 B
TypeScript
import { Injectable } from '@nestjs/common'
|
|
import { ResponseMapper } from '../common/response/response-mapper'
|
|
import { PrismaService } from '../prisma/prisma.service'
|
|
|
|
@Injectable()
|
|
export class RolesService {
|
|
constructor(private prisma: PrismaService) {}
|
|
async create(data: any) {
|
|
const item = await this.prisma.role.create({ data })
|
|
return ResponseMapper.create(item)
|
|
}
|
|
|
|
async findAll() {
|
|
const items = await this.prisma.role.findMany()
|
|
return ResponseMapper.list(items)
|
|
}
|
|
|
|
async findOne(id: number) {
|
|
const item = await this.prisma.role.findUnique({ where: { id } })
|
|
if (!item) return null
|
|
return ResponseMapper.single(item)
|
|
}
|
|
|
|
async update(id: number, data: any) {
|
|
const item = await this.prisma.role.update({ where: { id }, data })
|
|
return ResponseMapper.update(item)
|
|
}
|
|
|
|
async remove(id: number) {
|
|
const item = await this.prisma.role.delete({ where: { id } })
|
|
return ResponseMapper.single(item)
|
|
}
|
|
}
|