feat: 宠物及喂养计划模型设计
This commit is contained in:
1 parent
089cacee78
commit
5939e959d9
8 files changed
+119
-1
No files matched your search
+2
-1
@@ -2,9 +2,10 @@ import { Module } from '@nestjs/common';
|
||||
import { CoreModule } from './core/core.module';
|
||||
import { ArticleModule } from './article/article.module';
|
||||
import { WeChatModule } from './we-chat/we-chat.module';
|
||||
import { PetFeederModule } from './pet-feeder/pet-feeder.module';
|
||||
|
||||
@Module({
|
||||
imports: [CoreModule, ArticleModule, WeChatModule],
|
||||
imports: [CoreModule, ArticleModule, WeChatModule, PetFeederModule],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
})
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { BaseEntity } from '@/core/entity/base.entity';
|
||||
import { Column, Entity, OneToOne } from 'typeorm';
|
||||
import { Pet } from '@/pet-feeder/entity/pet.entity';
|
||||
import { FeedingGoal } from '@/pet-feeder/enum/feeding-goal';
|
||||
|
||||
@Entity()
|
||||
export class FeedingPlan extends BaseEntity {
|
||||
@Column()
|
||||
targetWeight: number;
|
||||
|
||||
@Column()
|
||||
feedingGoal: FeedingGoal;
|
||||
|
||||
// 反向一对一关系
|
||||
@OneToOne(() => Pet, (pet) => pet.feedingPlan)
|
||||
pet: Pet;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { TraceableEntity } from '@/core/entity/traceable.entity';
|
||||
import { PetType } from '@/pet-feeder/enum/pet-type';
|
||||
import { Gender } from '@/core/enum/Gender';
|
||||
import { PetBodyType } from '@/pet-feeder/enum/pet-body-type';
|
||||
import { Column, Entity, JoinColumn, OneToOne } from 'typeorm';
|
||||
import { FeedingPlan } from '@/pet-feeder/entity/feeding-plan.entity';
|
||||
|
||||
@Entity()
|
||||
export class Pet extends TraceableEntity {
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: PetType,
|
||||
default: PetType.CAT,
|
||||
})
|
||||
type: PetType;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: PetType,
|
||||
default: PetType.CAT,
|
||||
})
|
||||
gender: Gender;
|
||||
|
||||
@Column()
|
||||
birthday: Date;
|
||||
|
||||
@Column()
|
||||
weight: number;
|
||||
|
||||
@Column()
|
||||
isActive: boolean;
|
||||
|
||||
@Column()
|
||||
isPregnant: boolean;
|
||||
|
||||
// 是否绝育
|
||||
@Column()
|
||||
isSterilization: boolean;
|
||||
|
||||
// 是否在哺乳
|
||||
@Column()
|
||||
isLactation: boolean;
|
||||
|
||||
// 体型
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: PetBodyType,
|
||||
default: PetBodyType.IDEAL,
|
||||
})
|
||||
bodyType: PetBodyType;
|
||||
|
||||
// 一对一喂养计划
|
||||
@OneToOne(() => FeedingPlan, (feedingPlan) => feedingPlan.pet, {
|
||||
cascade: true,
|
||||
})
|
||||
@JoinColumn() // 用于指定外键关系
|
||||
feedingPlan: FeedingPlan;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export enum FeedingGoal {
|
||||
GAIN = 'gain',
|
||||
LOSE = 'lose',
|
||||
MAINTAIN = 'maintain',
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
export enum PetBodyType {
|
||||
// 极度消瘦
|
||||
EXTREMELY_THIN = 'extremely-thin',
|
||||
// 非常瘦
|
||||
VERY_THIN = 'very-thin',
|
||||
// 消瘦
|
||||
THIN = 'thin',
|
||||
// 偏轻
|
||||
UNDERWEIGHT = 'underweight',
|
||||
// 理想体重
|
||||
IDEAL = 'ideal',
|
||||
// 偏重
|
||||
OVERWEIGHT = 'overweight',
|
||||
// 肥胖
|
||||
OBESE = 'obese',
|
||||
// 极度肥胖
|
||||
EXTREMELY_OBESE = 'extremely-obese',
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export enum PetType {
|
||||
CAT = 'cat',
|
||||
DOG = 'dog',
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
exports: [],
|
||||
})
|
||||
export class PetFeederModule {}
|
||||
Reference in new issue
Block a user