From ffcb9d248228087ee05c7569784705b41d729aee Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 25 Jun 2020 08:56:47 +0300 Subject: feat: create vote model --- models/polls/poll.schema.ts | 7 ++++++- models/votes/vote.model.ts | 5 +++++ models/votes/vote.schema.ts | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 models/votes/vote.model.ts create mode 100644 models/votes/vote.schema.ts (limited to 'models') 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>('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 { + 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 }); + -- cgit v1.2.3