2021-10-22 00:42:27 +02:00
|
|
|
const asyncWrapper = require('../../middleware/asyncWrapper');
|
|
|
|
const App = require('../../models/App');
|
2021-11-11 16:01:56 +01:00
|
|
|
const ErrorResponse = require('../../utils/ErrorResponse');
|
2021-10-22 00:42:27 +02:00
|
|
|
|
|
|
|
// @desc Reorder apps
|
|
|
|
// @route PUT /api/apps/0/reorder
|
|
|
|
// @access Public
|
|
|
|
const reorderApps = asyncWrapper(async (req, res, next) => {
|
2021-11-11 16:01:56 +01:00
|
|
|
if (!req.isAuthenticated) {
|
|
|
|
return next(new ErrorResponse('Unauthorized', 401));
|
|
|
|
}
|
|
|
|
|
2021-10-22 00:42:27 +02:00
|
|
|
req.body.apps.forEach(async ({ id, orderId }) => {
|
|
|
|
await App.update(
|
|
|
|
{ orderId },
|
|
|
|
{
|
|
|
|
where: { id },
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
res.status(200).json({
|
|
|
|
success: true,
|
|
|
|
data: {},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = reorderApps;
|