1+ import Comment from '../Models/commentModel.js' ;
12import commentService from '../Service/commentService.js' ;
23// function to check ownership
3- import Comment from '../Models/commentModel.js' ;
44import isResourceOwner from '../helpers/isOwner.js' ;
55
66const commentController = {
77 createComment,
8- deleteComment,
98 getAllComment,
9+ deleteComment,
1010} ;
1111
1212function createComment ( req , res , next ) {
1313 commentService
14- . createComment ( req . user . id , req . params . id , req . body )
14+ . createComment (
15+ req . user . id ,
16+ req . params . id ,
17+ req . body . description ,
18+ req . body . calification ,
19+ )
1520 . then ( ( comment ) => res . json ( comment ) )
1621 . catch ( ( error ) => next ( error ) ) ;
1722}
1823
24+ function getAllComment ( req , res , next ) {
25+ commentService
26+ . getAllComment ( req . query . page , req . query . size , req . params . id )
27+ . then ( ( product ) => res . json ( product ) )
28+ . catch ( ( error ) => next ( error ) ) ;
29+ }
30+
1931function deleteComment ( req , res , next ) {
20- const isOwner = isResourceOwner ( Comment , req . params . commentId , req . user . id ) ;
32+ console . log ( req . params . id ) ;
33+ const isOwner = isResourceOwner ( Comment , req . params . id , req . user . id ) ;
2134 if ( isOwner ) {
2235 commentService
2336 . deleteComment ( req . params . id )
@@ -28,10 +41,4 @@ function deleteComment(req, res, next) {
2841 }
2942}
3043
31- function getAllComment ( req , res , next ) {
32- commentService
33- . getAllComment ( req . query . page , req . query . size )
34- . then ( ( product ) => res . json ( product ) )
35- . catch ( ( error ) => next ( error ) ) ;
36- }
3744export default commentController ;
0 commit comments