forked from NodeBB/NodeBB
-
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.
- Loading branch information
1 parent
e78c498
commit 083c74e
Showing
6 changed files
with
39 additions
and
31 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const categories = require('../categories'); | ||
const events = require('../events'); | ||
|
||
const categoriesAPI = module.exports; | ||
|
||
categoriesAPI.create = async function (caller, data) { | ||
const response = await categories.create(data); | ||
const categoryObjs = await categories.getCategories([response.cid], caller.uid); | ||
return categoryObjs[0]; | ||
}; | ||
|
||
categoriesAPI.update = async function (caller, data) { | ||
await categories.update(data); | ||
}; | ||
|
||
categoriesAPI.delete = async function (caller, data) { | ||
const name = await categories.getCategoryField(data.cid, 'name'); | ||
await categories.purge(data.cid, caller.uid); | ||
await events.log({ | ||
type: 'category-purge', | ||
uid: caller.uid, | ||
ip: caller.ip, | ||
cid: data.cid, | ||
name: name, | ||
}); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,26 @@ | ||
'use strict'; | ||
|
||
const categories = require('../../categories'); | ||
const events = require('../../events'); | ||
const api = require('../../api'); | ||
|
||
const helpers = require('../helpers'); | ||
|
||
const Categories = module.exports; | ||
|
||
Categories.create = async (req, res) => { | ||
const response = await categories.create(req.body); | ||
const categoryObjs = await categories.getCategories([response.cid]); | ||
helpers.formatApiResponse(200, res, categoryObjs[0]); | ||
const response = await api.categories.create(req, req.body); | ||
helpers.formatApiResponse(200, res, response); | ||
}; | ||
|
||
Categories.update = async (req, res) => { | ||
const payload = {}; | ||
payload[req.params.cid] = req.body; | ||
|
||
await categories.update(payload); | ||
await api.categories.update(req, payload); | ||
const categoryObjs = await categories.getCategories([req.params.cid]); | ||
helpers.formatApiResponse(200, res, categoryObjs[0]); | ||
}; | ||
|
||
Categories.delete = async (req, res) => { | ||
const name = await categories.getCategoryField(req.params.cid, 'name'); | ||
await categories.purge(req.params.cid, req.user.uid); | ||
await events.log({ | ||
type: 'category-purge', | ||
uid: req.user.uid, | ||
ip: req.ip, | ||
cid: req.params.cid, | ||
name: name, | ||
}); | ||
|
||
await api.categories.delete(req, { cid: req.params.cid }); | ||
helpers.formatApiResponse(200, res); | ||
}; |
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