diff --git a/src/api/article/services/article.ts b/src/api/article/services/article.ts index 05cc88d..53ddf79 100644 --- a/src/api/article/services/article.ts +++ b/src/api/article/services/article.ts @@ -23,36 +23,25 @@ export default factories.createCoreService('api::article.article', ({strapi}) => const startOfYear = new Date(`${year}-01-01T00:00:00.000Z`); const endOfYear = new Date(`${year}-12-31T23:59:59.999Z`); - const articles = await strapi.query("api::article.article").findMany({ + const articles = await strapi.query("api::article.article").findPage({ filters: { date: { $gte: startOfYear, $lte: endOfYear, }, + publishedAt: { + $ne: null + } }, limit: pageSize, offset: (page - 1) * pageSize, orderBy: { date: 'desc' }, }); - const totalArticles = await strapi.query("api::article.article").count({ - filters: { - date: { - $gte: startOfYear, - $lte: endOfYear, - }, - }, - }); - return { - data: articles, + data: articles.results, meta: { - pagination: { - page, - pageSize, - pageCount: Math.ceil(totalArticles / pageSize), - total: totalArticles, - }, + pagination: articles.pagination }, }; }, diff --git a/src/api/collection-lookup/content-types/collection-lookup/schema.json b/src/api/collection-lookup/content-types/collection-lookup/schema.json index 46fb3a8..e86c6c7 100644 --- a/src/api/collection-lookup/content-types/collection-lookup/schema.json +++ b/src/api/collection-lookup/content-types/collection-lookup/schema.json @@ -13,12 +13,14 @@ "pluginOptions": {}, "attributes": { "reference": { - "type": "uid", - "required": true + "type": "string", + "required": true, + "unique": true }, "collection": { - "type": "uid", - "required": true + "type": "string", + "required": true, + "unique": true }, "image_item": { "type": "boolean", diff --git a/src/api/event/services/event.ts b/src/api/event/services/event.ts index 62879ae..515d88a 100644 --- a/src/api/event/services/event.ts +++ b/src/api/event/services/event.ts @@ -7,11 +7,11 @@ import { parseISO, getYear } from 'date-fns'; export default factories.createCoreService('api::event.event', ({strapi}) => ({ async getDistinctYears() { - const articles = await strapi.query("api::event.event").findMany({ + const events = await strapi.query("api::event.event").findMany({ select: ['date'], }); - const years = articles + const years = events .map(article => getYear(parseISO(article.date + ""))) .filter((year, index, self) => self.indexOf(year) === index) .sort((a, b) => b - a); @@ -23,36 +23,25 @@ export default factories.createCoreService('api::event.event', ({strapi}) => ({ const startOfYear = new Date(`${year}-01-01T00:00:00.000Z`); const endOfYear = new Date(`${year}-12-31T23:59:59.999Z`); - const articles = await strapi.query("api::event.event").findMany({ + const events = await strapi.query("api::event.event").findPage({ filters: { date: { $gte: startOfYear, $lte: endOfYear, }, + publishedAt: { + $ne: null + } }, limit: pageSize, offset: (page - 1) * pageSize, orderBy: { date: 'desc' }, }); - const totalArticles = await strapi.query("api::event.event").count({ - filters: { - date: { - $gte: startOfYear, - $lte: endOfYear, - }, - }, - }); - return { - data: articles, + data: events.results, meta: { - pagination: { - page, - pageSize, - pageCount: Math.ceil(totalArticles / pageSize), - total: totalArticles, - }, + pagination: events.pagination }, }; }, diff --git a/src/api/operation/services/operation.ts b/src/api/operation/services/operation.ts index 6c65ac4..9e3791e 100644 --- a/src/api/operation/services/operation.ts +++ b/src/api/operation/services/operation.ts @@ -7,11 +7,11 @@ import { parseISO, getYear } from 'date-fns'; export default factories.createCoreService('api::operation.operation', ({strapi}) => ({ async getDistinctYears() { - const articles = await strapi.query("api::operation.operation").findMany({ + const operations = await strapi.query("api::operation.operation").findMany({ select: ['date'], }); - const years = articles + const years = operations .map(article => getYear(parseISO(article.date + ""))) .filter((year, index, self) => self.indexOf(year) === index) .sort((a, b) => b - a); @@ -23,36 +23,25 @@ export default factories.createCoreService('api::operation.operation', ({strapi} const startOfYear = new Date(`${year}-01-01T00:00:00.000Z`); const endOfYear = new Date(`${year}-12-31T23:59:59.999Z`); - const articles = await strapi.query("api::operation.operation").findMany({ + const operations = await strapi.query("api::operation.operation").findPage({ filters: { date: { $gte: startOfYear, $lte: endOfYear, }, + publishedAt: { + $ne: null + } }, limit: pageSize, offset: (page - 1) * pageSize, orderBy: { date: 'desc' }, }); - const totalArticles = await strapi.query("api::operation.operation").count({ - filters: { - date: { - $gte: startOfYear, - $lte: endOfYear, - }, - }, - }); - return { - data: articles, + data: operations.results, meta: { - pagination: { - page, - pageSize, - pageCount: Math.ceil(totalArticles / pageSize), - total: totalArticles, - }, + pagination: operations.pagination }, }; }, diff --git a/src/extensions/documentation/documentation/1.0.0/full_documentation.json b/src/extensions/documentation/documentation/1.0.0/full_documentation.json index 138e416..bd6cc61 100644 --- a/src/extensions/documentation/documentation/1.0.0/full_documentation.json +++ b/src/extensions/documentation/documentation/1.0.0/full_documentation.json @@ -14,7 +14,7 @@ "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, - "x-generation-date": "2024-11-04T10:41:27.532Z" + "x-generation-date": "2024-11-04T14:45:06.170Z" }, "x-strapi-config": { "plugins": [ diff --git a/src/middlewares/deepPopulate.ts b/src/middlewares/deepPopulate.ts index 18abee7..597bfd7 100644 --- a/src/middlewares/deepPopulate.ts +++ b/src/middlewares/deepPopulate.ts @@ -51,13 +51,8 @@ const getDeepPopulate = (uid: UID.Schema, opts: Options = {}) => { const isCreatorField = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(attributeName); if (isVisible) { - if (attributeName === 'testimonials') { - acc[attributeName] = { populate: "user.image" }; - } else { - acc[attributeName] = { populate: "*" }; - } + acc[attributeName] = { populate: "*" }; } - break; } @@ -105,6 +100,7 @@ export default (config, { strapi }: { strapi: Core.Strapi }) => { // @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 diff --git a/types/generated/contentTypes.d.ts b/types/generated/contentTypes.d.ts index 702c763..f932f66 100644 --- a/types/generated/contentTypes.d.ts +++ b/types/generated/contentTypes.d.ts @@ -417,7 +417,9 @@ export interface ApiCollectionLookupCollectionLookup draftAndPublish: true; }; attributes: { - collection: Schema.Attribute.UID & Schema.Attribute.Required; + collection: Schema.Attribute.String & + Schema.Attribute.Required & + Schema.Attribute.Unique; createdAt: Schema.Attribute.DateTime; createdBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> & Schema.Attribute.Private; @@ -434,7 +436,9 @@ export interface ApiCollectionLookupCollectionLookup > & Schema.Attribute.Private; publishedAt: Schema.Attribute.DateTime; - reference: Schema.Attribute.UID & Schema.Attribute.Required; + reference: Schema.Attribute.String & + Schema.Attribute.Required & + Schema.Attribute.Unique; updatedAt: Schema.Attribute.DateTime; updatedBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> & Schema.Attribute.Private;