Start on sort endpoint

This commit is contained in:
rijkvanzanten
2020-08-21 11:29:49 -06:00
parent 53a951fb65
commit a7e0ebfc11
2 changed files with 85 additions and 0 deletions

View File

@@ -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;