2021-10-21 22:42:27 +00:00
|
|
|
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
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-18 12:05:32 +00:00
|
|
|
let body = { ...req.body };
|
2021-10-21 22:42:27 +00:00
|
|
|
|
2021-11-18 12:05:32 +00:00
|
|
|
if (body.icon) {
|
|
|
|
body.icon = body.icon.trim();
|
2021-11-12 12:09:33 +00:00
|
|
|
}
|
|
|
|
|
2021-10-21 22:42:27 +00:00
|
|
|
if (req.file) {
|
2021-11-18 12:05:32 +00:00
|
|
|
body.icon = req.file.filename;
|
2021-10-21 22:42:27 +00:00
|
|
|
}
|
|
|
|
|
2021-11-18 12:05:32 +00:00
|
|
|
app = await app.update(body);
|
2021-10-21 22:42:27 +00:00
|
|
|
|
|
|
|
res.status(200).json({
|
|
|
|
success: true,
|
|
|
|
data: app,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = updateApp;
|