This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from soulsam480/dev
Features and fixes
- Loading branch information
Showing
35 changed files
with
1,360 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
"author": "soulsam480 <[email protected]>", | ||
"private": true, | ||
"scripts": { | ||
"dev": "ts-node-dev --respawn --files -- src/index.ts", | ||
"dev": "ts-node-dev --respawn --transpile-only --ignore-watch node_modules --files -- src/index.ts", | ||
"build": "rm -rf dist && yarn && tsc && tsc-alias", | ||
"build:swagger": "node swagger.js", | ||
"build:types": "tsc --declaration --emitDeclarationOnly --declarationDir ./types && tsc-alias", | ||
|
@@ -24,8 +24,7 @@ | |
"@types/swagger-jsdoc": "^6.0.1", | ||
"@types/swagger-ui-express": "^4.1.3", | ||
"ts-node-dev": "^1.1.8", | ||
"tsconfig-paths": "^3.10.1", | ||
"typescript": "4.3.5" | ||
"tsconfig-paths": "^3.10.1" | ||
}, | ||
"dependencies": { | ||
"@typegoose/typegoose": "^8.2.0", | ||
|
@@ -46,7 +45,6 @@ | |
}, | ||
"workspaces": { | ||
"nohoist": [ | ||
"**/typescript/**/**", | ||
"**/mongoose/**" | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import { createRoute } from 'dango-core'; | ||
import { DocumentDefinition } from 'mongoose'; | ||
|
||
import { | ||
createCommentOnPost, | ||
createReplyOnPost, | ||
getCommentsForPost, | ||
getRepliesForComment, | ||
likeOnComment, | ||
likeOnReply, | ||
unLikeOnComment, | ||
unLikeOnReply, | ||
} from 'src/services/comments'; | ||
import { formatResponse } from 'src/utils/helpers'; | ||
import { Comment } from 'src/entities/post'; | ||
|
||
export const getCommentsByPostId = createRoute< | ||
any, | ||
{ id: string }, | ||
{ cursor: string; limit: string } | ||
>({ | ||
path: '/:id/comments', | ||
method: 'get', | ||
handler: async (_, res, __, { id }, { cursor: pagination_cursor, limit: pagination_limit }) => { | ||
try { | ||
const cursor: number = parseInt(pagination_cursor); | ||
const limit: number = parseInt(pagination_limit) || 10; | ||
|
||
const comments = await getCommentsForPost(id, cursor, limit); | ||
|
||
res.json(comments); | ||
} catch (error) { | ||
console.log(error); | ||
res.sendError(500, error); | ||
} | ||
}, | ||
}); | ||
|
||
export const addCommentByPostId = createRoute< | ||
{ comment: DocumentDefinition<Comment> }, | ||
{ id: string } | ||
>({ | ||
path: '/:id/comments', | ||
method: 'post', | ||
handler: async ({ userId }, res, { comment }, { id }) => { | ||
try { | ||
await createCommentOnPost(id, { ...comment, user: userId as string }); | ||
|
||
res.sendStatus(200); | ||
} catch (error) { | ||
console.log(error); | ||
res.sendError(500, error); | ||
} | ||
}, | ||
}); | ||
|
||
export const getRepliesByCommentId = createRoute<any, { id: string; commentId: string }>({ | ||
path: '/:id/comments/:commentId', | ||
method: 'get', | ||
handler: async (_, res, __, { id, commentId }) => { | ||
try { | ||
const replies = await getRepliesForComment(id, commentId); | ||
|
||
res.json(formatResponse(replies)); | ||
} catch (error) { | ||
console.log(error); | ||
res.sendError(500, error); | ||
} | ||
}, | ||
}); | ||
|
||
export const addReplyByCommentId = createRoute< | ||
{ comment: DocumentDefinition<Comment> }, | ||
{ id: string; commentId: string } | ||
>({ | ||
path: '/:id/comments/:commentId', | ||
method: 'post', | ||
handler: async ({ userId }, res, { comment }, { id, commentId }) => { | ||
try { | ||
await createReplyOnPost(id, commentId, { ...comment, user: userId as string }); | ||
|
||
res.sendStatus(200); | ||
} catch (error) { | ||
console.log(error); | ||
res.sendError(500, error); | ||
} | ||
}, | ||
}); | ||
|
||
export const likeComment = createRoute<any, { id: string; commentId: string }>({ | ||
path: '/:id/comments/:commentId/like', | ||
method: 'post', | ||
handler: async ({ userId }, res, _, { id, commentId }) => { | ||
try { | ||
await likeOnComment(id, commentId, userId as string); | ||
|
||
res.sendStatus(200); | ||
} catch (error) { | ||
console.log(error); | ||
res.sendError(500, error); | ||
} | ||
}, | ||
}); | ||
|
||
export const unLikeComment = createRoute<any, { id: string; commentId: string }>({ | ||
path: '/:id/comments/:commentId/unlike', | ||
method: 'post', | ||
handler: async ({ userId }, res, _, { id, commentId }) => { | ||
try { | ||
await unLikeOnComment(id, commentId, userId as string); | ||
|
||
res.sendStatus(200); | ||
} catch (error) { | ||
console.log(error); | ||
res.sendError(500, error); | ||
} | ||
}, | ||
}); | ||
|
||
export const likeReply = createRoute<any, { id: string; commentId: string; replyId: string }>({ | ||
path: '/:id/comments/:commentId/replies/:replyId/like', | ||
method: 'post', | ||
handler: async ({ userId }, res, _, { commentId, id, replyId }) => { | ||
try { | ||
await likeOnReply(id, commentId, replyId, userId as string); | ||
|
||
res.sendStatus(200); | ||
} catch (error) { | ||
console.log(error); | ||
res.sendError(500, error); | ||
} | ||
}, | ||
}); | ||
|
||
export const unLikeReply = createRoute<any, { id: string; commentId: string; replyId: string }>({ | ||
path: '/:id/comments/:commentId/replies/:replyId/unlike', | ||
method: 'post', | ||
handler: async ({ userId }, res, _, { commentId, id, replyId }) => { | ||
try { | ||
await unLikeOnReply(id, commentId, replyId, userId as string); | ||
|
||
res.sendStatus(200); | ||
} catch (error) { | ||
console.log(error); | ||
res.sendError(500, error); | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.