mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Start on sort endpoint
This commit is contained in:
@@ -3,6 +3,9 @@ import asyncHandler from 'express-async-handler';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { InvalidQueryException, InvalidPayloadException } from '../exceptions';
|
||||
import argon2 from 'argon2';
|
||||
import collectionExists from '../middleware/collection-exists';
|
||||
import UtilsService from '../services/utils';
|
||||
import Joi from 'joi';
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -48,4 +51,23 @@ router.post(
|
||||
})
|
||||
);
|
||||
|
||||
const SortSchema = Joi.object({
|
||||
item: Joi.alternatives(Joi.string(), Joi.number()).required(),
|
||||
to: Joi.alternatives(Joi.string(), Joi.number()).required(),
|
||||
});
|
||||
|
||||
router.post(
|
||||
'/sort/:collection',
|
||||
collectionExists,
|
||||
asyncHandler(async (req, res) => {
|
||||
const { error } = SortSchema.validate(req.body);
|
||||
if (error) throw new InvalidPayloadException(error.message);
|
||||
|
||||
const service = new UtilsService({ accountability: req.accountability });
|
||||
await service.sort(req.collection, req.body);
|
||||
|
||||
return res.status(200).end();
|
||||
})
|
||||
)
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user