From 1df99d479dcf37b3b11668c10b8479d2f72b51b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Ch=C3=A1vez?= Date: Tue, 30 Jan 2024 09:24:06 +0100 Subject: [PATCH] docs(content-releases): add missing endpoints to backend docs (#19302) * docs(content-releases): add missing endpoints to backend docs * Update docs/docs/docs/01-core/content-releases/01-backend.md Co-authored-by: markkaylor * Update docs/docs/docs/01-core/content-releases/01-backend.md Co-authored-by: markkaylor * Update docs/docs/docs/01-core/content-releases/01-backend.md Co-authored-by: markkaylor * apply marks feedback --------- Co-authored-by: markkaylor --- .../admin/05-features/hooks/use-document.mdx | 47 ++++++++++++++++++ .../01-core/content-releases/01-backend.md | 49 ++++++++++++++++++- 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 docs/docs/docs/01-core/admin/05-features/hooks/use-document.mdx diff --git a/docs/docs/docs/01-core/admin/05-features/hooks/use-document.mdx b/docs/docs/docs/01-core/admin/05-features/hooks/use-document.mdx new file mode 100644 index 0000000000..a208e47173 --- /dev/null +++ b/docs/docs/docs/01-core/admin/05-features/hooks/use-document.mdx @@ -0,0 +1,47 @@ +--- +title: unstable_useDocument +description: API reference for the useDocument hook +tags: + - admin + - hooks + - document + - validations +--- + +:::caution +This hook is not stable and **likely to change**. Use at your own risk. +::: + +A hook that returns utilities to work with documents. + +## Usage + +``` +function Component() { + const { validate } = unstable_useDocument(); +} +``` + +At the moment, useDocument only returns a validate function. + +### `validate()` + +```ts +const validate( + entry: Entity, + { + contentType: Schema.ContentType, + components: { + [key: Schema.Component['uid']]: Schema.Component; + }, + isCreatingEntry?: boolean; + } +): { + errors: { [key: string]: TranslationMessage } +} +``` + +With this function, you can apply the same validations we use in the admin. Please be aware that for this function to work, you need to ensure the following: + +1. If you are validating an entry with relations/components/dynamic zones then it **MUST** be populated. Otherwise, the validations will pass even if there is an error on one populated field. +2. The correct schema for the contentType and the schemas for any components related to that content type are mandatory for this hook to function correctly. diff --git a/docs/docs/docs/01-core/content-releases/01-backend.md b/docs/docs/docs/01-core/content-releases/01-backend.md index 27451a2a7f..fd54046fec 100644 --- a/docs/docs/docs/01-core/content-releases/01-backend.md +++ b/docs/docs/docs/01-core/content-releases/01-backend.md @@ -56,6 +56,19 @@ packages/core/content-releases/server/src/routes/release.ts } ``` +**Get all releases with/without an entry**: + +- method: `GET` +- endpoint: `/content-releases/` +- params: + ```ts + { + contentTypeUid: string; + entryId: number; + hasEntryAttached?: boolean; + } + ``` + **Get a single release** - method: `GET` @@ -83,6 +96,11 @@ packages/core/content-releases/server/src/routes/release.ts } ``` +**Delete a release**: + +- method: `DELETE` +- endpoint: `/content-releases/:id` + **Publish a release**: - method: `POST` @@ -100,12 +118,25 @@ packages/core/content-releases/server/src/routes/release.ts { entry: { id: number, - contentType: string + contentType: string, + locale: string, } type: 'publish' | 'unpublish' } ``` +**Get release actions from a release** + +- method: `GET` +- endpoint: `/content-releases/:releaseId/actions` +- body: + ```ts + { + page: number; + pageSize: number; + } + ``` + **Update a release action** - method: `PUT` @@ -153,3 +184,19 @@ Exposes validation functions to run before performing operations on a Release ``` packages/core/content-releases/server/src/services/validation.ts ``` + +## Migrations + +We have two migrations that we run every time we sync the content types. + +### `deleteActionsOnDisableDraftAndPublish` + +When a user disables Draft and Publish in one Content Type we make sure to remove all the release actions related to entries of that content type to avoid errors. + +### `deleteActionsOnDeleteContentType` + +When a Content Type is deleted, delete all actions containing entries from that Content Type. + +## Subscribing to Lifecycles Events + +When an entry is deleted delete all actions containing that entry.