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,
|
limit: pageSize,
|
||||||
offset: (page - 1) * pageSize,
|
page: page,
|
||||||
orderBy: { date: 'desc' },
|
orderBy: { date: 'desc' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,16 @@
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false,
|
"default": false,
|
||||||
"required": true
|
"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,
|
limit: pageSize,
|
||||||
offset: (page - 1) * pageSize,
|
page: page,
|
||||||
orderBy: { date: 'desc' },
|
orderBy: { date: 'desc' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ export default factories.createCoreService('api::operation.operation', ({strapi}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
limit: pageSize,
|
limit: pageSize,
|
||||||
offset: (page - 1) * pageSize,
|
page: page,
|
||||||
orderBy: { date: 'desc' },
|
orderBy: { date: 'desc' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
"name": "Apache 2.0",
|
"name": "Apache 2.0",
|
||||||
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
|
"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": {
|
"x-strapi-config": {
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
@ -6444,7 +6444,9 @@
|
||||||
"reference",
|
"reference",
|
||||||
"collection",
|
"collection",
|
||||||
"image_item",
|
"image_item",
|
||||||
"date_list"
|
"date_list",
|
||||||
|
"numbered_item",
|
||||||
|
"inverse_count"
|
||||||
],
|
],
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -6460,6 +6462,12 @@
|
||||||
"date_list": {
|
"date_list": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"numbered_item": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"inverse_count": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"locale": {
|
"locale": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
@ -6522,7 +6530,9 @@
|
||||||
"reference",
|
"reference",
|
||||||
"collection",
|
"collection",
|
||||||
"image_item",
|
"image_item",
|
||||||
"date_list"
|
"date_list",
|
||||||
|
"numbered_item",
|
||||||
|
"inverse_count"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
|
@ -6543,6 +6553,12 @@
|
||||||
"date_list": {
|
"date_list": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"numbered_item": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"inverse_count": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"createdAt": {
|
"createdAt": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "date-time"
|
"format": "date-time"
|
||||||
|
@ -6855,6 +6871,12 @@
|
||||||
"date_list": {
|
"date_list": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"numbered_item": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"inverse_count": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"createdAt": {
|
"createdAt": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"format": "date-time"
|
"format": "date-time"
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import type { Core } from '@strapi/strapi';
|
import type { Core } from '@strapi/strapi';
|
||||||
import { UID } from '@strapi/types';
|
import { UID } from '@strapi/types';
|
||||||
import { contentTypes } from '@strapi/utils';
|
import { contentTypes } from '@strapi/utils';
|
||||||
|
import path from 'path';
|
||||||
import pluralize from 'pluralize';
|
import pluralize from 'pluralize';
|
||||||
|
|
||||||
interface Options {
|
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) {
|
if (ctx.request.url.startsWith('/api/') && ctx.request.method === 'GET' && !ctx.query.populate) {
|
||||||
strapi.log.info('Using custom Dynamic-Zone population Middleware...');
|
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);
|
const uid = getModelUID(pathSegment);
|
||||||
|
|
||||||
// @ts-ignores
|
// @ts-ignores
|
||||||
try {
|
try {
|
||||||
ctx.query.populate = getDeepPopulate(uid);
|
ctx.query.populate = getDeepPopulate(uid);
|
||||||
console.log(JSON.stringify(ctx.query.populate))
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error in deepPopulate middleware for path ${pathSegment}:`, error);
|
console.error(`Error in deepPopulate middleware for path ${pathSegment}:`, error);
|
||||||
// Continue without population if there's an 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 &
|
image_item: Schema.Attribute.Boolean &
|
||||||
Schema.Attribute.Required &
|
Schema.Attribute.Required &
|
||||||
Schema.Attribute.DefaultTo<false>;
|
Schema.Attribute.DefaultTo<false>;
|
||||||
|
inverse_count: Schema.Attribute.Boolean &
|
||||||
|
Schema.Attribute.Required &
|
||||||
|
Schema.Attribute.DefaultTo<false>;
|
||||||
locale: Schema.Attribute.String & Schema.Attribute.Private;
|
locale: Schema.Attribute.String & Schema.Attribute.Private;
|
||||||
localizations: Schema.Attribute.Relation<
|
localizations: Schema.Attribute.Relation<
|
||||||
'oneToMany',
|
'oneToMany',
|
||||||
'api::collection-lookup.collection-lookup'
|
'api::collection-lookup.collection-lookup'
|
||||||
> &
|
> &
|
||||||
Schema.Attribute.Private;
|
Schema.Attribute.Private;
|
||||||
|
numbered_item: Schema.Attribute.Boolean &
|
||||||
|
Schema.Attribute.Required &
|
||||||
|
Schema.Attribute.DefaultTo<false>;
|
||||||
publishedAt: Schema.Attribute.DateTime;
|
publishedAt: Schema.Attribute.DateTime;
|
||||||
reference: Schema.Attribute.String &
|
reference: Schema.Attribute.String &
|
||||||
Schema.Attribute.Required &
|
Schema.Attribute.Required &
|
||||||
|
|
Loading…
Reference in a new issue