aboutsummaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/polls/poll.model.ts4
-rw-r--r--models/polls/poll.schema.ts12
-rw-r--r--models/users/user.model.ts4
-rw-r--r--models/users/user.schema.ts6
4 files changed, 16 insertions, 10 deletions
diff --git a/models/polls/poll.model.ts b/models/polls/poll.model.ts
index 211d1e6..be1f604 100644
--- a/models/polls/poll.model.ts
+++ b/models/polls/poll.model.ts
@@ -1,5 +1,5 @@
import { Model, model } from "mongoose"
-import { Poll, PollSchema } from './poll.schema';
+import { PollSchema, pollSchema } from './poll.schema';
-export default model<Poll, Model<Poll>>("Poll", PollSchema);
+export default model<PollSchema, Model<PollSchema>>("Poll", pollSchema);
diff --git a/models/polls/poll.schema.ts b/models/polls/poll.schema.ts
index 2e7dccd..ea91051 100644
--- a/models/polls/poll.schema.ts
+++ b/models/polls/poll.schema.ts
@@ -1,26 +1,30 @@
import { Document, Schema, Types } from 'mongoose';
-import { User } from '../users/user.schema';
+import { User } from '../users/user.schema'
interface ImageData {
url: string;
votes: number;
}
-export interface Poll extends Document {
- authorId: string;
+export interface Poll {
+ author: User;
contents: {
left: ImageData;
right: ImageData;
};
}
+export interface PollSchema extends Document, Omit<Poll, 'author'> {
+ authorId: string;
+}
+
const imageDataSchema = {
url: String,
votes: Number
}
-export const PollSchema = new Schema({
+export const pollSchema = new Schema({
contents: {
left: imageDataSchema,
right: imageDataSchema
diff --git a/models/users/user.model.ts b/models/users/user.model.ts
index cec9298..d4c67df 100644
--- a/models/users/user.model.ts
+++ b/models/users/user.model.ts
@@ -1,5 +1,5 @@
import { Model, model } from "mongoose"
-import { User, UserSchema } from './user.schema';
+import { UserSchema, userSchema } from './user.schema';
-export default model<User, Model<User>>("User", UserSchema);
+export default model<UserSchema, Model<UserSchema>>("User", userSchema);
diff --git a/models/users/user.schema.ts b/models/users/user.schema.ts
index c846f81..e39f667 100644
--- a/models/users/user.schema.ts
+++ b/models/users/user.schema.ts
@@ -1,12 +1,14 @@
import { Document, Schema } from "mongoose"
-export interface User extends Document {
+export interface User {
name: string;
avatarUrl?: string;
age?: number;
}
-export const UserSchema = new Schema({
+export interface UserSchema extends Document, User {}
+
+export const userSchema = new Schema({
name: String,
avatarUrl: {
type: String,