updateApp.js 687 B

1234567891011121314151617181920212223242526272829303132333435
  1. const asyncWrapper = require('../../middleware/asyncWrapper');
  2. const App = require('../../models/App');
  3. // @desc Update app
  4. // @route PUT /api/apps/:id
  5. // @access Public
  6. const updateApp = asyncWrapper(async (req, res, next) => {
  7. let app = await App.findOne({
  8. where: { id: req.params.id },
  9. });
  10. if (!app) {
  11. return next(
  12. new ErrorResponse(
  13. `App with the id of ${req.params.id} was not found`,
  14. 404
  15. )
  16. );
  17. }
  18. let _body = { ...req.body };
  19. if (req.file) {
  20. _body.icon = req.file.filename;
  21. }
  22. app = await app.update(_body);
  23. res.status(200).json({
  24. success: true,
  25. data: app,
  26. });
  27. });
  28. module.exports = updateApp;