Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/routes/CreateReactionRoute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TestUtils from '../utils/TestUtils';
* npm run test CreateReaction
* - Delete this comment.
*/
describe.skip('POST /posts/:id/reactions', () => {
describe('POST /posts/:id/reactions', () => {
let post: PostDocument = null;

beforeAll(async () => {
Expand Down
23 changes: 18 additions & 5 deletions src/routes/CreateReactionRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export default class CreateReactionRoute extends BaseRoute<ReactionDocument> {
* - Fill in the path string with the appropriate path to this endpoint.
* - Delete this comment.
*/
authenticated: false,
method: null,
path: '/'
authenticated: true,
method: RouteMethod.POST,
path: '/posts/:id/reactions'
});
}

Expand Down Expand Up @@ -60,10 +60,23 @@ export default class CreateReactionRoute extends BaseRoute<ReactionDocument> {
async content(req: CreateReactionRequest): Promise<ReactionDocument> {
// TODO: (16.03) Get the reaction type from the request body and the post
// id from the request paramters.
try {
const { id } = req.params;
const { type } = req.body;
// TODO: (16.03) Create the reaction and associate it with the logged-in user.

// TODO: (16.03) Create the reaction and associate it with the logged-in user.
const reaction: ReactionDocument = await Reaction.create({
post: id,
type,
user: req.user
});

return reaction;
} catch (e) {
console.log(e);
return e;
}

// TODO: (16.03) Return the reaction!
return null;
}
}