aboutsummaryrefslogtreecommitdiff
path: root/models/polls
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-09 19:23:44 +0300
committereug-vs <eug-vs@keemail.me>2020-06-09 19:23:44 +0300
commitde9771959850f193f173616b73099c3ae6f010c9 (patch)
tree65262d9badbc46f99d8644705c4aeed62e5373ca /models/polls
parent39d637a817460ee62a0a6667abd6afc5b6898895 (diff)
downloadwhich-api-de9771959850f193f173616b73099c3ae6f010c9.tar.gz
feat!: integrate mongoDB
Diffstat (limited to 'models/polls')
-rw-r--r--models/polls/poll.model.ts5
-rw-r--r--models/polls/poll.schema.ts33
2 files changed, 38 insertions, 0 deletions
diff --git a/models/polls/poll.model.ts b/models/polls/poll.model.ts
new file mode 100644
index 0000000..211d1e6
--- /dev/null
+++ b/models/polls/poll.model.ts
@@ -0,0 +1,5 @@
+import { Model, model } from "mongoose"
+import { Poll, PollSchema } from './poll.schema';
+
+export default model<Poll, Model<Poll>>("Poll", PollSchema);
+
diff --git a/models/polls/poll.schema.ts b/models/polls/poll.schema.ts
new file mode 100644
index 0000000..2e7dccd
--- /dev/null
+++ b/models/polls/poll.schema.ts
@@ -0,0 +1,33 @@
+import { Document, Schema, Types } from 'mongoose';
+import { User } from '../users/user.schema';
+
+interface ImageData {
+ url: string;
+ votes: number;
+}
+
+export interface Poll extends Document {
+ authorId: string;
+ contents: {
+ left: ImageData;
+ right: ImageData;
+ };
+}
+
+
+const imageDataSchema = {
+ url: String,
+ votes: Number
+}
+
+export const PollSchema = new Schema({
+ contents: {
+ left: imageDataSchema,
+ right: imageDataSchema
+ },
+ authorId: {
+ type: Types.ObjectId,
+ ref: 'User'
+ }
+});
+