Skip to content

Commit ffcb9d2

Browse files
committed
feat: create vote model
1 parent 75e5273 commit ffcb9d2

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

models/polls/poll.schema.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ export interface PollSchema extends Document {
1717

1818
export const imageDataSchema = {
1919
url: String,
20-
votes: [Types.ObjectId]
20+
votes: [
21+
{
22+
type: Types.ObjectId,
23+
ref: 'vote'
24+
}
25+
]
2126
};
2227

2328
export const pollSchema = new Schema({

models/votes/vote.model.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Model, model } from 'mongoose';
2+
import { VoteSchema, voteSchema } from './vote.schema';
3+
4+
export default model<VoteSchema, Model<VoteSchema>>('Vote', voteSchema);
5+

models/votes/vote.schema.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Document, Schema, Types } from 'mongoose';
2+
import { Vote } from 'which-types';
3+
4+
export interface VoteSchema extends Document, Omit<Vote, '_id'> {
5+
password: string;
6+
}
7+
8+
export const voteSchema = new Schema({
9+
userId: {
10+
type: Types.ObjectId,
11+
ref: 'user'
12+
},
13+
pollId: {
14+
type: Types.ObjectId,
15+
ref: 'poll'
16+
},
17+
which: {
18+
type: String,
19+
match: /left|right/g
20+
}
21+
}, { timestamps: true });
22+

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@
4343
"eslint-config-airbnb-typescript": "^8.0.2",
4444
"eslint-plugin-import": "^2.21.2",
4545
"typescript": "^3.9.5",
46-
"which-types": "^1.3.1"
46+
"which-types": "^1.4.0"
4747
}
4848
}

0 commit comments

Comments
 (0)