소스 검색

feat: 宠物及喂养计划模型设计

IlhamTahir 1 년 전
부모
커밋
5939e959d9

+ 2 - 1
src/app.module.ts

@@ -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: [],
 })

+ 17 - 0
src/pet-feeder/entity/feeding-plan.entity.ts

@@ -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;
+}

+ 61 - 0
src/pet-feeder/entity/pet.entity.ts

@@ -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;
+}

+ 5 - 0
src/pet-feeder/enum/feeding-goal.ts

@@ -0,0 +1,5 @@
+export enum FeedingGoal {
+  GAIN = 'gain',
+  LOSE = 'lose',
+  MAINTAIN = 'maintain',
+}

+ 18 - 0
src/pet-feeder/enum/pet-body-type.ts

@@ -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',
+}

+ 4 - 0
src/pet-feeder/enum/pet-type.ts

@@ -0,0 +1,4 @@
+export enum PetType {
+  CAT = 'cat',
+  DOG = 'dog',
+}

+ 9 - 0
src/pet-feeder/pet-feeder.module.ts

@@ -0,0 +1,9 @@
+import { Module } from '@nestjs/common';
+
+@Module({
+  imports: [],
+  controllers: [],
+  providers: [],
+  exports: [],
+})
+export class PetFeederModule {}

+ 3 - 0
tsconfig.json

@@ -10,6 +10,9 @@
     "sourceMap": true,
     "outDir": "./dist",
     "baseUrl": "./",
+    "paths": {
+      "@/*": ["src/*"]
+    },
     "incremental": true,
     "skipLibCheck": true,
     "strictNullChecks": false,