feat: 产品管理相关接口
This commit is contained in:
1 parent
e0cf2c00d6
commit
79255480bc
7 files changed
+42
-1
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { IsNotEmpty, IsOptional } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { ProductCategory } from '@/pet-feeder/enum/product-category';
|
||||
|
||||
export class CreateProductRequest {
|
||||
@IsNotEmpty({
|
||||
@@ -8,6 +9,12 @@ export class CreateProductRequest {
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
|
||||
@IsNotEmpty({
|
||||
message: '产品分类不能为空',
|
||||
})
|
||||
@ApiProperty()
|
||||
category: ProductCategory;
|
||||
|
||||
@IsNotEmpty({
|
||||
message: '产品图片不能为空',
|
||||
})
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import { BaseFilter } from '@/core/dto/base.filter';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class SearchProductFilter extends BaseFilter {}
|
||||
export class SearchProductFilter extends BaseFilter {
|
||||
@ApiProperty()
|
||||
order = ['-createdTime'];
|
||||
}
|
||||
@@ -1,12 +1,20 @@
|
||||
import { BaseEntity } from '@/core/entity/base.entity';
|
||||
import { Column, Entity, OneToMany } from 'typeorm';
|
||||
import { FeedingPlanProduct } from '@/pet-feeder/entity/feeding-plan-product.entity';
|
||||
import { ProductCategory } from '@/pet-feeder/enum/product-category';
|
||||
|
||||
@Entity()
|
||||
export class Product extends BaseEntity {
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: ProductCategory,
|
||||
default: ProductCategory.DRY_FOOD,
|
||||
})
|
||||
category: ProductCategory;
|
||||
|
||||
@Column()
|
||||
photo: string;
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export enum ProductCategory {
|
||||
DRY_FOOD,
|
||||
WET_FOOD,
|
||||
}
|
||||
|
||||
export const productCategoryLabels: Record<ProductCategory, string> = {
|
||||
[ProductCategory.DRY_FOOD]: '干粮',
|
||||
[ProductCategory.WET_FOOD]: '湿粮',
|
||||
};
|
||||
@@ -2,6 +2,7 @@ import { BaseMapper } from '@/core/mapper/base.mapper';
|
||||
import { Product } from '@/pet-feeder/entity/product.entity';
|
||||
import { ProductVo } from '@/pet-feeder/vo/product.vo';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { productCategoryLabels } from '@/pet-feeder/enum/product-category';
|
||||
|
||||
@Injectable()
|
||||
export class ProductMapper extends BaseMapper<Product, ProductVo> {
|
||||
@@ -9,6 +10,7 @@ export class ProductMapper extends BaseMapper<Product, ProductVo> {
|
||||
return {
|
||||
...super.toVo(entity),
|
||||
name: entity.name,
|
||||
category: productCategoryLabels[entity.category],
|
||||
photo: entity.photo,
|
||||
tags: entity.tags,
|
||||
totalCalories: entity.totalCalories,
|
||||
|
||||
@@ -28,6 +28,7 @@ export class ProductService {
|
||||
): Promise<Product> {
|
||||
const product = await this.get(id);
|
||||
product.name = updateProductRequest.name;
|
||||
product.category = updateProductRequest.category;
|
||||
product.tags = updateProductRequest.tags;
|
||||
product.photo = updateProductRequest.photo;
|
||||
product.totalCalories = updateProductRequest.totalCalories;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { BaseVo } from '@/core/vo/base.vo';
|
||||
import { ApiProperty, ApiSchema } from '@nestjs/swagger';
|
||||
import {
|
||||
ProductCategory,
|
||||
productCategoryLabels,
|
||||
} from '@/pet-feeder/enum/product-category';
|
||||
|
||||
@ApiSchema({
|
||||
name: 'Product',
|
||||
@@ -7,6 +11,12 @@ import { ApiProperty, ApiSchema } from '@nestjs/swagger';
|
||||
export class ProductVo extends BaseVo {
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
|
||||
@ApiProperty({
|
||||
example: [ProductCategory.DRY_FOOD, ProductCategory.WET_FOOD],
|
||||
})
|
||||
category: string;
|
||||
|
||||
@ApiProperty()
|
||||
photo: string;
|
||||
@ApiProperty()
|
||||
|
||||
Reference in new issue
Block a user