aboutsummaryrefslogtreecommitdiff
path: root/models/polls
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-22 01:47:12 +0300
committereug-vs <eug-vs@keemail.me>2020-06-22 01:47:12 +0300
commit1af98079d43b8bf5da7a32870b7bb60e5f59e554 (patch)
tree03bb4b67ca952d3c5c611ee31aa2d49129fa2687 /models/polls
parent4909dda29566710793b8445ab4426102ca4a0324 (diff)
downloadwhich-api-1af98079d43b8bf5da7a32870b7bb60e5f59e554.tar.gz
feat: add vote function to schema
Diffstat (limited to 'models/polls')
-rw-r--r--models/polls/poll.model.ts5
-rw-r--r--models/polls/poll.schema.ts1
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 = {