api changes
This commit is contained in:
parent
28afdfd83e
commit
c27e8d3f4b
7 changed files with 37 additions and 68 deletions
|
@ -23,36 +23,25 @@ export default factories.createCoreService('api::article.article', ({strapi}) =>
|
||||||
const startOfYear = new Date(`${year}-01-01T00:00:00.000Z`);
|
const startOfYear = new Date(`${year}-01-01T00:00:00.000Z`);
|
||||||
const endOfYear = new Date(`${year}-12-31T23:59:59.999Z`);
|
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: {
|
filters: {
|
||||||
date: {
|
date: {
|
||||||
$gte: startOfYear,
|
$gte: startOfYear,
|
||||||
$lte: endOfYear,
|
$lte: endOfYear,
|
||||||
},
|
},
|
||||||
|
publishedAt: {
|
||||||
|
$ne: null
|
||||||
|
}
|
||||||
},
|
},
|
||||||
limit: pageSize,
|
limit: pageSize,
|
||||||
offset: (page - 1) * pageSize,
|
offset: (page - 1) * pageSize,
|
||||||
orderBy: { date: 'desc' },
|
orderBy: { date: 'desc' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const totalArticles = await strapi.query("api::article.article").count({
|
|
||||||
filters: {
|
|
||||||
date: {
|
|
||||||
$gte: startOfYear,
|
|
||||||
$lte: endOfYear,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: articles,
|
data: articles.results,
|
||||||
meta: {
|
meta: {
|
||||||
pagination: {
|
pagination: articles.pagination
|
||||||
page,
|
|
||||||
pageSize,
|
|
||||||
pageCount: Math.ceil(totalArticles / pageSize),
|
|
||||||
total: totalArticles,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,12 +13,14 @@
|
||||||
"pluginOptions": {},
|
"pluginOptions": {},
|
||||||
"attributes": {
|
"attributes": {
|
||||||
"reference": {
|
"reference": {
|
||||||
"type": "uid",
|
"type": "string",
|
||||||
"required": true
|
"required": true,
|
||||||
|
"unique": true
|
||||||
},
|
},
|
||||||
"collection": {
|
"collection": {
|
||||||
"type": "uid",
|
"type": "string",
|
||||||
"required": true
|
"required": true,
|
||||||
|
"unique": true
|
||||||
},
|
},
|
||||||
"image_item": {
|
"image_item": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|
|
@ -7,11 +7,11 @@ import { parseISO, getYear } from 'date-fns';
|
||||||
|
|
||||||
export default factories.createCoreService('api::event.event', ({strapi}) => ({
|
export default factories.createCoreService('api::event.event', ({strapi}) => ({
|
||||||
async getDistinctYears() {
|
async getDistinctYears() {
|
||||||
const articles = await strapi.query("api::event.event").findMany({
|
const events = await strapi.query("api::event.event").findMany({
|
||||||
select: ['date'],
|
select: ['date'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const years = articles
|
const years = events
|
||||||
.map(article => getYear(parseISO(article.date + "")))
|
.map(article => getYear(parseISO(article.date + "")))
|
||||||
.filter((year, index, self) => self.indexOf(year) === index)
|
.filter((year, index, self) => self.indexOf(year) === index)
|
||||||
.sort((a, b) => b - a);
|
.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 startOfYear = new Date(`${year}-01-01T00:00:00.000Z`);
|
||||||
const endOfYear = new Date(`${year}-12-31T23:59:59.999Z`);
|
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: {
|
filters: {
|
||||||
date: {
|
date: {
|
||||||
$gte: startOfYear,
|
$gte: startOfYear,
|
||||||
$lte: endOfYear,
|
$lte: endOfYear,
|
||||||
},
|
},
|
||||||
|
publishedAt: {
|
||||||
|
$ne: null
|
||||||
|
}
|
||||||
},
|
},
|
||||||
limit: pageSize,
|
limit: pageSize,
|
||||||
offset: (page - 1) * pageSize,
|
offset: (page - 1) * pageSize,
|
||||||
orderBy: { date: 'desc' },
|
orderBy: { date: 'desc' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const totalArticles = await strapi.query("api::event.event").count({
|
|
||||||
filters: {
|
|
||||||
date: {
|
|
||||||
$gte: startOfYear,
|
|
||||||
$lte: endOfYear,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: articles,
|
data: events.results,
|
||||||
meta: {
|
meta: {
|
||||||
pagination: {
|
pagination: events.pagination
|
||||||
page,
|
|
||||||
pageSize,
|
|
||||||
pageCount: Math.ceil(totalArticles / pageSize),
|
|
||||||
total: totalArticles,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,11 +7,11 @@ import { parseISO, getYear } from 'date-fns';
|
||||||
|
|
||||||
export default factories.createCoreService('api::operation.operation', ({strapi}) => ({
|
export default factories.createCoreService('api::operation.operation', ({strapi}) => ({
|
||||||
async getDistinctYears() {
|
async getDistinctYears() {
|
||||||
const articles = await strapi.query("api::operation.operation").findMany({
|
const operations = await strapi.query("api::operation.operation").findMany({
|
||||||
select: ['date'],
|
select: ['date'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const years = articles
|
const years = operations
|
||||||
.map(article => getYear(parseISO(article.date + "")))
|
.map(article => getYear(parseISO(article.date + "")))
|
||||||
.filter((year, index, self) => self.indexOf(year) === index)
|
.filter((year, index, self) => self.indexOf(year) === index)
|
||||||
.sort((a, b) => b - a);
|
.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 startOfYear = new Date(`${year}-01-01T00:00:00.000Z`);
|
||||||
const endOfYear = new Date(`${year}-12-31T23:59:59.999Z`);
|
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: {
|
filters: {
|
||||||
date: {
|
date: {
|
||||||
$gte: startOfYear,
|
$gte: startOfYear,
|
||||||
$lte: endOfYear,
|
$lte: endOfYear,
|
||||||
},
|
},
|
||||||
|
publishedAt: {
|
||||||
|
$ne: null
|
||||||
|
}
|
||||||
},
|
},
|
||||||
limit: pageSize,
|
limit: pageSize,
|
||||||
offset: (page - 1) * pageSize,
|
offset: (page - 1) * pageSize,
|
||||||
orderBy: { date: 'desc' },
|
orderBy: { date: 'desc' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const totalArticles = await strapi.query("api::operation.operation").count({
|
|
||||||
filters: {
|
|
||||||
date: {
|
|
||||||
$gte: startOfYear,
|
|
||||||
$lte: endOfYear,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: articles,
|
data: operations.results,
|
||||||
meta: {
|
meta: {
|
||||||
pagination: {
|
pagination: operations.pagination
|
||||||
page,
|
|
||||||
pageSize,
|
|
||||||
pageCount: Math.ceil(totalArticles / pageSize),
|
|
||||||
total: totalArticles,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
@ -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-04T10:41:27.532Z"
|
"x-generation-date": "2024-11-04T14:45:06.170Z"
|
||||||
},
|
},
|
||||||
"x-strapi-config": {
|
"x-strapi-config": {
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
|
|
@ -51,13 +51,8 @@ const getDeepPopulate = (uid: UID.Schema, opts: Options = {}) => {
|
||||||
const isCreatorField = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(attributeName);
|
const isCreatorField = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(attributeName);
|
||||||
|
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
if (attributeName === 'testimonials') {
|
acc[attributeName] = { populate: "*" };
|
||||||
acc[attributeName] = { populate: "user.image" };
|
|
||||||
} else {
|
|
||||||
acc[attributeName] = { populate: "*" };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +100,7 @@ export default (config, { strapi }: { strapi: Core.Strapi }) => {
|
||||||
// @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
|
||||||
|
|
8
types/generated/contentTypes.d.ts
vendored
8
types/generated/contentTypes.d.ts
vendored
|
@ -417,7 +417,9 @@ export interface ApiCollectionLookupCollectionLookup
|
||||||
draftAndPublish: true;
|
draftAndPublish: true;
|
||||||
};
|
};
|
||||||
attributes: {
|
attributes: {
|
||||||
collection: Schema.Attribute.UID & Schema.Attribute.Required;
|
collection: Schema.Attribute.String &
|
||||||
|
Schema.Attribute.Required &
|
||||||
|
Schema.Attribute.Unique;
|
||||||
createdAt: Schema.Attribute.DateTime;
|
createdAt: Schema.Attribute.DateTime;
|
||||||
createdBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> &
|
createdBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> &
|
||||||
Schema.Attribute.Private;
|
Schema.Attribute.Private;
|
||||||
|
@ -434,7 +436,9 @@ export interface ApiCollectionLookupCollectionLookup
|
||||||
> &
|
> &
|
||||||
Schema.Attribute.Private;
|
Schema.Attribute.Private;
|
||||||
publishedAt: Schema.Attribute.DateTime;
|
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;
|
updatedAt: Schema.Attribute.DateTime;
|
||||||
updatedBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> &
|
updatedBy: Schema.Attribute.Relation<'oneToOne', 'admin::user'> &
|
||||||
Schema.Attribute.Private;
|
Schema.Attribute.Private;
|
||||||
|
|
Loading…
Reference in a new issue