From e63122d84c65f30eb1e063504e7f16a05eb769f1 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 28 Jun 2020 15:40:53 +0300 Subject: feat: create Feedback model --- models/feedback/feedback.model.ts | 5 +++++ models/feedback/feedback.schema.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 models/feedback/feedback.model.ts create mode 100644 models/feedback/feedback.schema.ts (limited to 'models/feedback') diff --git a/models/feedback/feedback.model.ts b/models/feedback/feedback.model.ts new file mode 100644 index 0000000..b2ec4b5 --- /dev/null +++ b/models/feedback/feedback.model.ts @@ -0,0 +1,5 @@ +import { Model, model, Types } from 'mongoose'; +import { FeedbackSchema, feedbackSchema } from './feedback.schema'; + +export default model>('Feedback', feedbackSchema); + diff --git a/models/feedback/feedback.schema.ts b/models/feedback/feedback.schema.ts new file mode 100644 index 0000000..a0844d6 --- /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 }); + -- cgit v1.2.3 From 02b0da08155c6615a48b8d7f49648c19c1600020 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 28 Jun 2020 16:18:20 +0300 Subject: feat: create feedback service --- models/feedback/feedback.schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'models/feedback') diff --git a/models/feedback/feedback.schema.ts b/models/feedback/feedback.schema.ts index a0844d6..ea6f6e7 100644 --- a/models/feedback/feedback.schema.ts +++ b/models/feedback/feedback.schema.ts @@ -8,7 +8,7 @@ export interface FeedbackSchema extends Document { createdAt: Date; } -export const FeedbackSchema = new Schema({ +export const feedbackSchema = new Schema({ contents: String, authorId: { type: Types.ObjectId, -- cgit v1.2.3 From 00387d9ad38049db555cad7b5cb375167a108a6e Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 28 Jun 2020 18:56:14 +0300 Subject: style: fix linting errors --- models/feedback/feedback.model.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'models/feedback') diff --git a/models/feedback/feedback.model.ts b/models/feedback/feedback.model.ts index b2ec4b5..793f8da 100644 --- a/models/feedback/feedback.model.ts +++ b/models/feedback/feedback.model.ts @@ -1,4 +1,4 @@ -import { Model, model, Types } from 'mongoose'; +import { Model, model } from 'mongoose'; import { FeedbackSchema, feedbackSchema } from './feedback.schema'; export default model>('Feedback', feedbackSchema); -- cgit v1.2.3 From 094384b580ab36feb7e23507aab36d174022ac0c Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 28 Jun 2020 18:57:31 +0300 Subject: feat: only allow feedback once per version --- models/feedback/feedback.model.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'models/feedback') diff --git a/models/feedback/feedback.model.ts b/models/feedback/feedback.model.ts index 793f8da..b21747b 100644 --- a/models/feedback/feedback.model.ts +++ b/models/feedback/feedback.model.ts @@ -1,5 +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>('Feedback', feedbackSchema); -- cgit v1.2.3