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/votes/vote.schema.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 models/votes/vote.schema.ts (limited to 'models/votes/vote.schema.ts') 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 From 2e28a2555119c8958737e84fd2312e9930046242 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 25 Jun 2020 09:48:39 +0300 Subject: feat: change match to enum in voteSchema --- models/votes/vote.schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'models/votes/vote.schema.ts') diff --git a/models/votes/vote.schema.ts b/models/votes/vote.schema.ts index 36b38f2..709e8bf 100644 --- a/models/votes/vote.schema.ts +++ b/models/votes/vote.schema.ts @@ -16,7 +16,7 @@ export const voteSchema = new Schema({ }, which: { type: String, - match: /left|right/g + enum: ['left', 'right'] } }, { timestamps: true }); -- cgit v1.2.3 From a58354a1d1bf967fc932723b9138d8c6322591d5 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 25 Jun 2020 11:23:20 +0300 Subject: feat: validate fields in votes --- models/votes/vote.schema.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'models/votes/vote.schema.ts') diff --git a/models/votes/vote.schema.ts b/models/votes/vote.schema.ts index 709e8bf..63ba212 100644 --- a/models/votes/vote.schema.ts +++ b/models/votes/vote.schema.ts @@ -8,15 +8,18 @@ export interface VoteSchema extends Document, Omit { export const voteSchema = new Schema({ userId: { type: Types.ObjectId, - ref: 'user' + ref: 'user', + required: true }, pollId: { type: Types.ObjectId, - ref: 'poll' + ref: 'poll', + required: true }, which: { type: String, - enum: ['left', 'right'] + enum: ['left', 'right'], + required: true } }, { timestamps: true }); -- cgit v1.2.3