createApp.js 704 B

123456789101112131415161718192021222324252627282930313233
  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 (req.file) {
  12. _body.icon = req.file.filename;
  13. }
  14. if (pinAppsByDefault) {
  15. app = await App.create({
  16. ..._body,
  17. isPinned: true,
  18. });
  19. } else {
  20. app = await App.create(req.body);
  21. }
  22. res.status(201).json({
  23. success: true,
  24. data: app,
  25. });
  26. });
  27. module.exports = createApp;