feat: update product entity and request to include nutritional values

This commit is contained in:
ilhamtahir committed 2025-02-17 05:28:49 +08:00
1 parent 73ac0f8049
commit 99a37cd2ff
5 files changed
+77 -17

No files matched your search

+30 -6
View File
@@ -25,15 +25,39 @@ export class CreateProductRequest {
@ApiProperty() @ApiProperty()
tags: string[] = []; tags: string[] = [];
@IsNotEmpty({
message: '总卡路里不能为空',
})
@ApiProperty()
totalCalories: number;
@IsNotEmpty({ @IsNotEmpty({
message: '总重量不能为空', message: '总重量不能为空',
}) })
@ApiProperty() @ApiProperty()
totalWeight: number; totalWeight: number;
@IsNotEmpty({
message: '蛋白质百分比不能为空',
})
@ApiProperty()
protein: number;
@IsNotEmpty({
message: '脂肪百分比不能为空',
})
@ApiProperty()
fat: number;
@IsNotEmpty({
message: '粗纤维百分比不能为空',
})
@ApiProperty()
fiber: number;
@IsNotEmpty({
message: '粗灰分百分比不能为空',
})
@ApiProperty()
ash: number;
@IsNotEmpty({
message: '水分百分比不能为空',
})
@ApiProperty()
moisture: number;
} }
+20 -3
View File
@@ -23,12 +23,29 @@ export class Product extends BaseEntity {
}) })
tags: string[]; tags: string[];
@Column()
totalCalories: number;
@Column() @Column()
totalWeight: number; totalWeight: number;
//蛋白质
@Column()
protein: number;
// 脂肪
@Column()
fat: number;
// 粗纤维
@Column()
fiber: number;
// 粗灰分
@Column()
ash: number;
// 水分
@Column()
moisture: number;
@OneToMany( @OneToMany(
() => FeedingPlanProduct, () => FeedingPlanProduct,
(feedingPlanProduct) => feedingPlanProduct.feedingPlan, (feedingPlanProduct) => feedingPlanProduct.feedingPlan,
+5 -1
View File
@@ -13,7 +13,11 @@ export class ProductMapper extends BaseMapper<Product, ProductVo> {
category: productCategoryLabels[entity.category], category: productCategoryLabels[entity.category],
photo: entity.photo, photo: entity.photo,
tags: entity.tags, tags: entity.tags,
totalCalories: entity.totalCalories, protein: entity.protein,
fat: entity.fat,
fiber: entity.fiber,
ash: entity.ash,
moisture: entity.moisture,
totalWeight: entity.totalWeight, totalWeight: entity.totalWeight,
}; };
} }
+5 -1
View File
@@ -31,7 +31,11 @@ export class ProductService {
product.category = updateProductRequest.category; 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.protein = updateProductRequest.protein;
product.fat = updateProductRequest.fat;
product.fiber = updateProductRequest.fiber;
product.ash = updateProductRequest.ash;
product.moisture = updateProductRequest.moisture;
product.totalWeight = updateProductRequest.totalWeight; product.totalWeight = updateProductRequest.totalWeight;
return this.productRepository.save(product); return this.productRepository.save(product);
} }
+17 -6
View File
@@ -1,9 +1,6 @@
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 { import { ProductCategory } from '@/pet-feeder/enum/product-category';
ProductCategory,
productCategoryLabels,
} from '@/pet-feeder/enum/product-category';
@ApiSchema({ @ApiSchema({
name: 'Product', name: 'Product',
@@ -21,8 +18,22 @@ export class ProductVo extends BaseVo {
photo: string; photo: string;
@ApiProperty() @ApiProperty()
tags: string[]; tags: string[];
@ApiProperty()
totalCalories: number;
@ApiProperty() @ApiProperty()
totalWeight: number; totalWeight: number;
@ApiProperty()
protein: number;
@ApiProperty()
fat: number;
@ApiProperty()
fiber: number;
@ApiProperty()
ash: number;
@ApiProperty()
moisture: number;
} }