2021-10-22 01:42:27 +03:00
|
|
|
const asyncWrapper = require('../../middleware/asyncWrapper');
|
|
|
|
const App = require('../../models/App');
|
|
|
|
const loadConfig = require('../../utils/loadConfig');
|
|
|
|
|
|
|
|
// @desc Create new app
|
|
|
|
// @route POST /api/apps
|
|
|
|
// @access Public
|
|
|
|
const createApp = asyncWrapper(async (req, res, next) => {
|
|
|
|
const { pinAppsByDefault } = await loadConfig();
|
|
|
|
|
2021-11-18 15:05:32 +03:00
|
|
|
let body = { ...req.body };
|
2021-11-15 18:34:12 +03:00
|
|
|
|
2021-11-18 15:05:32 +03:00
|
|
|
if (body.icon) {
|
|
|
|
body.icon = body.icon.trim();
|
2021-11-15 18:34:12 +03:00
|
|
|
}
|
2021-10-22 01:42:27 +03:00
|
|
|
|
|
|
|
if (req.file) {
|
2021-11-18 15:05:32 +03:00
|
|
|
body.icon = req.file.filename;
|
2021-10-22 01:42:27 +03:00
|
|
|
}
|
|
|
|
|
2021-11-18 15:05:32 +03:00
|
|
|
const app = await App.create({
|
|
|
|
...body,
|
|
|
|
isPinned: pinAppsByDefault,
|
|
|
|
});
|
2021-10-22 01:42:27 +03:00
|
|
|
|
|
|
|
res.status(201).json({
|
|
|
|
success: true,
|
|
|
|
data: app,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = createApp;
|