diff --git a/src/models/Reaction.ts b/src/models/Reaction.ts index 4e48085..54cbe53 100644 --- a/src/models/Reaction.ts +++ b/src/models/Reaction.ts @@ -1,64 +1,49 @@ -import mongoose, { Document, PopulatedDoc, Schema } from 'mongoose'; - -import { Model } from '../utils/constants'; -import { BaseModel, ID } from '../utils/types'; -import { PostDocument } from './Post'; -import { UserDocument } from './User'; - -/** - * TODO: (4.01) - * - Read this enum. - * - Delete this comment - */ -export enum ReactionType { - FIRE = 'FIRE', // 🔥 - HEART = 'HEART', // 💖 - HUNDRED = 'HUNDRED', // 💯 - LAUGH = 'LAUGH', // 😂 - SAD = 'SAD' // 😢 -} - -/** - * TODO: (4.02) - * - Read this interface. - * - Delete this comment once you've done so. - */ -interface IReaction extends BaseModel { - /** - * Post that was "reacted" to. - */ - post: PopulatedDoc; - - /** - * Type of the reaction, which corresponds to an emoji, as seen above. - * - * @default ReactionType.HEART - */ - type: ReactionType; - - /** - * User that made the reaction. - */ - user: PopulatedDoc; -} - -export type ReactionDocument = Document<{}, {}, IReaction> & IReaction; - -const reactionSchema: Schema = new Schema( - { - /** - * TODO: (3.03) - * - Create the schema for the Reactions that we'll save in the database - * using the interface above as a reference. - * - Delete this comment and the example field. - * - Add comment(s) to explain your work. - */ - exampleField: { required: true, type: String } - }, - { timestamps: true } -); - -const Reaction: mongoose.Model = - mongoose.model(Model.REACTION, reactionSchema); - -export default Reaction; +import mongoose, { Document, PopulatedDoc, Schema } from 'mongoose'; + +import { Model } from '../utils/constants'; +import { BaseModel, ID } from '../utils/types'; +import { PostDocument } from './Post'; +import { UserDocument } from './User'; + +export enum ReactionType { + FIRE = 'FIRE', // 🔥 + HEART = 'HEART', // 💖 + HUNDRED = 'HUNDRED', // 💯 + LAUGH = 'LAUGH', // 😂 + SAD = 'SAD' // 😢 +} + +interface IReaction extends BaseModel { + /** + * Post that was "reacted" to. + */ + post: PopulatedDoc; + + /** + * Type of the reaction, which corresponds to an emoji, as seen above. + * + * @default ReactionType.HEART + */ + type: ReactionType; + + /** + * User that made the reaction. + */ + user: PopulatedDoc; +} + +export type ReactionDocument = Document<{}, {}, IReaction> & IReaction; + +const reactionSchema: Schema = new Schema( + { + post: { ref: Model.POST, required: true, type: ID }, + type: { default: ReactionType.HEART, required: true, type: String }, + user: { ref: Model.USER, required: true, type: ID } + }, + { timestamps: true } +); + +const Reaction: mongoose.Model = + mongoose.model(Model.REACTION, reactionSchema); + +export default Reaction; diff --git a/src/routes/HelloWorldRoute.ts b/src/routes/HelloWorldRoute.ts index f5f8e01..2c8f864 100644 --- a/src/routes/HelloWorldRoute.ts +++ b/src/routes/HelloWorldRoute.ts @@ -3,7 +3,7 @@ import { RouteMethod } from '../utils/constants'; type HelloWorldResult = { message: string; - podmates: string[]; + podmates: string[]; }; // This is just a "dummy" endpoint that we can send a GET request to, to ensure