- Install packages with
npm i
- Create
.env
file withPORT
andMONGO_SERVER
values corresponding to your environment. - Start sever with
npm start
npm test
POST comments
Content-Type: application/json
{
"_id":"000000000000000000000004",
"body": "Last reply to the first comment.",
"parentId": "000000000000000000000001",
"replyTo": "000000000000000000000001",
"threadId": "acd88360-e772-11ea-bc06-6ba89fdab63e",
"createdAt": "2020-11-18T10:11Z"
}
GET comments/{threadId}?skip=&limit=
Content-Type: application/json
GET comments/{threadId}/{commentId}
Content-Type: application/json
PATCH comments/{threadId}/{commentId}
Content-Type: application/json
{
"status": "declined" | "approved"
}
- I believe these comments should be swapped in terms of parentId.
_id
orid
field name. Such contracts should be strictly defined across the entire project.- ThreadId is UUID, but CommentId is ObjectId. I'd suggest to use UUIDs everywhere.
- Nest and the project structure is okay. And because it is very small I don't really see the need to change anything right now.
@Type(() => Number)
workaround took me a while, looks like number transforms are still not fixed.- Cannot really separate business and database logic e.g. with
declined
- The solution should scale well with mongo replicas because we're sending ton of db requests.
- Also caching could be introduced. E.g. it should be possible to save entire thread tree snapshot at the specific date and then only patch it with the new data.
- Infinite loop possible when getting comment replies
- No auht roles for moderation
- Moderator can only update
status
field toapproved
ordeclined
- Skip & limit query parameters are constrained to
int
- Build an API to get specific comment and all nested replies
- Each comment should have moderation status. Default value for new comments - pending (available statuses: pending, approved, declined)
- Build an API to update moderation status of a comment
- Build an API to retrieve comments per specific thread.
- Endpoint should contain skip & limit parameters.
- Endpoint should return specified limit of root comments and all nested replies to each of root comment.
- Root comments and replies should be sorted. For more datails about sort see the section - Comments sort explanation.
- Comments with declined status should not be returned from this API.
- Replies that are left to comments with declined status should not be returned.
- Add some tests