pagination on custom routes
This commit is contained in:
parent
e8fae6dcfb
commit
f4acc5799c
7 changed files with 49 additions and 8 deletions
|
@ -34,7 +34,7 @@ export default factories.createCoreService('api::article.article', ({strapi}) =>
|
|||
}
|
||||
},
|
||||
limit: pageSize,
|
||||
offset: (page - 1) * pageSize,
|
||||
page: page,
|
||||
orderBy: { date: 'desc' },
|
||||
});
|
||||
|
||||
|
|
|
@ -31,6 +31,16 @@
|
|||
"type": "boolean",
|
||||
"default": false,
|
||||
"required": true
|
||||
},
|
||||
"numbered_item": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"required": true
|
||||
},
|
||||
"inverse_count": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"required": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ export default factories.createCoreService('api::event.event', ({strapi}) => ({
|
|||
}
|
||||
},
|
||||
limit: pageSize,
|
||||
offset: (page - 1) * pageSize,
|
||||
page: page,
|
||||
orderBy: { date: 'desc' },
|
||||
});
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ export default factories.createCoreService('api::operation.operation', ({strapi}
|
|||
}
|
||||
},
|
||||
limit: pageSize,
|
||||
offset: (page - 1) * pageSize,
|
||||
page: page,
|
||||
orderBy: { date: 'desc' },
|
||||
});
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"name": "Apache 2.0",
|
||||
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
},
|
||||
"x-generation-date": "2024-11-05T07:32:30.586Z"
|
||||
"x-generation-date": "2024-11-05T13:02:13.660Z"
|
||||
},
|
||||
"x-strapi-config": {
|
||||
"plugins": [
|
||||
|
@ -6444,7 +6444,9 @@
|
|||
"reference",
|
||||
"collection",
|
||||
"image_item",
|
||||
"date_list"
|
||||
"date_list",
|
||||
"numbered_item",
|
||||
"inverse_count"
|
||||
],
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -6460,6 +6462,12 @@
|
|||
"date_list": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"numbered_item": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"inverse_count": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"locale": {
|
||||
"type": "string"
|
||||
},
|
||||
|
@ -6522,7 +6530,9 @@
|
|||
"reference",
|
||||
"collection",
|
||||
"image_item",
|
||||
"date_list"
|
||||
"date_list",
|
||||
"numbered_item",
|
||||
"inverse_count"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
|
@ -6543,6 +6553,12 @@
|
|||
"date_list": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"numbered_item": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"inverse_count": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
|
@ -6855,6 +6871,12 @@
|
|||
"date_list": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"numbered_item": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"inverse_count": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
import type { Core } from '@strapi/strapi';
|
||||
import { UID } from '@strapi/types';
|
||||
import { contentTypes } from '@strapi/utils';
|
||||
import path from 'path';
|
||||
import pluralize from 'pluralize';
|
||||
|
||||
interface Options {
|
||||
|
@ -94,13 +95,15 @@ export default (config, { strapi }: { strapi: Core.Strapi }) => {
|
|||
if (ctx.request.url.startsWith('/api/') && ctx.request.method === 'GET' && !ctx.query.populate) {
|
||||
strapi.log.info('Using custom Dynamic-Zone population Middleware...');
|
||||
|
||||
const pathSegment = extractPathSegment(ctx.request.url);
|
||||
let pathSegment = extractPathSegment(ctx.request.url);
|
||||
if(ctx.request.url.startsWith('/api/custom/')) {
|
||||
pathSegment = ctx.request.url.split("/")[3]
|
||||
}
|
||||
const uid = getModelUID(pathSegment);
|
||||
|
||||
// @ts-ignores
|
||||
try {
|
||||
ctx.query.populate = getDeepPopulate(uid);
|
||||
console.log(JSON.stringify(ctx.query.populate))
|
||||
} catch (error) {
|
||||
console.error(`Error in deepPopulate middleware for path ${pathSegment}:`, error);
|
||||
// Continue without population if there's an error
|
||||
|
|
6
types/generated/contentTypes.d.ts
vendored
6
types/generated/contentTypes.d.ts
vendored
|
@ -429,12 +429,18 @@ export interface ApiCollectionLookupCollectionLookup
|
|||
image_item: Schema.Attribute.Boolean &
|
||||
Schema.Attribute.Required &
|
||||
Schema.Attribute.DefaultTo<false>;
|
||||
inverse_count: Schema.Attribute.Boolean &
|
||||
Schema.Attribute.Required &
|
||||
Schema.Attribute.DefaultTo<false>;
|
||||
locale: Schema.Attribute.String & Schema.Attribute.Private;
|
||||
localizations: Schema.Attribute.Relation<
|
||||
'oneToMany',
|
||||
'api::collection-lookup.collection-lookup'
|
||||
> &
|
||||
Schema.Attribute.Private;
|
||||
numbered_item: Schema.Attribute.Boolean &
|
||||
Schema.Attribute.Required &
|
||||
Schema.Attribute.DefaultTo<false>;
|
||||
publishedAt: Schema.Attribute.DateTime;
|
||||
reference: Schema.Attribute.String &
|
||||
Schema.Attribute.Required &
|
||||
|
|
Loading…
Reference in a new issue