feat: add product variant management functionality
- 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.
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
import { IsObject, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
export class CreateRoleDto {
|
||||
@IsString()
|
||||
name: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
permissions?: any
|
||||
}
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
import { IsObject, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
export class UpdateRoleDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsObject()
|
||||
permissions?: any
|
||||
}
|
||||
|
||||
+17
-11
@@ -1,27 +1,33 @@
|
||||
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) {}
|
||||
|
||||
create(data: any) {
|
||||
return this.prisma.role.create({ data })
|
||||
async create(data: any) {
|
||||
const item = await this.prisma.role.create({ data })
|
||||
return ResponseMapper.create(item)
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return this.prisma.role.findMany()
|
||||
async findAll() {
|
||||
const items = await this.prisma.role.findMany()
|
||||
return ResponseMapper.list(items)
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return this.prisma.role.findUnique({ where: { id } })
|
||||
async findOne(id: number) {
|
||||
const item = await this.prisma.role.findUnique({ where: { id } })
|
||||
if (!item) return null
|
||||
return ResponseMapper.single(item)
|
||||
}
|
||||
|
||||
update(id: number, data: any) {
|
||||
return this.prisma.role.update({ where: { id }, data })
|
||||
async update(id: number, data: any) {
|
||||
const item = await this.prisma.role.update({ where: { id }, data })
|
||||
return ResponseMapper.update(item)
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return this.prisma.role.delete({ where: { id } })
|
||||
async remove(id: number) {
|
||||
const item = await this.prisma.role.delete({ where: { id } })
|
||||
return ResponseMapper.single(item)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user