Commit 2d9b9492 authored by Oleg Nikolaev's avatar Oleg Nikolaev
Browse files

MAX-24: Contacts page logic

parent a413daa4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
{
  "latest": "5.12.5",
  "lastUpdateCheck": 1744806284674,
  "lastUpdateCheck": 1745211071553,
  "lastNotification": 1744867304898
}
+31 −0
Original line number Diff line number Diff line
{
  "kind": "collectionType",
  "collectionName": "contacts_pages",
  "info": {
    "singularName": "contacts-page",
    "pluralName": "contacts-pages",
    "displayName": "ContactsPage",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "attributes": {
    "pageTitle": {
      "type": "string",
      "default": "Контакты",
      "required": true
    },
    "contactsSection": {
      "type": "component",
      "repeatable": false,
      "component": "page-block.section-with-contacts"
    },
    "site": {
      "type": "relation",
      "relation": "oneToOne",
      "target": "api::site.site",
      "inversedBy": "contacts_page"
    }
  }
}
+16 −0
Original line number Diff line number Diff line
/**
 * contacts-page controller
 */

import { Context } from "koa";

import { factories } from "@strapi/strapi";

export default factories.createCoreController(
  "api::contacts-page.contacts-page",
  ({ strapi }) => ({
    getContactsPage(ctx: Context) {
      return strapi.service("api::contacts-page.contacts-page").getPage(ctx);
    },
  }),
);
+14 −0
Original line number Diff line number Diff line
/**
 * contacts-page router
 */

export default {
  routes: [
    {
      method: "GET",
      path: "/pages/contacts-page",
      handler: "contacts-page.getContactsPage",
      config: { auth: false },
    },
  ],
};
+43 −0
Original line number Diff line number Diff line
import { Context } from "koa";
import { factories } from "@strapi/strapi";
import { CUSTOM_REQUEST_HEADERS } from "../../../lib/constants/custom-headers";
import {
  formatSectionWithContacts,
  sectionWithContactsRetrievingConfig,
} from "../../../lib/api-utils/data-retrieving-configs/section-witch-contacts";

export default factories.createCoreService(
  "api::contacts-page.contacts-page",
  ({ strapi }) => ({
    async getPage(ctx: Context) {
      const contactsPage = await strapi
        .documents("api::contacts-page.contacts-page")
        .findFirst({
          filters: {
            site: {
              documentId: ctx.request.headers[
                CUSTOM_REQUEST_HEADERS.siteDocumentId
              ] as string,
            },
          },
          fields: ["pageTitle"],
          populate: {
            contactsSection: sectionWithContactsRetrievingConfig,
          },
        });

      if (!contactsPage) {
        return ctx.notFound("Page not found");
      }

      const responseBody = {
        pageTitle: contactsPage.pageTitle,
        contactsSection: formatSectionWithContacts(
          contactsPage.contactsSection,
        ),
      };

      ctx.body = responseBody;
    },
  }),
);
Loading