diff options
Diffstat (limited to 'models')
-rw-r--r-- | models/polls/poll.model.ts | 5 | ||||
-rw-r--r-- | models/polls/poll.schema.ts | 1 |
2 files changed, 6 insertions, 0 deletions
diff --git a/models/polls/poll.model.ts b/models/polls/poll.model.ts index 7f6be9a..6f3d088 100644 --- a/models/polls/poll.model.ts +++ b/models/polls/poll.model.ts @@ -1,5 +1,10 @@ import { Model, model } from 'mongoose'; import { PollSchema, pollSchema } from './poll.schema'; +pollSchema.methods.vote = function(userId: string, which: 'left' | 'right'): PollSchema { + this.contents[which].votes.push(userId); + return this.save(); +} + export default model<PollSchema, Model<PollSchema>>('Poll', pollSchema); diff --git a/models/polls/poll.schema.ts b/models/polls/poll.schema.ts index fd6751c..0caa6b2 100644 --- a/models/polls/poll.schema.ts +++ b/models/polls/poll.schema.ts @@ -11,6 +11,7 @@ export interface PollSchema extends Document { right: ImageDataSchema; }; authorId: string; + vote: (userId: string, which: 'left' | 'right') => void; } export const imageDataSchema = { |