Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
KSZK
DevTeam
kszkepzes
Backend
Commits
f25aa298
Commit
f25aa298
authored
Aug 03, 2020
by
rlacko
💬
Browse files
comment documentation
parent
96c1f46f
Pipeline
#4714
passed with stages
in 1 minute and 48 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/resources/comment/commentControllers.js
View file @
f25aa298
const
{
crudControllers
}
=
require
(
'
../../utils/crud
'
)
const
{
pick
}
=
require
(
'
lodash
'
)
const
{
Comment
}
=
require
(
'
./commentModel
'
)
const
{
Solution
}
=
require
(
'
../solution/solutionModel
'
)
const
{
Task
}
=
require
(
'
../task/taskModel
'
)
const
{
Attendance
}
=
require
(
'
../attendance/attendanceModel
'
)
const
{
Activity
}
=
require
(
'
../activity/activityModel
'
)
const
{
omit
,
pick
}
=
require
(
'
lodash
'
)
const
pickedKeys
=
[
'
_id
'
,
...
...
@@ -119,10 +120,23 @@ exports.default.getMany = async (req, res) => {
exports
.
default
.
createOne
=
async
(
req
,
res
)
=>
{
try
{
if
(
req
.
user
.
role
!=
'
mentor
'
||
!
req
.
body
.
creator
)
req
.
body
.
creator
=
req
.
user
.
schacc
var
comment
=
await
Comment
.
create
({
...
req
.
body
,
})
// Add to parent
let
updateParent
=
await
getParentModel
(
comment
).
findById
(
comment
.
parentId
)
if
(
updateParent
.
comments
.
indexOf
(
comment
.
_id
)
==
-
1
)
{
updateParent
.
comments
.
push
(
comment
.
_id
)
try
{
await
updateParent
.
save
()
}
catch
(
error
)
{
await
Comment
.
findByIdAndRemove
(
comment
.
_id
)
}
}
comment
=
await
comment
.
populate
(
'
_creator
'
,
'
fullName nickName schacc
'
)
.
execPopulate
()
...
...
src/resources/comment/commentDocs.yml
0 → 100644
View file @
f25aa298
openapi
:
'
3.0.2'
info
:
title
:
'
Comment
Endpoint'
version
:
'
1.0'
paths
:
/comment
:
get
:
tags
:
-
'
Comment'
summary
:
'
Get
a
List
of
comments'
description
:
'
This
can
only
be
get
by
a
mentor.'
operationId
:
'
getAllComments'
responses
:
'
200'
:
description
:
OK
content
:
application/json
:
schema
:
type
:
'
array'
items
:
$ref
:
'
#/components/schemas/Comment'
post
:
tags
:
-
'
Comment'
summary
:
'
Create
a
comment'
description
:
'
Only
logged
in
users
can
create
a
comment.
The
creator
only
can
be
set
by
Mentor.
By
default
the
creator
is
own
user.
Automatically
adds
itself
to
parent
object.'
operationId
:
'
createComment'
requestBody
:
content
:
application/json
:
schema
:
$ref
:
'
#/components/schemas/Comment'
responses
:
'
200'
:
description
:
OK
content
:
application/json
:
schema
:
$ref
:
'
#/components/schemas/Comment'
/comment/id/{id}
:
get
:
tags
:
-
'
Comment'
summary
:
'
Get
a
comment
by
ID'
description
:
'
If
not
mentor
only
own
comment
or
comment
on
own
solution
can
be
get.'
operationId
:
'
getComment'
responses
:
'
200'
:
description
:
OK
content
:
application/json
:
schema
:
$ref
:
'
#/components/schemas/Comment'
delete
:
tags
:
-
'
Comment'
summary
:
'
Delete
a
comment
by
ID'
description
:
'
Only
logged
in
users
can
delete
a
comment.
To
delete
has
to
be
the
owner
or
mentor.'
operationId
:
'
deleteComment'
responses
:
'
200'
:
description
:
OK
content
:
application/json
:
schema
:
$ref
:
'
#/components/schemas/Comment'
put
:
tags
:
-
'
Comment'
summary
:
'
Update
a
comment
by
ID'
description
:
'
Only
logged
in
users
can
update
a
comment.
To
update
has
to
be
the
owner
or
mentor.'
operationId
:
'
updateOneComment'
requestBody
:
content
:
application/json
:
schema
:
$ref
:
'
#/components/schemas/Comment'
responses
:
'
200'
:
description
:
OK
content
:
application/json
:
schema
:
$ref
:
'
#/components/schemas/Groups'
components
:
schemas
:
Comment
:
type
:
object
properties
:
parentId
:
type
:
string
description
:
ObjectId of the object that has the comment
parentType
:
type
:
string
enum
:
-
'
solution'
-
'
task'
-
'
attendance'
-
'
activity'
description
:
Name of the object that has the comment
creator
:
type
:
string
description
:
Schacc of the creator. Default is own user
text
:
type
:
string
isAnonim
:
type
:
boolean
default
:
false
createdAt
:
type
:
string
format
:
date-time
updatedAt
:
type
:
string
format
:
date-time
required
:
-
parentId
-
parentType
-
creator
-
text
-
isAnonim
src/resources/comment/commentModel.js
View file @
f25aa298
...
...
@@ -8,12 +8,13 @@ const CommentSchema = new mongoose.Schema(
required
:
true
,
},
parentType
:
{
type
:
mongoose
.
Schema
.
Types
.
String
,
type
:
String
,
required
:
true
,
enum
:
[
'
solution
'
,
'
task
'
,
'
attendance
'
,
'
activity
'
],
},
creator
:
{
type
:
String
,
required
:
true
,
},
text
:
{
type
:
String
,
...
...
src/resources/comment/commentRouter.js
View file @
f25aa298
...
...
@@ -4,13 +4,13 @@ const { isLoggedIn, isMentor } = require('../../middlewares/auth')
const
router
=
Router
()
// /api/
item
// /api/
v1/comment
router
.
route
(
'
/
'
)
.
get
(
isLoggedIn
,
isMentor
,
controllers
.
default
.
getMany
)
.
post
(
isLoggedIn
,
controllers
.
default
.
createOne
)
// /api/
item
/:id
// /api/
v1/comment/id
/:id
router
.
route
(
'
/id/:id
'
)
.
get
(
isLoggedIn
,
controllers
.
default
.
getOne
)
...
...
src/resources/solution/solutionControllers.js
View file @
f25aa298
...
...
@@ -49,7 +49,7 @@ exports.default.createOne = async (req, res) => {
}
if
(
task
.
solutions
.
indexOf
(
solution
.
_id
)
==
-
1
)
{
task
.
solutions
.
push
(
solution
.
_id
)
task
.
save
()
await
task
.
save
()
}
let
retSolution
=
await
Solution
.
findById
({
_id
:
solution
.
_id
})
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment