feat: 创建产品接口
This commit is contained in:
1 parent
7c34f8b986
commit
8d72401f74
13 files changed
+217
-11
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import { BaseEntity } from '@/core/entity/base.entity';
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
|
||||
import { FeedingPlan } from '@/pet-feeder/entity/feeding-plan.entity';
|
||||
import { Product } from '@/pet-feeder/entity/product.entity';
|
||||
|
||||
@Entity()
|
||||
export class FeedingPlanProduct extends BaseEntity {
|
||||
@Column()
|
||||
dailyUsageWeight: number;
|
||||
|
||||
@ManyToOne(
|
||||
() => FeedingPlan,
|
||||
(feedingPlan) => feedingPlan.feedingPlanProducts,
|
||||
)
|
||||
@JoinColumn({
|
||||
name: 'feedingPlanId',
|
||||
})
|
||||
feedingPlan: FeedingPlan;
|
||||
|
||||
@ManyToOne(() => Product, (product) => product.feedingPlanProducts, {
|
||||
eager: true,
|
||||
onDelete: 'CASCADE',
|
||||
})
|
||||
@JoinColumn({
|
||||
name: 'productId',
|
||||
})
|
||||
product: Product;
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { BaseEntity } from '@/core/entity/base.entity';
|
||||
import { Column, Entity, OneToOne } from 'typeorm';
|
||||
import { Column, Entity, OneToMany, OneToOne } from 'typeorm';
|
||||
import { Pet } from '@/pet-feeder/entity/pet.entity';
|
||||
import { FeedingGoal } from '@/pet-feeder/enum/feeding-goal';
|
||||
import { FeedingPlanProduct } from '@/pet-feeder/entity/feeding-plan-product.entity';
|
||||
|
||||
@Entity()
|
||||
export class FeedingPlan extends BaseEntity {
|
||||
@@ -14,4 +15,10 @@ export class FeedingPlan extends BaseEntity {
|
||||
// 反向一对一关系
|
||||
@OneToOne(() => Pet, (pet) => pet.feedingPlan)
|
||||
pet: Pet;
|
||||
|
||||
@OneToMany(
|
||||
() => FeedingPlanProduct,
|
||||
(feedingPlanProduct) => feedingPlanProduct.product,
|
||||
)
|
||||
feedingPlanProducts: FeedingPlanProduct[];
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { BaseEntity } from '@/core/entity/base.entity';
|
||||
import { Column, Entity, OneToMany } from 'typeorm';
|
||||
import { FeedingPlanProduct } from '@/pet-feeder/entity/feeding-plan-product.entity';
|
||||
|
||||
@Entity()
|
||||
export class Product extends BaseEntity {
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
photo: string;
|
||||
|
||||
@Column({
|
||||
type: 'json',
|
||||
})
|
||||
tags: string[];
|
||||
|
||||
@Column()
|
||||
totalCalories: number;
|
||||
|
||||
@Column()
|
||||
totalWeight: number;
|
||||
|
||||
@OneToMany(
|
||||
() => FeedingPlanProduct,
|
||||
(feedingPlanProduct) => feedingPlanProduct.feedingPlan,
|
||||
{ cascade: true },
|
||||
)
|
||||
feedingPlanProducts: FeedingPlanProduct[];
|
||||
}
|
||||
Reference in new issue
Block a user