-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathvote.model.ts
More file actions
23 lines (19 loc) · 732 Bytes
/
vote.model.ts
File metadata and controls
23 lines (19 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { model, models, Schema, Types , HydratedDocument} from "mongoose";
export interface IVote {
author: Types.ObjectId;
actionId: Types.ObjectId;
actionType: "question" | "answer";
voteType: "upvote" | "downvote";
}
export type IVoteDoc = HydratedDocument<IVote>;
const VoteSchema = new Schema<IVote>(
{
author: { type: Schema.Types.ObjectId, ref: "User", required: true },
actionId: { type: Schema.Types.ObjectId, required: true },
actionType: { type: String, enum: ["question", "answer"], required: true },
voteType: { type: String, enum: ["upvote", "downvote"], required: true },
},
{ timestamps: true }
);
const Vote = models?.Vote || model<IVote>("Vote", VoteSchema);
export default Vote;