-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathinteraction.model.ts
More file actions
39 lines (34 loc) · 982 Bytes
/
interaction.model.ts
File metadata and controls
39 lines (34 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Schema, models, model, Types, Document , HydratedDocument} from "mongoose";
export interface IInteraction {
user: Types.ObjectId;
action: string;
actionId: Types.ObjectId;
actionType: string;
}
export const InteractionActionEnums = [
"view",
"upvote",
"downvote",
"bookmark",
"post",
"edit",
"delete",
"search",
] as const;
export type IInteractionDoc = HydratedDocument<IInteraction>;
const InteractionSchema = new Schema<IInteraction>(
{
user: { type: Schema.Types.ObjectId, ref: "User", required: true },
action: {
type: String,
enum: InteractionActionEnums,
required: true,
},
actionId: { type: Schema.Types.ObjectId, required: true }, // 'questionId', 'answerId',
actionType: { type: String, enum: ["question", "answer"], required: true },
},
{ timestamps: true }
);
const Interaction =
models?.Interaction || model<IInteraction>("Interaction", InteractionSchema);
export default Interaction;