diff options
Diffstat (limited to 'models')
| -rw-r--r-- | models/feedback/feedback.model.ts | 7 | ||||
| -rw-r--r-- | models/feedback/feedback.schema.ts | 28 | ||||
| -rw-r--r-- | models/votes/vote.model.ts | 2 | ||||
| -rw-r--r-- | models/votes/vote.schema.ts | 6 | 
4 files changed, 38 insertions, 5 deletions
| diff --git a/models/feedback/feedback.model.ts b/models/feedback/feedback.model.ts new file mode 100644 index 0000000..b21747b --- /dev/null +++ b/models/feedback/feedback.model.ts @@ -0,0 +1,7 @@ +import { Model, model } from 'mongoose'; +import { FeedbackSchema, feedbackSchema } from './feedback.schema'; + +feedbackSchema.index({ version: 1, authorId: 1 }, { unique: true }); // Unique together + +export default model<FeedbackSchema, Model<FeedbackSchema>>('Feedback', feedbackSchema); + diff --git a/models/feedback/feedback.schema.ts b/models/feedback/feedback.schema.ts new file mode 100644 index 0000000..ea6f6e7 --- /dev/null +++ b/models/feedback/feedback.schema.ts @@ -0,0 +1,28 @@ +import { Document, Schema, Types } from 'mongoose'; + +export interface FeedbackSchema extends Document { +  contents: string; +  authorId: string; +  score: number; +  version: string; +  createdAt: Date; +} + +export const feedbackSchema = new Schema({ +  contents: String, +  authorId: { +    type: Types.ObjectId, +    required: true, +    ref: 'User' +  }, +  score: { +    type: Number, +    required: true +  }, +  version: { +    type: String, +    match: /^v\d+\.\d+\.\d+$/, +    required: true +  } +}, { timestamps: true }); + diff --git a/models/votes/vote.model.ts b/models/votes/vote.model.ts index df2307e..bf2dcf6 100644 --- a/models/votes/vote.model.ts +++ b/models/votes/vote.model.ts @@ -1,7 +1,7 @@  import { Model, model } from 'mongoose';  import { VoteSchema, voteSchema } from './vote.schema'; -voteSchema.index({ pollId: 1, userId: 1 }, { unique: true }); // Unique together +voteSchema.index({ pollId: 1, authorId: 1 }, { unique: true }); // Unique together  export default model<VoteSchema, Model<VoteSchema>>('Vote', voteSchema); diff --git a/models/votes/vote.schema.ts b/models/votes/vote.schema.ts index 63ba212..72b196d 100644 --- a/models/votes/vote.schema.ts +++ b/models/votes/vote.schema.ts @@ -1,12 +1,10 @@  import { Document, Schema, Types } from 'mongoose';  import { Vote } from 'which-types'; -export interface VoteSchema extends Document, Omit<Vote, '_id'> { -  password: string; -} +export interface VoteSchema extends Document, Omit<Vote, '_id'> {}  export const voteSchema = new Schema({ -  userId: { +  authorId: {      type: Types.ObjectId,      ref: 'user',      required: true | 
