aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-25 08:56:47 +0300
committereug-vs <eug-vs@keemail.me>2020-06-25 08:56:47 +0300
commitffcb9d248228087ee05c7569784705b41d729aee (patch)
treed753ff19df916a283991b3f9baf668df501cdfff
parent75e527334e4e9a94b63704f87aa650c75f13891c (diff)
downloadwhich-api-ffcb9d248228087ee05c7569784705b41d729aee.tar.gz
feat: create vote model
-rw-r--r--models/polls/poll.schema.ts7
-rw-r--r--models/votes/vote.model.ts5
-rw-r--r--models/votes/vote.schema.ts22
-rw-r--r--package-lock.json6
-rw-r--r--package.json2
5 files changed, 37 insertions, 5 deletions
diff --git a/models/polls/poll.schema.ts b/models/polls/poll.schema.ts
index d495e4b..2f39aa1 100644
--- a/models/polls/poll.schema.ts
+++ b/models/polls/poll.schema.ts
@@ -17,7 +17,12 @@ export interface PollSchema extends Document {
export const imageDataSchema = {
url: String,
- votes: [Types.ObjectId]
+ votes: [
+ {
+ type: Types.ObjectId,
+ ref: 'vote'
+ }
+ ]
};
export const pollSchema = new Schema({
diff --git a/models/votes/vote.model.ts b/models/votes/vote.model.ts
new file mode 100644
index 0000000..1dbb146
--- /dev/null
+++ b/models/votes/vote.model.ts
@@ -0,0 +1,5 @@
+import { Model, model } from 'mongoose';
+import { VoteSchema, voteSchema } from './vote.schema';
+
+export default model<VoteSchema, Model<VoteSchema>>('Vote', voteSchema);
+
diff --git a/models/votes/vote.schema.ts b/models/votes/vote.schema.ts
new file mode 100644
index 0000000..36b38f2
--- /dev/null
+++ b/models/votes/vote.schema.ts
@@ -0,0 +1,22 @@
+import { Document, Schema, Types } from 'mongoose';
+import { Vote } from 'which-types';
+
+export interface VoteSchema extends Document, Omit<Vote, '_id'> {
+ password: string;
+}
+
+export const voteSchema = new Schema({
+ userId: {
+ type: Types.ObjectId,
+ ref: 'user'
+ },
+ pollId: {
+ type: Types.ObjectId,
+ ref: 'poll'
+ },
+ which: {
+ type: String,
+ match: /left|right/g
+ }
+}, { timestamps: true });
+
diff --git a/package-lock.json b/package-lock.json
index 51ac1a5..1402c27 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3051,9 +3051,9 @@
}
},
"which-types": {
- "version": "1.3.1",
- "resolved": "https://registry.npmjs.org/which-types/-/which-types-1.3.1.tgz",
- "integrity": "sha512-UU7+/FRfELIrUyZiTJkTDJ9dNxhW/ZVcWTjXn9TMtaqdIEDtu+NDFe13jZkFhlPVsVwwXa5R4n6MUa1iuLhAlg==",
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/which-types/-/which-types-1.4.0.tgz",
+ "integrity": "sha512-dq5f7AmZeataiQZxko+Dw1xRvWdzSXTwXrjKxtyL5zqLgS29J1PXjTgcAWMfbkZhbd8+iJLkfxKvYZ42itmxeA==",
"dev": true
},
"word-wrap": {
diff --git a/package.json b/package.json
index 3986b6c..ecdd31d 100644
--- a/package.json
+++ b/package.json
@@ -43,6 +43,6 @@
"eslint-config-airbnb-typescript": "^8.0.2",
"eslint-plugin-import": "^2.21.2",
"typescript": "^3.9.5",
- "which-types": "^1.3.1"
+ "which-types": "^1.4.0"
}
}