From 1e713853c454cce4dcd4419afe2cfa229de9b1a3 Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Thu, 18 Jan 2024 02:01:44 +0330 Subject: [PATCH] feat: add missing fields --- src/api/page/content-types/page/schema.json | 37 ++++++++++++++++ src/api/page/controllers/page.ts | 7 +++ src/api/page/routes/page.ts | 7 +++ src/api/page/services/page.ts | 7 +++ .../content-types/podcast-show/schema.json | 10 ++++- src/api/post/content-types/post/schema.json | 19 +++++++- src/api/tag/controllers/tag.ts | 19 +++++++- src/api/tag/routes/custom.ts | 12 +++++ types/generated/contentTypes.d.ts | 44 ++++++++++++++++++- 9 files changed, 155 insertions(+), 7 deletions(-) create mode 100644 src/api/page/content-types/page/schema.json create mode 100644 src/api/page/controllers/page.ts create mode 100644 src/api/page/routes/page.ts create mode 100644 src/api/page/services/page.ts create mode 100644 src/api/tag/routes/custom.ts diff --git a/src/api/page/content-types/page/schema.json b/src/api/page/content-types/page/schema.json new file mode 100644 index 0000000..9999c2a --- /dev/null +++ b/src/api/page/content-types/page/schema.json @@ -0,0 +1,37 @@ +{ + "kind": "collectionType", + "collectionName": "pages", + "info": { + "singularName": "page", + "pluralName": "pages", + "displayName": "Page", + "description": "" + }, + "options": { + "draftAndPublish": true + }, + "pluginOptions": {}, + "attributes": { + "title": { + "type": "string" + }, + "slug": { + "type": "uid", + "targetField": "title" + }, + "body": { + "type": "customField", + "options": { + "output": "HTML", + "preset": "standard" + }, + "customField": "plugin::ckeditor.CKEditor" + }, + "subtitle": { + "type": "string" + }, + "description": { + "type": "text" + } + } +} diff --git a/src/api/page/controllers/page.ts b/src/api/page/controllers/page.ts new file mode 100644 index 0000000..f513618 --- /dev/null +++ b/src/api/page/controllers/page.ts @@ -0,0 +1,7 @@ +/** + * page controller + */ + +import { factories } from '@strapi/strapi' + +export default factories.createCoreController('api::page.page'); diff --git a/src/api/page/routes/page.ts b/src/api/page/routes/page.ts new file mode 100644 index 0000000..8e5ddfc --- /dev/null +++ b/src/api/page/routes/page.ts @@ -0,0 +1,7 @@ +/** + * page router + */ + +import { factories } from '@strapi/strapi'; + +export default factories.createCoreRouter('api::page.page'); diff --git a/src/api/page/services/page.ts b/src/api/page/services/page.ts new file mode 100644 index 0000000..eaf07ff --- /dev/null +++ b/src/api/page/services/page.ts @@ -0,0 +1,7 @@ +/** + * page service + */ + +import { factories } from '@strapi/strapi'; + +export default factories.createCoreService('api::page.page'); diff --git a/src/api/podcast-show/content-types/podcast-show/schema.json b/src/api/podcast-show/content-types/podcast-show/schema.json index 4f39c9a..9005916 100644 --- a/src/api/podcast-show/content-types/podcast-show/schema.json +++ b/src/api/podcast-show/content-types/podcast-show/schema.json @@ -12,7 +12,7 @@ }, "pluginOptions": {}, "attributes": { - "Name": { + "name": { "type": "string", "required": true }, @@ -33,13 +33,19 @@ "type": "media", "multiple": false, "required": false, - "allowedTypes": ["images"] + "allowedTypes": [ + "images" + ] }, "posts": { "type": "relation", "relation": "oneToMany", "target": "api::post.post", "mappedBy": "podcast_show" + }, + "slug": { + "type": "uid", + "targetField": "name" } } } diff --git a/src/api/post/content-types/post/schema.json b/src/api/post/content-types/post/schema.json index 93516bf..d6137b9 100644 --- a/src/api/post/content-types/post/schema.json +++ b/src/api/post/content-types/post/schema.json @@ -27,7 +27,10 @@ }, "type": { "type": "enumeration", - "enum": ["Article", "Episode"], + "enum": [ + "Article", + "Episode" + ], "default": "Article" }, "episode_number": { @@ -64,7 +67,9 @@ "type": "media", "multiple": false, "required": false, - "allowedTypes": ["images"] + "allowedTypes": [ + "images" + ] }, "tags": { "type": "relation", @@ -85,6 +90,16 @@ "preset": "standard" }, "customField": "plugin::ckeditor.CKEditor" + }, + "featured": { + "type": "boolean", + "default": false, + "required": false + }, + "related_posts": { + "type": "relation", + "relation": "oneToMany", + "target": "api::post.post" } } } diff --git a/src/api/tag/controllers/tag.ts b/src/api/tag/controllers/tag.ts index 0b3e997..22bc5da 100644 --- a/src/api/tag/controllers/tag.ts +++ b/src/api/tag/controllers/tag.ts @@ -2,6 +2,21 @@ * tag controller */ -import { factories } from '@strapi/strapi' +import { factories } from "@strapi/strapi"; -export default factories.createCoreController('api::tag.tag'); +export default factories.createCoreController("api::tag.tag", ({ strapi }) => ({ + async getAll(ctx) { + const tags = await strapi.entityService.findMany("api::tag.tag", { + populate: { + posts: { + count: true, + } as any, + }, + fields: "id,name", + limit: 1000, + sort: "name:asc", + }); + + return tags; + }, +})); diff --git a/src/api/tag/routes/custom.ts b/src/api/tag/routes/custom.ts new file mode 100644 index 0000000..ac7e372 --- /dev/null +++ b/src/api/tag/routes/custom.ts @@ -0,0 +1,12 @@ +export default { + routes: [ + { + method: "GET", + path: "/tags/getAll", + handler: "tag.getAll", + config: { + policies: [], + }, + }, + ], +}; diff --git a/types/generated/contentTypes.d.ts b/types/generated/contentTypes.d.ts index a499822..5d5d16e 100644 --- a/types/generated/contentTypes.d.ts +++ b/types/generated/contentTypes.d.ts @@ -800,6 +800,40 @@ export interface ApiAuthorAuthor extends Schema.CollectionType { }; } +export interface ApiPagePage extends Schema.CollectionType { + collectionName: 'pages'; + info: { + singularName: 'page'; + pluralName: 'pages'; + displayName: 'Page'; + description: ''; + }; + options: { + draftAndPublish: true; + }; + attributes: { + title: Attribute.String; + slug: Attribute.UID<'api::page.page', 'title'>; + body: Attribute.RichText & + Attribute.CustomField< + 'plugin::ckeditor.CKEditor', + { + output: 'HTML'; + preset: 'standard'; + } + >; + subtitle: Attribute.String; + description: Attribute.Text; + createdAt: Attribute.DateTime; + updatedAt: Attribute.DateTime; + publishedAt: Attribute.DateTime; + createdBy: Attribute.Relation<'api::page.page', 'oneToOne', 'admin::user'> & + Attribute.Private; + updatedBy: Attribute.Relation<'api::page.page', 'oneToOne', 'admin::user'> & + Attribute.Private; + }; +} + export interface ApiPodcastShowPodcastShow extends Schema.CollectionType { collectionName: 'podcast_shows'; info: { @@ -812,7 +846,7 @@ export interface ApiPodcastShowPodcastShow extends Schema.CollectionType { draftAndPublish: true; }; attributes: { - Name: Attribute.String & Attribute.Required; + name: Attribute.String & Attribute.Required; hosts: Attribute.Relation< 'api::podcast-show.podcast-show', 'oneToMany', @@ -832,6 +866,7 @@ export interface ApiPodcastShowPodcastShow extends Schema.CollectionType { 'oneToMany', 'api::post.post' >; + slug: Attribute.UID<'api::podcast-show.podcast-show', 'name'>; createdAt: Attribute.DateTime; updatedAt: Attribute.DateTime; publishedAt: Attribute.DateTime; @@ -906,6 +941,12 @@ export interface ApiPostPost extends Schema.CollectionType { preset: 'standard'; } >; + featured: Attribute.Boolean & Attribute.DefaultTo; + related_posts: Attribute.Relation< + 'api::post.post', + 'oneToMany', + 'api::post.post' + >; createdAt: Attribute.DateTime; updatedAt: Attribute.DateTime; publishedAt: Attribute.DateTime; @@ -958,6 +999,7 @@ declare module '@strapi/types' { 'plugin::users-permissions.role': PluginUsersPermissionsRole; 'plugin::users-permissions.user': PluginUsersPermissionsUser; 'api::author.author': ApiAuthorAuthor; + 'api::page.page': ApiPagePage; 'api::podcast-show.podcast-show': ApiPodcastShowPodcastShow; 'api::post.post': ApiPostPost; 'api::tag.tag': ApiTagTag;