Josh a8498df926
feat(cm): reimplement relations for draft & publish (#19642)
* feat(content-manager): Rework findAvailable and findExisting (#19597)

* feat(content-manager): wip rework findAvailable and findExisting

* chore(strapi): simplify relations controller

* feat(content-manager): entity Id based find available

* feat(content-manager): entity Id based find existing

* fix(content-manager): build issues

* chore(content-manager): cleanup

* fix(content-manager): relations controllers unit tests

* fix(content-manager): improve error handling

* fix(content-manager): simplify findExisting relations logic

* fix(content-manager): clean up types

* fix(content-manager): extend available relation API tests

* fix(content-manager): pr feedback

* feat(content-manager): cover find existing test cases

* feat(content-manager): test that we can only find available relations in the same locale

* fix: wip fix unit tests

* chore(content-manager): pr feedback

* fix(content-manager): use db layer to find relations

fix(content-manager): failing relations tests

* fix(content-manager): find relations test

* fix(content-manager): build issues

* fix(content-manager): return latest status of relations in findAvailable (#19681)

* fix(content-manager): return latest status of relations in findAvailable

* fix(content-manager): share logic for findAvailable and findExisting

* fix(admin): relation tests

* fix(content-manager): clean up types

* fix(content-manager): support status for find exisiting

* fix(content-manager): add status and locale filters to subQuery

* fix(content-manager): ts front and skip relations unit tests

* fix(content-manager): request specific status or get latest using document-metadata

* chore(content-manager): use interface

* fix(content-manager): tidy up target relation subquery

* fix(content-manager): tidy up and skip TS for build issues

* fix(content-manager): return status when requested

* chore(content-manager): dont re type entity service response

* fix(content-manager): use document metadata getManyAvailableStatus

* chore(content-manager): remove mapAsync

* feat: implement relations in the cm (#19702)

* Fix: Relating i18n and non-i18n content types (#19731)

* chore: re-enable e2e relation tests

* fix: return undefined

---------

Co-authored-by: Jamie Howard <48524071+jhoward1994@users.noreply.github.com>
Co-authored-by: Jamie Howard <jamie.howard@strapi.io>
Co-authored-by: Marc-Roig <marc12info@gmail.com>
2024-03-13 10:25:47 +00:00

81 lines
1.8 KiB
TypeScript

import { Documents, Entity, EntityService } from '@strapi/types';
import { errors } from '@strapi/utils';
type PaginationQuery = EntityService.Params.Pagination.PageNotation;
export interface RelationResult {
documentId: Documents.ID;
id: number;
status: Documents.Params.PublicationStatus.Kind;
locale?: Documents.Params.Locale;
[key: string]: unknown;
}
export interface Pagination {
page: NonNullable<PaginationQuery['page']>;
pageSize: NonNullable<PaginationQuery['pageSize']>;
pageCount: number;
total: number;
}
type RelationResponse =
| {
results: RelationResult[];
pagination: Pagination;
error?: never;
}
| {
results?: never;
pagination?: never;
error: errors.ApplicationError | errors.YupValidationError;
};
/**
* GET /relations/:model/:targetField
*/
export declare namespace FindAvailable {
export interface Params {
model: string;
targetField: string;
}
export interface Request {
body: {};
query: Partial<Pick<Pagination, 'pageSize' | 'page'>> & {
id?: Entity.ID;
locale?: Documents.Params.Locale;
_filter?: string;
_q?: string;
idsToOmit?: Documents.ID[];
idsToInclude?: Documents.ID[];
};
}
export type Response = RelationResponse;
}
/**
* GET /relations/:model/:id/:targetField
*/
export declare namespace FindExisting {
export interface Params {
model: string;
targetField: string;
id?: Entity.ID;
}
export interface Request {
body: {};
query: Partial<Pick<Pagination, 'pageSize' | 'page'>> & {
locale?: string | null;
_filter?: string;
_q?: string;
status?: Documents.Params.PublicationStatus.Kind;
idsToOmit?: Documents.ID[];
idsToInclude?: Documents.ID[];
};
}
export type Response = RelationResponse;
}