updating
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { GoodPricingModel, UnitType } from '@/generated/prisma/enums'
|
||||
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||
import { IsNumber, IsOptional, IsString } from 'class-validator'
|
||||
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
||||
|
||||
export class CreateGoodDto {
|
||||
export class CreateGuildGoodDto {
|
||||
@IsString()
|
||||
@ApiProperty()
|
||||
name: string
|
||||
@@ -10,30 +11,22 @@ export class CreateGoodDto {
|
||||
@ApiProperty()
|
||||
sku: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ required: true })
|
||||
category_id: string
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@ApiProperty({ required: false })
|
||||
local_sku?: string
|
||||
@IsEnum(UnitType)
|
||||
@ApiProperty({ required: true, enum: UnitType })
|
||||
unit_type: UnitType
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ required: false })
|
||||
barcode?: string
|
||||
@IsEnum(GoodPricingModel)
|
||||
@ApiProperty({ required: true, enum: GoodPricingModel })
|
||||
pricing_model: GoodPricingModel
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ required: false })
|
||||
description?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@ApiProperty({ required: false })
|
||||
base_sale_price?: number
|
||||
}
|
||||
|
||||
export class UpdateGoodDto extends PartialType(CreateGoodDto) {}
|
||||
export class UpdateGuildGoodDto extends PartialType(CreateGuildGoodDto) {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
||||
import { CreateGoodDto } from './dto/create-good.dto'
|
||||
import { CreateGuildGoodDto } from './dto/create-good.dto'
|
||||
import { GoodsService } from './goods.service'
|
||||
|
||||
@Controller('admin/guilds/:guildId/goods')
|
||||
@@ -17,7 +17,7 @@ export class GoodsController {
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Param('guildId') guildId: string, @Body() data: CreateGoodDto) {
|
||||
create(@Param('guildId') guildId: string, @Body() data: CreateGuildGoodDto) {
|
||||
return this.goodsService.create(guildId, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { GoodOmit } from '@/generated/prisma/models'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { ResponseMapper } from 'common/response/response-mapper'
|
||||
import { CreateGoodDto } from './dto/create-good.dto'
|
||||
import { CreateGuildGoodDto } from './dto/create-good.dto'
|
||||
|
||||
@Injectable()
|
||||
export class GoodsService {
|
||||
@@ -24,6 +24,14 @@ export class GoodsService {
|
||||
guild_id: guildId,
|
||||
is_default_guild_good: true,
|
||||
},
|
||||
include: {
|
||||
category: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
omit: this.goodOmit,
|
||||
}),
|
||||
this.prisma.good.count(),
|
||||
@@ -41,13 +49,22 @@ export class GoodsService {
|
||||
is_default_guild_good: true,
|
||||
},
|
||||
|
||||
include: {
|
||||
category: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
omit: this.goodOmit,
|
||||
})
|
||||
|
||||
return ResponseMapper.single(good)
|
||||
}
|
||||
|
||||
async create(guild_id: string, data: CreateGoodDto) {
|
||||
async create(guild_id: string, data: CreateGuildGoodDto) {
|
||||
const { category_id, ...rest } = data
|
||||
|
||||
const good = await this.prisma.good.create({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Get, Param, Post, Put } from '@nestjs/common'
|
||||
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||
import { ApiTags } from '@nestjs/swagger'
|
||||
import { CreateGuildDto } from './dto/create-guild.dto'
|
||||
import { UpdateGuildDto } from './dto/update-guild.dto'
|
||||
@@ -24,7 +24,7 @@ export class GuildsController {
|
||||
return await this.guildsService.create(data)
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@Patch(':id')
|
||||
async update(@Param('id') id: string, @Body() data: UpdateGuildDto) {
|
||||
return await this.guildsService.update(id, data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user