Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 49 additions & 64 deletions src/models/Reaction.ts
Original file line number Diff line number Diff line change
@@ -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<PostDocument>;

/**
* Type of the reaction, which corresponds to an emoji, as seen above.
*
* @default ReactionType.HEART
*/
type: ReactionType;

/**
* User that made the reaction.
*/
user: PopulatedDoc<UserDocument>;
}

export type ReactionDocument = Document<{}, {}, IReaction> & IReaction;

const reactionSchema: Schema<ReactionDocument> = new Schema<ReactionDocument>(
{
/**
* 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<ReactionDocument> =
mongoose.model<ReactionDocument>(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<PostDocument>;

/**
* Type of the reaction, which corresponds to an emoji, as seen above.
*
* @default ReactionType.HEART
*/
type: ReactionType;

/**
* User that made the reaction.
*/
user: PopulatedDoc<UserDocument>;
}

export type ReactionDocument = Document<{}, {}, IReaction> & IReaction;

const reactionSchema: Schema<ReactionDocument> = new Schema<ReactionDocument>(
{
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<ReactionDocument> =
mongoose.model<ReactionDocument>(Model.REACTION, reactionSchema);

export default Reaction;
2 changes: 1 addition & 1 deletion src/routes/HelloWorldRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down