createApp.js 765 B

12345678910111213141516171819202122232425262728293031323334353637
  1. const asyncWrapper = require('../../middleware/asyncWrapper');
  2. const App = require('../../models/App');
  3. const loadConfig = require('../../utils/loadConfig');
  4. // @desc Create new app
  5. // @route POST /api/apps
  6. // @access Public
  7. const createApp = asyncWrapper(async (req, res, next) => {
  8. const { pinAppsByDefault } = await loadConfig();
  9. let app;
  10. let _body = { ...req.body };
  11. if (_body.icon) {
  12. _body.icon = _body.icon.trim();
  13. }
  14. if (req.file) {
  15. _body.icon = req.file.filename;
  16. }
  17. if (pinAppsByDefault) {
  18. app = await App.create({
  19. ..._body,
  20. isPinned: true,
  21. });
  22. } else {
  23. app = await App.create(req.body);
  24. }
  25. res.status(201).json({
  26. success: true,
  27. data: app,
  28. });
  29. });
  30. module.exports = createApp;