Ver código fonte

feat: update product entity and request to include nutritional values

IlhamTahir 11 meses atrás
pai
commit
99a37cd2ff

+ 28 - 4
src/pet-feeder/dto/create-product.request.ts

@@ -26,14 +26,38 @@ export class CreateProductRequest {
   tags: string[] = [];
 
   @IsNotEmpty({
-    message: '总卡路里不能为空',
+    message: '总重量不能为空',
   })
   @ApiProperty()
-  totalCalories: number;
+  totalWeight: number;
 
   @IsNotEmpty({
-    message: '总重量不能为空',
+    message: '蛋白质百分比不能为空',
   })
   @ApiProperty()
-  totalWeight: number;
+  protein: number;
+
+  @IsNotEmpty({
+    message: '脂肪百分比不能为空',
+  })
+  @ApiProperty()
+  fat: number;
+
+  @IsNotEmpty({
+    message: '粗纤维百分比不能为空',
+  })
+  @ApiProperty()
+  fiber: number;
+
+  @IsNotEmpty({
+    message: '粗灰分百分比不能为空',
+  })
+  @ApiProperty()
+  ash: number;
+
+  @IsNotEmpty({
+    message: '水分百分比不能为空',
+  })
+  @ApiProperty()
+  moisture: number;
 }

+ 19 - 2
src/pet-feeder/entity/product.entity.ts

@@ -24,10 +24,27 @@ export class Product extends BaseEntity {
   tags: string[];
 
   @Column()
-  totalCalories: number;
+  totalWeight: number;
 
+  //蛋白质
   @Column()
-  totalWeight: number;
+  protein: number;
+
+  // 脂肪
+  @Column()
+  fat: number;
+
+  // 粗纤维
+  @Column()
+  fiber: number;
+
+  // 粗灰分
+  @Column()
+  ash: number;
+
+  // 水分
+  @Column()
+  moisture: number;
 
   @OneToMany(
     () => FeedingPlanProduct,

+ 5 - 1
src/pet-feeder/mapper/product.mapper.ts

@@ -13,7 +13,11 @@ export class ProductMapper extends BaseMapper<Product, ProductVo> {
       category: productCategoryLabels[entity.category],
       photo: entity.photo,
       tags: entity.tags,
-      totalCalories: entity.totalCalories,
+      protein: entity.protein,
+      fat: entity.fat,
+      fiber: entity.fiber,
+      ash: entity.ash,
+      moisture: entity.moisture,
       totalWeight: entity.totalWeight,
     };
   }

+ 5 - 1
src/pet-feeder/service/product.service.ts

@@ -31,7 +31,11 @@ export class ProductService {
     product.category = updateProductRequest.category;
     product.tags = updateProductRequest.tags;
     product.photo = updateProductRequest.photo;
-    product.totalCalories = updateProductRequest.totalCalories;
+    product.protein = updateProductRequest.protein;
+    product.fat = updateProductRequest.fat;
+    product.fiber = updateProductRequest.fiber;
+    product.ash = updateProductRequest.ash;
+    product.moisture = updateProductRequest.moisture;
     product.totalWeight = updateProductRequest.totalWeight;
     return this.productRepository.save(product);
   }

+ 17 - 6
src/pet-feeder/vo/product.vo.ts

@@ -1,9 +1,6 @@
 import { BaseVo } from '@/core/vo/base.vo';
 import { ApiProperty, ApiSchema } from '@nestjs/swagger';
-import {
-  ProductCategory,
-  productCategoryLabels,
-} from '@/pet-feeder/enum/product-category';
+import { ProductCategory } from '@/pet-feeder/enum/product-category';
 
 @ApiSchema({
   name: 'Product',
@@ -21,8 +18,22 @@ export class ProductVo extends BaseVo {
   photo: string;
   @ApiProperty()
   tags: string[];
-  @ApiProperty()
-  totalCalories: number;
+
   @ApiProperty()
   totalWeight: number;
+
+  @ApiProperty()
+  protein: number;
+
+  @ApiProperty()
+  fat: number;
+
+  @ApiProperty()
+  fiber: number;
+
+  @ApiProperty()
+  ash: number;
+
+  @ApiProperty()
+  moisture: number;
 }