diff options
-rw-r--r-- | models/polls/poll.schema.ts | 7 | ||||
-rw-r--r-- | models/votes/vote.model.ts | 5 | ||||
-rw-r--r-- | models/votes/vote.schema.ts | 22 | ||||
-rw-r--r-- | package-lock.json | 6 | ||||
-rw-r--r-- | package.json | 2 |
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" } } |