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 { IsNotEmpty, IsOptional } from 'class-validator';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { ProductCategory } from '@/pet-feeder/enum/product-category';
|
||||||
|
|
||||||
export class CreateProductRequest {
|
export class CreateProductRequest {
|
||||||
@IsNotEmpty({
|
@IsNotEmpty({
|
||||||
@@ -8,6 +9,12 @@ export class CreateProductRequest {
|
|||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
@IsNotEmpty({
|
||||||
|
message: '产品分类不能为空',
|
||||||
|
})
|
||||||
|
@ApiProperty()
|
||||||
|
category: ProductCategory;
|
||||||
|
|
||||||
@IsNotEmpty({
|
@IsNotEmpty({
|
||||||
message: '产品图片不能为空',
|
message: '产品图片不能为空',
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
import { BaseFilter } from '@/core/dto/base.filter';
|
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 { BaseEntity } from '@/core/entity/base.entity';
|
||||||
import { Column, Entity, OneToMany } from 'typeorm';
|
import { Column, Entity, OneToMany } from 'typeorm';
|
||||||
import { FeedingPlanProduct } from '@/pet-feeder/entity/feeding-plan-product.entity';
|
import { FeedingPlanProduct } from '@/pet-feeder/entity/feeding-plan-product.entity';
|
||||||
|
import { ProductCategory } from '@/pet-feeder/enum/product-category';
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Product extends BaseEntity {
|
export class Product extends BaseEntity {
|
||||||
@Column()
|
@Column()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
type: 'enum',
|
||||||
|
enum: ProductCategory,
|
||||||
|
default: ProductCategory.DRY_FOOD,
|
||||||
|
})
|
||||||
|
category: ProductCategory;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
photo: string;
|
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 { Product } from '@/pet-feeder/entity/product.entity';
|
||||||
import { ProductVo } from '@/pet-feeder/vo/product.vo';
|
import { ProductVo } from '@/pet-feeder/vo/product.vo';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { productCategoryLabels } from '@/pet-feeder/enum/product-category';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ProductMapper extends BaseMapper<Product, ProductVo> {
|
export class ProductMapper extends BaseMapper<Product, ProductVo> {
|
||||||
@@ -9,6 +10,7 @@ export class ProductMapper extends BaseMapper<Product, ProductVo> {
|
|||||||
return {
|
return {
|
||||||
...super.toVo(entity),
|
...super.toVo(entity),
|
||||||
name: entity.name,
|
name: entity.name,
|
||||||
|
category: productCategoryLabels[entity.category],
|
||||||
photo: entity.photo,
|
photo: entity.photo,
|
||||||
tags: entity.tags,
|
tags: entity.tags,
|
||||||
totalCalories: entity.totalCalories,
|
totalCalories: entity.totalCalories,
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export class ProductService {
|
|||||||
): Promise<Product> {
|
): Promise<Product> {
|
||||||
const product = await this.get(id);
|
const product = await this.get(id);
|
||||||
product.name = updateProductRequest.name;
|
product.name = updateProductRequest.name;
|
||||||
|
product.category = updateProductRequest.category;
|
||||||
product.tags = updateProductRequest.tags;
|
product.tags = updateProductRequest.tags;
|
||||||
product.photo = updateProductRequest.photo;
|
product.photo = updateProductRequest.photo;
|
||||||
product.totalCalories = updateProductRequest.totalCalories;
|
product.totalCalories = updateProductRequest.totalCalories;
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { BaseVo } from '@/core/vo/base.vo';
|
import { BaseVo } from '@/core/vo/base.vo';
|
||||||
import { ApiProperty, ApiSchema } from '@nestjs/swagger';
|
import { ApiProperty, ApiSchema } from '@nestjs/swagger';
|
||||||
|
import {
|
||||||
|
ProductCategory,
|
||||||
|
productCategoryLabels,
|
||||||
|
} from '@/pet-feeder/enum/product-category';
|
||||||
|
|
||||||
@ApiSchema({
|
@ApiSchema({
|
||||||
name: 'Product',
|
name: 'Product',
|
||||||
@@ -7,6 +11,12 @@ import { ApiProperty, ApiSchema } from '@nestjs/swagger';
|
|||||||
export class ProductVo extends BaseVo {
|
export class ProductVo extends BaseVo {
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
example: [ProductCategory.DRY_FOOD, ProductCategory.WET_FOOD],
|
||||||
|
})
|
||||||
|
category: string;
|
||||||
|
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
photo: string;
|
photo: string;
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
|
|||||||
Reference in new issue
Block a user