Compare commits
No commits in common. "6ac5965b88e196a121a3a7239db9860ae6678273" and "8c70fa1c503fb409ed0ed8d167e87909eb688e26" have entirely different histories.
6ac5965b88
...
8c70fa1c50
7 changed files with 4106 additions and 3082 deletions
7091
package-lock.json
generated
7091
package-lock.json
generated
File diff suppressed because it is too large
Load diff
10
package.json
10
package.json
|
@ -12,11 +12,11 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@offset-dev/strapi-calendar": "^1.0.0",
|
"@offset-dev/strapi-calendar": "^1.0.0",
|
||||||
"@strapi/plugin-color-picker": "5.6.0",
|
"@strapi/plugin-color-picker": "^5.1.1",
|
||||||
"@strapi/plugin-documentation": "5.6.0",
|
"@strapi/plugin-documentation": "^5.1.1",
|
||||||
"@strapi/plugin-graphql": "5.6.0",
|
"@strapi/plugin-graphql": "^5.1.1",
|
||||||
"@strapi/plugin-users-permissions": "5.6.0",
|
"@strapi/plugin-users-permissions": "5.1.1",
|
||||||
"@strapi/strapi": "5.6.0",
|
"@strapi/strapi": "5.1.1",
|
||||||
"mysql2": "3.9.8",
|
"mysql2": "3.9.8",
|
||||||
"react": "^18.0.0",
|
"react": "^18.0.0",
|
||||||
"react-dom": "^18.0.0",
|
"react-dom": "^18.0.0",
|
||||||
|
|
|
@ -2,27 +2,6 @@
|
||||||
* vehicle controller
|
* vehicle controller
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { factories } from "@strapi/strapi";
|
import { factories } from '@strapi/strapi'
|
||||||
|
|
||||||
export default factories.createCoreController("api::vehicle.vehicle", ({ strapi }) => ({
|
export default factories.createCoreController('api::vehicle.vehicle');
|
||||||
async distinctYears(ctx) {
|
|
||||||
try {
|
|
||||||
const years = await strapi.service("api::vehicle.vehicle").getDistinctYears();
|
|
||||||
ctx.body = years;
|
|
||||||
} catch (err) {
|
|
||||||
ctx.throw(500, err);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async findByYear(ctx) {
|
|
||||||
try {
|
|
||||||
const { year } = ctx.params;
|
|
||||||
const { page = "1", pageSize = "10" } = ctx.query as { page?: string; pageSize?: string };
|
|
||||||
|
|
||||||
const result = await strapi.service("api::vehicle.vehicle").findByYear(year, parseInt(page), parseInt(pageSize));
|
|
||||||
ctx.body = result;
|
|
||||||
} catch (err) {
|
|
||||||
ctx.throw(500, err);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
export default {
|
|
||||||
routes: [
|
|
||||||
{
|
|
||||||
method: "GET",
|
|
||||||
path: "/custom/vehicle/distinct-years",
|
|
||||||
handler: "api::vehicle.vehicle.distinctYears",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
method: "GET",
|
|
||||||
path: "/custom/vehicle/year/:year",
|
|
||||||
handler: "api::vehicle.vehicle.findByYear",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
|
@ -2,47 +2,6 @@
|
||||||
* vehicle service
|
* vehicle service
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { factories } from "@strapi/strapi";
|
import { factories } from '@strapi/strapi';
|
||||||
import { parseISO, getYear } from "date-fns";
|
|
||||||
|
|
||||||
export default factories.createCoreService("api::vehicle.vehicle", ({ strapi }) => ({
|
export default factories.createCoreService('api::vehicle.vehicle');
|
||||||
async getDistinctYears() {
|
|
||||||
const articles = await strapi.query("api::vehicle.vehicle").findMany({
|
|
||||||
select: ["date"],
|
|
||||||
});
|
|
||||||
|
|
||||||
const years = articles
|
|
||||||
.map((article) => getYear(parseISO(article.date + "")))
|
|
||||||
.filter((year, index, self) => self.indexOf(year) === index)
|
|
||||||
.sort((a, b) => b - a);
|
|
||||||
|
|
||||||
return years;
|
|
||||||
},
|
|
||||||
|
|
||||||
async findByYear(year: string, page = 1, pageSize = 10) {
|
|
||||||
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::vehicle.vehicle").findPage({
|
|
||||||
filters: {
|
|
||||||
date: {
|
|
||||||
$gte: startOfYear,
|
|
||||||
$lte: endOfYear,
|
|
||||||
},
|
|
||||||
publishedAt: {
|
|
||||||
$ne: null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
limit: pageSize,
|
|
||||||
page: page,
|
|
||||||
orderBy: { date: "desc" },
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
data: articles.results,
|
|
||||||
meta: {
|
|
||||||
pagination: articles.pagination,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
|
@ -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": "2025-01-14T08:03:38.856Z"
|
"x-generation-date": "2025-01-05T16:42:52.145Z"
|
||||||
},
|
},
|
||||||
"x-strapi-config": {
|
"x-strapi-config": {
|
||||||
"plugins": [
|
"plugins": [
|
||||||
|
|
1
types/generated/contentTypes.d.ts
vendored
1
types/generated/contentTypes.d.ts
vendored
|
@ -707,7 +707,6 @@ export interface PluginReviewWorkflowsWorkflow extends Struct.CollectionTypeSche
|
||||||
Schema.Attribute.Private;
|
Schema.Attribute.Private;
|
||||||
name: Schema.Attribute.String & Schema.Attribute.Required & Schema.Attribute.Unique;
|
name: Schema.Attribute.String & Schema.Attribute.Required & Schema.Attribute.Unique;
|
||||||
publishedAt: Schema.Attribute.DateTime;
|
publishedAt: Schema.Attribute.DateTime;
|
||||||
stageRequiredToPublish: Schema.Attribute.Relation<"oneToOne", "plugin::review-workflows.workflow-stage">;
|
|
||||||
stages: Schema.Attribute.Relation<"oneToMany", "plugin::review-workflows.workflow-stage">;
|
stages: Schema.Attribute.Relation<"oneToMany", "plugin::review-workflows.workflow-stage">;
|
||||||
updatedAt: Schema.Attribute.DateTime;
|
updatedAt: Schema.Attribute.DateTime;
|
||||||
updatedBy: Schema.Attribute.Relation<"oneToOne", "admin::user"> & Schema.Attribute.Private;
|
updatedBy: Schema.Attribute.Relation<"oneToOne", "admin::user"> & Schema.Attribute.Private;
|
||||||
|
|
Loading…
Reference in a new issue