mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Support meta in most endpoints
This commit is contained in:
@@ -3,6 +3,7 @@ import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import ActivityService from '../services/activity';
|
||||
import MetaService from '../services/meta';
|
||||
import { Action } from '../types';
|
||||
|
||||
const router = express.Router();
|
||||
@@ -13,10 +14,14 @@ router.get(
|
||||
sanitizeQuery,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new ActivityService({ accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
|
||||
const records = await service.readByQuery(req.sanitizedQuery);
|
||||
const meta = await metaService.getMetaForQuery(req.collection, req.sanitizedQuery);
|
||||
|
||||
return res.json({
|
||||
data: records || null,
|
||||
meta,
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
@@ -3,6 +3,7 @@ import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import CollectionsService from '../services/collections';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -24,9 +25,12 @@ router.get(
|
||||
useCollection('directus_collections'),
|
||||
asyncHandler(async (req, res) => {
|
||||
const collectionsService = new CollectionsService({ accountability: req.accountability });
|
||||
const collections = await collectionsService.readByQuery();
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
|
||||
res.json({ data: collections || null });
|
||||
const collections = await collectionsService.readByQuery();
|
||||
const meta = await metaService.getMetaForQuery(req.collection, {});
|
||||
|
||||
res.json({ data: collections || null, meta });
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import FoldersService from '../services/folders';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -24,9 +25,12 @@ router.get(
|
||||
sanitizeQuery,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new FoldersService({ accountability: req.accountability });
|
||||
const records = await service.readByQuery(req.sanitizedQuery);
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
|
||||
return res.json({ data: records || null });
|
||||
const records = await service.readByQuery(req.sanitizedQuery);
|
||||
const meta = await metaService.getMetaForQuery(req.collection, req.sanitizedQuery);
|
||||
|
||||
return res.json({ data: records || null, meta });
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import PermissionsService from '../services/permissions';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -24,8 +25,12 @@ router.get(
|
||||
sanitizeQuery,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new PermissionsService({ accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
|
||||
const item = await service.readByQuery(req.sanitizedQuery);
|
||||
return res.json({ data: item || null });
|
||||
const meta = await metaService.getMetaForQuery(req.collection, req.sanitizedQuery);
|
||||
|
||||
return res.json({ data: item || null, meta });
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import PresetsService from '../services/presets';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -24,9 +25,12 @@ router.get(
|
||||
sanitizeQuery,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new PresetsService({ accountability: req.accountability });
|
||||
const records = await service.readByQuery(req.sanitizedQuery);
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
|
||||
return res.json({ data: records || null });
|
||||
const records = await service.readByQuery(req.sanitizedQuery);
|
||||
const meta = await metaService.getMetaForQuery(req.collection, req.sanitizedQuery);
|
||||
|
||||
return res.json({ data: records || null, meta });
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import RelationsService from '../services/relations';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -24,8 +25,12 @@ router.get(
|
||||
sanitizeQuery,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new RelationsService({ accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
|
||||
const records = await service.readByQuery(req.sanitizedQuery);
|
||||
return res.json({ data: records || null });
|
||||
const meta = await metaService.getMetaForQuery(req.collection, req.sanitizedQuery);
|
||||
|
||||
return res.json({ data: records || null, meta });
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import RevisionsService from '../services/revisions';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -12,8 +13,12 @@ router.get(
|
||||
sanitizeQuery,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new RevisionsService({ accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
|
||||
const records = await service.readByQuery(req.sanitizedQuery);
|
||||
return res.json({ data: records || null });
|
||||
const meta = await metaService.getMetaForQuery(req.collection, req.sanitizedQuery);
|
||||
|
||||
return res.json({ data: records || null, meta });
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import RolesService from '../services/roles';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -24,8 +25,12 @@ router.get(
|
||||
sanitizeQuery,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new RolesService({ accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
|
||||
const records = await service.readByQuery(req.sanitizedQuery);
|
||||
return res.json({ data: records || null });
|
||||
const meta = await metaService.getMetaForQuery(req.collection, req.sanitizedQuery);
|
||||
|
||||
return res.json({ data: records || null, meta });
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import Joi from 'joi';
|
||||
import { InvalidPayloadException, InvalidCredentialsException } from '../exceptions';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import UsersService from '../services/users';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -26,8 +27,12 @@ router.get(
|
||||
sanitizeQuery,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new UsersService({ accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
|
||||
const item = await service.readByQuery(req.sanitizedQuery);
|
||||
return res.json({ data: item || null });
|
||||
const meta = await metaService.getMetaForQuery(req.collection, req.sanitizedQuery);
|
||||
|
||||
return res.json({ data: item || null, meta });
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import WebhooksService from '../services/webhooks';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -24,9 +25,12 @@ router.get(
|
||||
sanitizeQuery,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new WebhooksService({ accountability: req.accountability });
|
||||
const records = await service.readByQuery(req.sanitizedQuery);
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
|
||||
return res.json({ data: records || null });
|
||||
const records = await service.readByQuery(req.sanitizedQuery);
|
||||
const meta = await metaService.getMetaForQuery(req.collection, req.sanitizedQuery);
|
||||
|
||||
return res.json({ data: records || null, meta });
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user