mirror of
https://github.com/pawelmalak/flame.git
synced 2026-03-06 20:43:13 +08:00
Split apps controllers into separate files
This commit is contained in:
35
controllers/apps/updateApp.js
Normal file
35
controllers/apps/updateApp.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const asyncWrapper = require('../../middleware/asyncWrapper');
|
||||
const App = require('../../models/App');
|
||||
|
||||
// @desc Update app
|
||||
// @route PUT /api/apps/:id
|
||||
// @access Public
|
||||
const updateApp = asyncWrapper(async (req, res, next) => {
|
||||
let app = await App.findOne({
|
||||
where: { id: req.params.id },
|
||||
});
|
||||
|
||||
if (!app) {
|
||||
return next(
|
||||
new ErrorResponse(
|
||||
`App with the id of ${req.params.id} was not found`,
|
||||
404
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
let _body = { ...req.body };
|
||||
|
||||
if (req.file) {
|
||||
_body.icon = req.file.filename;
|
||||
}
|
||||
|
||||
app = await app.update(_body);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
data: app,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = updateApp;
|
||||
Reference in New Issue
Block a user