aboutsummaryrefslogtreecommitdiff
path: root/models/feedback
diff options
context:
space:
mode:
authorEugene Sokolov <eug-vs@keemail.me>2020-06-28 19:01:52 +0300
committerGitHub <noreply@github.com>2020-06-28 19:01:52 +0300
commit88e97a42096c1e4de7b9f1d8fefa0829bbc0d321 (patch)
treeae402f77d0d0d7b8d06dcefc614bbb9aad12ed59 /models/feedback
parent8baf96be5ea7880cebe3aeda733b9196950be434 (diff)
parent29197dd3bc7e941707979b6c226e5f3b1a4cbbed (diff)
downloadwhich-api-88e97a42096c1e4de7b9f1d8fefa0829bbc0d321.tar.gz
Merge pull request #16 from which-ecosystem/feedback
Feedback endpoint & schema updates
Diffstat (limited to 'models/feedback')
-rw-r--r--models/feedback/feedback.model.ts7
-rw-r--r--models/feedback/feedback.schema.ts28
2 files changed, 35 insertions, 0 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 });
+