mirror of
https://github.com/directus/directus.git
synced 2026-01-27 02:37:56 -05:00
@@ -31,6 +31,10 @@ const sanitizeQuery: RequestHandler = (req, res, next) => {
|
||||
query.offset = sanitizeOffset(req.query.offset);
|
||||
}
|
||||
|
||||
if (req.query.single) {
|
||||
query.single = sanitizeSingle(req.query.single);
|
||||
}
|
||||
|
||||
res.locals.query = query;
|
||||
return next();
|
||||
};
|
||||
@@ -79,3 +83,7 @@ function sanitizeLimit(rawLimit: any) {
|
||||
function sanitizeOffset(rawOffset: any) {
|
||||
return Number(rawOffset);
|
||||
}
|
||||
|
||||
function sanitizeSingle(rawSingle: any) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export const readItems = async (collection: string, query: Query = {}) => {
|
||||
});
|
||||
}
|
||||
|
||||
if (query.limit) {
|
||||
if (query.limit && !query.offset) {
|
||||
dbQuery.limit(query.limit);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,17 @@ export const readItems = async (collection: string, query: Query = {}) => {
|
||||
dbQuery.offset(query.offset);
|
||||
}
|
||||
|
||||
return await dbQuery;
|
||||
if (query.single) {
|
||||
dbQuery.limit(1);
|
||||
}
|
||||
|
||||
const records = await dbQuery;
|
||||
|
||||
if (query.single) {
|
||||
return records[0];
|
||||
}
|
||||
|
||||
return records;
|
||||
};
|
||||
|
||||
export const readItem = async (collection: string, pk: number | string, query: Query = {}) => {
|
||||
|
||||
@@ -5,6 +5,7 @@ export type Query = {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
page?: number;
|
||||
single?: boolean;
|
||||
};
|
||||
|
||||
export type Sort = {
|
||||
|
||||
Reference in New Issue
Block a user