|
@@ -185,7 +185,7 @@ module.exports = (crowi) => {
|
|
|
* $ref: '#/components/schemas/Page'
|
|
* $ref: '#/components/schemas/Page'
|
|
|
*/
|
|
*/
|
|
|
router.put('/likes', accessTokenParser, loginRequiredStrictly, csrf, validator.likes, apiV3FormValidator, async(req, res) => {
|
|
router.put('/likes', accessTokenParser, loginRequiredStrictly, csrf, validator.likes, apiV3FormValidator, async(req, res) => {
|
|
|
- const { pageId, bool } = req.body;
|
|
|
|
|
|
|
+ const { pageId, bool: isLiked } = req.body;
|
|
|
|
|
|
|
|
let page;
|
|
let page;
|
|
|
try {
|
|
try {
|
|
@@ -193,7 +193,8 @@ module.exports = (crowi) => {
|
|
|
if (page == null) {
|
|
if (page == null) {
|
|
|
return res.apiv3Err(`Page '${pageId}' is not found or forbidden`);
|
|
return res.apiv3Err(`Page '${pageId}' is not found or forbidden`);
|
|
|
}
|
|
}
|
|
|
- if (bool) {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (isLiked) {
|
|
|
page = await page.like(req.user);
|
|
page = await page.like(req.user);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
@@ -205,17 +206,19 @@ module.exports = (crowi) => {
|
|
|
return res.apiv3Err(err, 500);
|
|
return res.apiv3Err(err, 500);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- try {
|
|
|
|
|
- // global notification
|
|
|
|
|
- await globalNotificationService.fire(GlobalNotificationSetting.EVENT.PAGE_LIKE, page, req.user);
|
|
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
- logger.error('Like notification failed', err);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
const result = { page };
|
|
const result = { page };
|
|
|
result.seenUser = page.seenUsers;
|
|
result.seenUser = page.seenUsers;
|
|
|
- return res.apiv3({ result });
|
|
|
|
|
|
|
+ res.apiv3({ result });
|
|
|
|
|
+
|
|
|
|
|
+ if (isLiked) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // global notification
|
|
|
|
|
+ await globalNotificationService.fire(GlobalNotificationSetting.EVENT.PAGE_LIKE, page, req.user);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ logger.error('Like notification failed', err);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
/**
|