Spaces:
Sleeping
Sleeping
Commit
·
cf14b0a
1
Parent(s):
b561958
feat: create activites model
Browse files
src/common/enums/activity-type.enum.ts
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
export enum ActivityType {}
|
src/common/models/activity.model.ts
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import mongoose, { Types } from "mongoose";
|
2 |
+
import { MealDocument } from "./meal.model";
|
3 |
+
import { MealPlanDocument } from "./meal-plan.model";
|
4 |
+
import { WorkoutDocument } from "./workout.model";
|
5 |
+
import { ExerciseDocument } from "./exercise.model";
|
6 |
+
import { ActivityType } from "@common/enums/activity-type.enum";
|
7 |
+
const { Schema } = mongoose;
|
8 |
+
//related_item
|
9 |
+
//meta_data
|
10 |
+
//activity type
|
11 |
+
//related id
|
12 |
+
//user id
|
13 |
+
//created_//at
|
14 |
+
//
|
15 |
+
|
16 |
+
export type RelatedItem = MealDocument | MealPlanDocument | WorkoutDocument | ExerciseDocument;
|
17 |
+
export type AMetaData = {};
|
18 |
+
|
19 |
+
export interface IActivity {
|
20 |
+
related_item?: RelatedItem;
|
21 |
+
meta_data: AMetaData;
|
22 |
+
activity_type: ActivityType;
|
23 |
+
related_id: string | Types.ObjectId;
|
24 |
+
user_id: string | Types.ObjectId;
|
25 |
+
created_at: Date;
|
26 |
+
}
|
27 |
+
|
28 |
+
const activitySchema = new Schema({
|
29 |
+
related_item: {
|
30 |
+
type: Schema.Types.Mixed,
|
31 |
+
required: false,
|
32 |
+
},
|
33 |
+
meta_data: {
|
34 |
+
type: Schema.Types.Mixed,
|
35 |
+
default: {},
|
36 |
+
},
|
37 |
+
activity_type: {
|
38 |
+
type: String,
|
39 |
+
enum: Object.values(ActivityType),
|
40 |
+
},
|
41 |
+
related_id: {
|
42 |
+
type: Schema.Types.ObjectId,
|
43 |
+
required: true,
|
44 |
+
},
|
45 |
+
user_id: {
|
46 |
+
type: Schema.Types.ObjectId,
|
47 |
+
required: true,
|
48 |
+
},
|
49 |
+
created_at: {
|
50 |
+
type: Date,
|
51 |
+
default: Date.now,
|
52 |
+
},
|
53 |
+
});
|
54 |
+
|
55 |
+
export type ActivityDocument = IActivity & mongoose.Document;
|
56 |
+
|
57 |
+
export const Activity = mongoose.model<ActivityDocument>(
|
58 |
+
"activities",
|
59 |
+
activitySchema
|
60 |
+
);
|