2021-10-21 22:42:27 +00: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 12:05:32 +00:00
|
|
|
let body = { ...req.body };
|
2021-11-15 15:34:12 +00:00
|
|
|
|
2021-11-18 12:05:32 +00:00
|
|
|
if (body.icon) {
|
|
|
|
body.icon = body.icon.trim();
|
2021-11-15 15:34:12 +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
|
|
|
const app = await App.create({
|
|
|
|
...body,
|
|
|
|
isPinned: pinAppsByDefault,
|
|
|
|
});
|
2021-10-21 22:42:27 +00:00
|
|
|
|
|
|
|
res.status(201).json({
|
|
|
|
success: true,
|
|
|
|
data: app,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = createApp;
|