api changes

This commit is contained in:
Julian Krauser 2024-11-04 15:57:46 +01:00
parent 28afdfd83e
commit c27e8d3f4b
7 changed files with 37 additions and 68 deletions

View file

@ -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
},
};
},

View file

@ -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",

View file

@ -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
},
};
},

View file

@ -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
},
};
},

View file

@ -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": [

View file

@ -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: "*" };
}
}
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

View file

@ -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;