complexGood
Module
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Controller, Get } from '@nestjs/common'
|
import { Controller, Get, Param } from '@nestjs/common'
|
||||||
import { ApiTags } from '@nestjs/swagger'
|
import { ApiTags } from '@nestjs/swagger'
|
||||||
import { CatalogsService } from './catalog.service'
|
import { CatalogsService } from './catalog.service'
|
||||||
|
|
||||||
@@ -26,4 +26,9 @@ export class CatalogsController {
|
|||||||
async getDeviceBrands() {
|
async getDeviceBrands() {
|
||||||
return this.catalogService.getDeviceBrands()
|
return this.catalogService.getDeviceBrands()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('guilds/:guildId/good_categories')
|
||||||
|
async getGuildGoodCategories(@Param('guildId') guild_id: string) {
|
||||||
|
return this.catalogService.getGuildGoodCategories(guild_id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,4 +38,14 @@ export class CatalogsService {
|
|||||||
})
|
})
|
||||||
return ResponseMapper.list(items)
|
return ResponseMapper.list(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getGuildGoodCategories(guild_id: string) {
|
||||||
|
const items = await this.prisma.goodCategory.findMany({
|
||||||
|
where: {
|
||||||
|
guild_id,
|
||||||
|
},
|
||||||
|
select: this.defaultSelect,
|
||||||
|
})
|
||||||
|
return ResponseMapper.list(items)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ import { PrismaModule } from '@/prisma/prisma.module'
|
|||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
import { BusinessActivityComplexesController } from './complexes.controller'
|
import { BusinessActivityComplexesController } from './complexes.controller'
|
||||||
import { BusinessActivityComplexesService } from './complexes.service'
|
import { BusinessActivityComplexesService } from './complexes.service'
|
||||||
|
import { ConsumerComplexGoodsModule } from './goods/goods.module'
|
||||||
import { ConsumerComplexPosesModule } from './poses/poses.module'
|
import { ConsumerComplexPosesModule } from './poses/poses.module'
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [PrismaModule, ConsumerComplexPosesModule],
|
imports: [PrismaModule, ConsumerComplexPosesModule, ConsumerComplexGoodsModule],
|
||||||
controllers: [BusinessActivityComplexesController],
|
controllers: [BusinessActivityComplexesController],
|
||||||
providers: [BusinessActivityComplexesService],
|
providers: [BusinessActivityComplexesService],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { GoodPricingModel, UnitType } from '@/generated/prisma/enums'
|
||||||
|
import { ApiProperty, PartialType } from '@nestjs/swagger'
|
||||||
|
import { IsEnum, IsOptional, IsString } from 'class-validator'
|
||||||
|
|
||||||
|
export class CreateGoodDto {
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
name: string
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
sku: string
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ required: true })
|
||||||
|
category_id: string
|
||||||
|
|
||||||
|
@IsEnum(UnitType)
|
||||||
|
@ApiProperty({ required: true, enum: UnitType })
|
||||||
|
unit_type: UnitType
|
||||||
|
|
||||||
|
@IsEnum(GoodPricingModel)
|
||||||
|
@ApiProperty({ required: true, enum: GoodPricingModel })
|
||||||
|
pricing_model: GoodPricingModel
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
@ApiProperty({ required: false })
|
||||||
|
description?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export class UpdateGoodDto extends PartialType(CreateGoodDto) {}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
|
||||||
|
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common'
|
||||||
|
import { ApiTags } from '@nestjs/swagger'
|
||||||
|
import { CreateGoodDto, UpdateGoodDto } from './dto/good.dto'
|
||||||
|
import { ConsumerComplexGoodsService } from './goods.service'
|
||||||
|
|
||||||
|
@ApiTags('ConsumerComplexGoods')
|
||||||
|
@Controller('consumer/business_activities/:businessActivityId/complexes/:complexId/goods')
|
||||||
|
export class ConsumerComplexGoodsController {
|
||||||
|
constructor(private readonly service: ConsumerComplexGoodsService) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
async findAll(
|
||||||
|
@TokenAccount('userId') userId: string,
|
||||||
|
@Param('businessActivityId') businessActivityId: string,
|
||||||
|
@Param('complexId') complexId: string,
|
||||||
|
) {
|
||||||
|
console.log(userId, businessActivityId, complexId)
|
||||||
|
|
||||||
|
return this.service.findAll(userId, businessActivityId, complexId)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
async findOne(
|
||||||
|
@TokenAccount('userId') userId: string,
|
||||||
|
@Param('businessActivityId') businessActivityId: string,
|
||||||
|
@Param('complexId') complexId: string,
|
||||||
|
@Param('id') id: string,
|
||||||
|
) {
|
||||||
|
return this.service.findOne(userId, businessActivityId, complexId, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
async create(@Param('complexId') complexId: string, @Body() data: CreateGoodDto) {
|
||||||
|
return this.service.create(complexId, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch(':id')
|
||||||
|
async update(
|
||||||
|
@TokenAccount('userId') userId: string,
|
||||||
|
@Param('businessActivityId') businessActivityId: string,
|
||||||
|
@Param('complexId') complexId: string,
|
||||||
|
@Param('id') id: string,
|
||||||
|
@Body() data: UpdateGoodDto,
|
||||||
|
) {
|
||||||
|
return this.service.update(userId, businessActivityId, complexId, id, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Delete(':id')
|
||||||
|
// async delete(@Param('id') id: string) {
|
||||||
|
// return this.businessActivityAccountsService.delete(id)
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { PrismaModule } from '@/prisma/prisma.module'
|
||||||
|
import { Module } from '@nestjs/common'
|
||||||
|
import { ConsumerComplexGoodsController } from './goods.controller'
|
||||||
|
import { ConsumerComplexGoodsService } from './goods.service'
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [PrismaModule],
|
||||||
|
controllers: [ConsumerComplexGoodsController],
|
||||||
|
providers: [ConsumerComplexGoodsService],
|
||||||
|
exports: [ConsumerComplexGoodsService],
|
||||||
|
})
|
||||||
|
export class ConsumerComplexGoodsModule {}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
import { GoodSelect } from '@/generated/prisma/models'
|
||||||
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
|
import { Injectable } from '@nestjs/common'
|
||||||
|
import { ResponseMapper } from 'common/response/response-mapper'
|
||||||
|
import { CreateGoodDto, UpdateGoodDto } from './dto/good.dto'
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ConsumerComplexGoodsService {
|
||||||
|
constructor(private readonly prisma: PrismaService) {}
|
||||||
|
|
||||||
|
defaultSelect: GoodSelect = {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
barcode: true,
|
||||||
|
sku: true,
|
||||||
|
local_sku: true,
|
||||||
|
pricing_model: true,
|
||||||
|
unit_type: true,
|
||||||
|
category: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
created_at: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
async findAll(user_id: string, business_activity_id: string, complex_id: string) {
|
||||||
|
const goods = await this.prisma.good.findMany({
|
||||||
|
where: {
|
||||||
|
complex_id,
|
||||||
|
complex: {
|
||||||
|
id: complex_id,
|
||||||
|
business_activity: {
|
||||||
|
id: business_activity_id,
|
||||||
|
user_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: this.defaultSelect,
|
||||||
|
})
|
||||||
|
|
||||||
|
return ResponseMapper.list(goods)
|
||||||
|
}
|
||||||
|
|
||||||
|
async findOne(
|
||||||
|
user_id: string,
|
||||||
|
business_activity_id: string,
|
||||||
|
complex_id: string,
|
||||||
|
id: string,
|
||||||
|
) {
|
||||||
|
const good = await this.prisma.good.findUnique({
|
||||||
|
where: {
|
||||||
|
complex: {
|
||||||
|
id: complex_id,
|
||||||
|
business_activity: {
|
||||||
|
id: business_activity_id,
|
||||||
|
user_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
select: this.defaultSelect,
|
||||||
|
})
|
||||||
|
return ResponseMapper.single(good)
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(complex_id: string, data: CreateGoodDto) {
|
||||||
|
const { category_id, ...rest } = data
|
||||||
|
|
||||||
|
const good = await this.prisma.good.create({
|
||||||
|
data: {
|
||||||
|
...rest,
|
||||||
|
complex: {
|
||||||
|
connect: {
|
||||||
|
id: complex_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
category: {
|
||||||
|
connect: {
|
||||||
|
id: category_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return ResponseMapper.create(good)
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(
|
||||||
|
user_id: string,
|
||||||
|
business_activity_id: string,
|
||||||
|
complex_id: string,
|
||||||
|
id: string,
|
||||||
|
data: UpdateGoodDto,
|
||||||
|
) {
|
||||||
|
const { category_id, ...rest } = data
|
||||||
|
const good = await this.prisma.good.update({
|
||||||
|
where: {
|
||||||
|
complex: {
|
||||||
|
id: complex_id,
|
||||||
|
business_activity: {
|
||||||
|
id: business_activity_id,
|
||||||
|
user_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
complex: {
|
||||||
|
connect: {
|
||||||
|
id: complex_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
category: {
|
||||||
|
connect: {
|
||||||
|
id: category_id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
...rest,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return ResponseMapper.update(good)
|
||||||
|
}
|
||||||
|
|
||||||
|
// async delete(id: string) {
|
||||||
|
// await this.prisma.complex.delete({ where: { id } })
|
||||||
|
// return ResponseMapper.delete()
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -90,7 +90,6 @@ export class ComplexPosesService {
|
|||||||
},
|
},
|
||||||
select: this.defaultSelect,
|
select: this.defaultSelect,
|
||||||
})
|
})
|
||||||
console.log(poses)
|
|
||||||
|
|
||||||
return ResponseMapper.list(poses)
|
return ResponseMapper.list(poses)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user