@webbio/strapi-plugin-page-builder 0.3.2 → 0.3.4-platform
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/admin/src/api/page-type.ts +5 -4
- package/admin/src/api/platform-page-types.ts +40 -0
- package/admin/src/api/platform.ts +5 -5
- package/admin/src/components/EditView/CollectionTypeSettings/index.tsx +59 -20
- package/admin/src/components/EditView/PageSettings/index.tsx +19 -2
- package/admin/src/components/PageFilters/filters.tsx +9 -9
- package/dist/package.json +1 -1
- package/dist/server/bootstrap/permissions.js +68 -10
- package/dist/server/graphql/page-by-slug.js +44 -37
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/server/bootstrap/permissions.ts +75 -10
- package/server/graphql/page-by-slug.ts +50 -43
|
@@ -9,11 +9,11 @@ export type PageType = {
|
|
|
9
9
|
|
|
10
10
|
const QUERY_KEY = 'page-types';
|
|
11
11
|
|
|
12
|
-
const fetchPageTypes = async ({ fetchClient }: any): Promise<PageType[]> => {
|
|
12
|
+
const fetchPageTypes = async ({ fetchClient }: Record<string, any>): Promise<PageType[]> => {
|
|
13
13
|
const { get } = fetchClient;
|
|
14
|
-
const result = await get(`/content-manager/collection-types/api::page-type.page-type`);
|
|
14
|
+
const result = await get(`/content-manager/collection-types/api::page-type.page-type?page=1&pageSize=100`);
|
|
15
15
|
|
|
16
|
-
return result?.data?.results?.map((entity: any) => ({
|
|
16
|
+
return result?.data?.results?.map((entity: Record<string, any>) => ({
|
|
17
17
|
id: entity.id,
|
|
18
18
|
uid: entity.uid,
|
|
19
19
|
title: entity.title,
|
|
@@ -21,11 +21,12 @@ const fetchPageTypes = async ({ fetchClient }: any): Promise<PageType[]> => {
|
|
|
21
21
|
}));
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
export const useGetPageTypes = (params: any) => {
|
|
24
|
+
export const useGetPageTypes = (params: Record<string, any>) => {
|
|
25
25
|
const fetchClient = useFetchClient();
|
|
26
26
|
params = {
|
|
27
27
|
...params,
|
|
28
28
|
fetchClient
|
|
29
29
|
};
|
|
30
|
+
|
|
30
31
|
return useQuery<PageType[], Error>(QUERY_KEY, () => fetchPageTypes(params));
|
|
31
32
|
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useQuery } from 'react-query';
|
|
2
|
+
|
|
3
|
+
import { useFetchClient } from '@strapi/helper-plugin';
|
|
4
|
+
|
|
5
|
+
import { PageType } from './page-type';
|
|
6
|
+
|
|
7
|
+
const QUERY_KEY = 'pageTypesForPlatform';
|
|
8
|
+
|
|
9
|
+
const fetchPageTypesForPlatform = async ({ fetchClient, id }: Record<string, any>): Promise<PageType[]> => {
|
|
10
|
+
if (!id) return [];
|
|
11
|
+
|
|
12
|
+
const { get } = fetchClient;
|
|
13
|
+
const pageTypesByPlatformResult = await get(
|
|
14
|
+
`/content-manager/relations/api::platform.platform/${id}/pageTypes?page=1&pageSize=100`
|
|
15
|
+
);
|
|
16
|
+
const pageTypesResult = await get(`/content-manager/collection-types/api::page-type.page-type?page=1&pageSize=100`);
|
|
17
|
+
|
|
18
|
+
return pageTypesByPlatformResult?.data?.results?.map((entity: Record<string, any>) => {
|
|
19
|
+
const fullPageType = pageTypesResult?.data?.results?.find(
|
|
20
|
+
(pageType: Record<string, any>) => pageType.id === entity.id
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
id: entity.id,
|
|
25
|
+
uid: fullPageType.uid,
|
|
26
|
+
title: fullPageType.title,
|
|
27
|
+
templateId: fullPageType?.template?.id
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const useGetPageTypesForPlatform = (params: Record<string, any>) => {
|
|
33
|
+
const fetchClient = useFetchClient();
|
|
34
|
+
params = {
|
|
35
|
+
...params,
|
|
36
|
+
fetchClient
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return useQuery<PageType[], Error>([QUERY_KEY, params?.id], () => fetchPageTypesForPlatform(params));
|
|
40
|
+
};
|
|
@@ -2,7 +2,6 @@ import { useQuery } from 'react-query';
|
|
|
2
2
|
|
|
3
3
|
import { useFetchClient } from '@strapi/helper-plugin';
|
|
4
4
|
|
|
5
|
-
import getRequestUrl from '../utils/getRequestUrl';
|
|
6
5
|
import { PageType } from './page-type';
|
|
7
6
|
|
|
8
7
|
export type Platform = {
|
|
@@ -13,22 +12,23 @@ export type Platform = {
|
|
|
13
12
|
|
|
14
13
|
const QUERY_KEY = 'platforms';
|
|
15
14
|
|
|
16
|
-
const fetchPlatforms = async ({ fetchClient }: any): Promise<Platform[]> => {
|
|
15
|
+
const fetchPlatforms = async ({ fetchClient }: Record<string, any>): Promise<Platform[]> => {
|
|
17
16
|
const { get } = fetchClient;
|
|
18
|
-
const result = await get(
|
|
17
|
+
const result = await get('/content-manager/collection-types/api::platform.platform?page=1&pageSize=100');
|
|
19
18
|
|
|
20
|
-
return result?.data?.map((entity: any) => ({
|
|
19
|
+
return result?.data?.results.map((entity: Record<string, any>) => ({
|
|
21
20
|
id: entity.id,
|
|
22
21
|
title: entity.title,
|
|
23
22
|
pageTypes: entity.pageTypes
|
|
24
23
|
}));
|
|
25
24
|
};
|
|
26
25
|
|
|
27
|
-
export const useGetPlatforms = (params: any) => {
|
|
26
|
+
export const useGetPlatforms = (params: Record<string, any>) => {
|
|
28
27
|
const fetchClient = useFetchClient();
|
|
29
28
|
params = {
|
|
30
29
|
...params,
|
|
31
30
|
fetchClient
|
|
32
31
|
};
|
|
32
|
+
|
|
33
33
|
return useQuery<Platform[], Error>(QUERY_KEY, () => fetchPlatforms(params));
|
|
34
34
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
|
4
4
|
import { Flex } from '@strapi/design-system';
|
|
@@ -8,10 +8,13 @@ import { Wrapper } from '../wrapper';
|
|
|
8
8
|
import { CreatePageButton } from './CreatePageButton';
|
|
9
9
|
import { PAGE_TYPE_PAGE, PAGE_UID } from '../../../../../shared/utils/constants';
|
|
10
10
|
import S from '../Details/styles';
|
|
11
|
+
import { PlatformSelect } from '../Platform/platform-select';
|
|
12
|
+
import { Platform, useGetPlatforms } from '../../../api/platform';
|
|
11
13
|
|
|
12
14
|
export const CollectionTypeSettings = () => {
|
|
13
15
|
const { layout, isCreatingEntry, initialData, onChange } = useCMEditViewDataManager() as any;
|
|
14
|
-
|
|
16
|
+
const { data: platforms } = useGetPlatforms({});
|
|
17
|
+
const [selectedPlatform, setSelectedPlatform] = useState<Platform | undefined | null>(initialData?.platform?.[0]);
|
|
15
18
|
const isUserCreatedContentType = layout.uid.startsWith('api::');
|
|
16
19
|
const linkedPage = initialData.page?.[0];
|
|
17
20
|
|
|
@@ -33,26 +36,62 @@ export const CollectionTypeSettings = () => {
|
|
|
33
36
|
return null;
|
|
34
37
|
}
|
|
35
38
|
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
setSelectedPlatform(initialData?.platform?.[0]);
|
|
41
|
+
}, [initialData]);
|
|
42
|
+
|
|
43
|
+
const setFormValue = (name: string, value?: string | Record<string, any>[]) => {
|
|
44
|
+
onChange({
|
|
45
|
+
target: {
|
|
46
|
+
name,
|
|
47
|
+
value
|
|
48
|
+
},
|
|
49
|
+
shouldSetInitialValue: true
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const handleSelectPlatform = async (platformId: string) => {
|
|
54
|
+
const platform = platforms?.find((platform) => platform.id === Number(platformId));
|
|
55
|
+
|
|
56
|
+
if (platform && platform.title) {
|
|
57
|
+
setSelectedPlatform(platform);
|
|
58
|
+
const formPlatform = {
|
|
59
|
+
...platform,
|
|
60
|
+
label: platform.title,
|
|
61
|
+
value: platform.id
|
|
62
|
+
};
|
|
63
|
+
setFormValue('platform', [formPlatform]);
|
|
64
|
+
} else {
|
|
65
|
+
setFormValue('platform', []);
|
|
66
|
+
setSelectedPlatform(null);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
36
70
|
return (
|
|
37
|
-
|
|
38
|
-
<
|
|
39
|
-
{
|
|
71
|
+
<>
|
|
72
|
+
<Wrapper title="Platform">
|
|
73
|
+
<PlatformSelect platforms={platforms} selectedPlatform={selectedPlatform} onChange={handleSelectPlatform} />
|
|
74
|
+
</Wrapper>
|
|
75
|
+
<Wrapper title="Gekoppelde pagina">
|
|
76
|
+
<Flex direction="column" gap={4} width="100%" alignItems="start">
|
|
77
|
+
{showCreatePageButton && <CreatePageButton />}
|
|
40
78
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
79
|
+
{url && (
|
|
80
|
+
<Flex direction="column" alignItems="start" width="100%" gap={1}>
|
|
81
|
+
<S.SubtleType variant="omega" fontWeight="bold" textColor="neutral800">
|
|
82
|
+
{PAGE_TYPE_PAGE}
|
|
83
|
+
</S.SubtleType>
|
|
84
|
+
<S.EntityLinkWrapper variant="pi" textColor="neutral800">
|
|
85
|
+
<S.EntityLink title={linkedPage.title || '-'} to={url} variant="pi">
|
|
86
|
+
<Link />
|
|
87
|
+
{linkedPage.title || '-'}
|
|
88
|
+
</S.EntityLink>
|
|
89
|
+
</S.EntityLinkWrapper>
|
|
90
|
+
</Flex>
|
|
91
|
+
)}
|
|
92
|
+
</Flex>
|
|
93
|
+
</Wrapper>
|
|
94
|
+
</>
|
|
56
95
|
);
|
|
57
96
|
};
|
|
58
97
|
|
|
@@ -3,7 +3,7 @@ import React, { useEffect, useMemo, useState } from 'react';
|
|
|
3
3
|
import { useCMEditViewDataManager } from '@strapi/helper-plugin';
|
|
4
4
|
import { Stack, Flex } from '@strapi/design-system';
|
|
5
5
|
import { Cog, Cross } from '@strapi/icons';
|
|
6
|
-
import { getFetchClient } from '@strapi/helper-plugin';
|
|
6
|
+
import { getFetchClient, useRBACProvider } from '@strapi/helper-plugin';
|
|
7
7
|
import { TemplateSelect } from '../Template/TemplateSelect';
|
|
8
8
|
import { PageTypeSelect } from '../page-type-select';
|
|
9
9
|
import { CollectionTypeSearch } from '../CollectionTypeSearch';
|
|
@@ -18,6 +18,7 @@ import getRequestUrl from '../../../utils/getRequestUrl';
|
|
|
18
18
|
export const PageSettings = () => {
|
|
19
19
|
const { isCreatingEntry, initialData, onChange, modifiedData, ...rest } = useCMEditViewDataManager() as any;
|
|
20
20
|
const { data: allPageTypes } = useGetPageTypes({});
|
|
21
|
+
const { allPermissions } = useRBACProvider();
|
|
21
22
|
const { data: platforms } = useGetPlatforms({});
|
|
22
23
|
const [pageTypes, setPageTypes] = useState(allPageTypes);
|
|
23
24
|
const [selectedPageType, setSelectedPageType] = useState<PageType | undefined | null>(initialData?.initialPageType);
|
|
@@ -39,6 +40,18 @@ export const PageSettings = () => {
|
|
|
39
40
|
});
|
|
40
41
|
};
|
|
41
42
|
|
|
43
|
+
const getPlatformFromPermissions = () => {
|
|
44
|
+
const checkPagePremissions = allPermissions.filter((permission) => permission.subject === 'api::page.page');
|
|
45
|
+
|
|
46
|
+
const checkedConditions = checkPagePremissions.filter(
|
|
47
|
+
(permission) =>
|
|
48
|
+
permission.action === 'plugin::content-manager.explorer.create' ||
|
|
49
|
+
permission.action === 'plugin::content-manager.explorer.update'
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
getPlatformFromPermissions();
|
|
54
|
+
|
|
42
55
|
useEffect(() => {
|
|
43
56
|
setSelectedPageType(initialData?.initialPageType);
|
|
44
57
|
|
|
@@ -110,7 +123,11 @@ export const PageSettings = () => {
|
|
|
110
123
|
const { get } = getFetchClient();
|
|
111
124
|
const { data: platFormData } = await get(pageTypeUrl);
|
|
112
125
|
|
|
113
|
-
|
|
126
|
+
const filterPageTypeByPlatform = platFormData[0].pageTypes.filter(
|
|
127
|
+
(data) => allPageTypes?.find((pageData) => pageData.uid === data.uid)
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
setPageTypes(filterPageTypeByPlatform);
|
|
114
131
|
};
|
|
115
132
|
|
|
116
133
|
return (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
2
|
import set from 'lodash/set';
|
|
3
3
|
|
|
4
4
|
import { Stack } from '@strapi/design-system';
|
|
@@ -10,6 +10,7 @@ import PlatformFilter from './PlatformFilter';
|
|
|
10
10
|
import { Platform, useGetPlatforms } from '../../api/platform';
|
|
11
11
|
import { PAGE_TYPE, PAGE_TYPE_NO_FILTER, PLATFORM_NO_FILTER } from '../../constants';
|
|
12
12
|
import { PageType } from '../../api/page-type';
|
|
13
|
+
import { useGetPageTypesForPlatform } from '../../api/platform-page-types';
|
|
13
14
|
|
|
14
15
|
interface PageFiltersProps {
|
|
15
16
|
hidePageType?: boolean;
|
|
@@ -21,10 +22,12 @@ const PageFilters = ({ hidePageType }: PageFiltersProps) => {
|
|
|
21
22
|
const { data: platforms } = useGetPlatforms({});
|
|
22
23
|
|
|
23
24
|
const selectedPlatformTitle = useMemo(() => getPlatformFromQuery(query, platforms), [query, platforms]);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
);
|
|
25
|
+
|
|
26
|
+
const { data: pageTypesForPlatform } = useGetPageTypesForPlatform({
|
|
27
|
+
id: platforms?.find((p) => p.title === selectedPlatformTitle)?.id
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const selectedPageTypeUid = useMemo(() => getPageTypeFromQuery(query, []), [query, platforms, selectedPlatformTitle]);
|
|
28
31
|
|
|
29
32
|
const handleFilterChange = (
|
|
30
33
|
filters: Record<string, any>,
|
|
@@ -88,7 +91,7 @@ const PageFilters = ({ hidePageType }: PageFiltersProps) => {
|
|
|
88
91
|
{!hidePageType && (
|
|
89
92
|
<PageTypeFilter
|
|
90
93
|
onChange={handlePageTypeSelect}
|
|
91
|
-
pageTypes={
|
|
94
|
+
pageTypes={pageTypesForPlatform}
|
|
92
95
|
selectedPageTypeUid={selectedPageTypeUid}
|
|
93
96
|
/>
|
|
94
97
|
)}
|
|
@@ -98,9 +101,6 @@ const PageFilters = ({ hidePageType }: PageFiltersProps) => {
|
|
|
98
101
|
|
|
99
102
|
export default PageFilters;
|
|
100
103
|
|
|
101
|
-
const getPageTypesFromPlatformTitle = (selectedPlatformTitle?: string, platforms?: Platform[]) =>
|
|
102
|
-
platforms?.find((p) => p.title === selectedPlatformTitle)?.pageTypes;
|
|
103
|
-
|
|
104
104
|
const getPageTypeFromQuery = (query: Record<string, any>, pageTypes?: PageType[]) => {
|
|
105
105
|
const pageTypeFromQuery = query?.filters?.$and?.find(
|
|
106
106
|
(x?: Record<string, any>) => Object.keys(x || {})?.[0] === PAGE_TYPE
|
package/dist/package.json
CHANGED
|
@@ -2,30 +2,83 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const constants_1 = require("../../shared/utils/constants");
|
|
4
4
|
exports.default = async ({ strapi }) => {
|
|
5
|
-
var _a;
|
|
5
|
+
var _a, _b;
|
|
6
6
|
try {
|
|
7
7
|
const pageTypes = (await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_TYPE_UID, {
|
|
8
8
|
limit: -1
|
|
9
9
|
})));
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const platforms = (await ((_b = strapi.entityService) === null || _b === void 0 ? void 0 : _b.findMany(constants_1.PLATFORM_UID, {
|
|
11
|
+
limit: -1
|
|
12
|
+
})));
|
|
13
|
+
const platformPagePermissions = platforms.map((platform) => {
|
|
14
|
+
return pageTypes.map((pageType) => {
|
|
15
|
+
const name = `platform-is-${platform.title}-${pageType.uid}`;
|
|
16
|
+
const displayName = `${platform.title}-${pageType.title}`;
|
|
17
|
+
return {
|
|
18
|
+
plugin: 'page-builder',
|
|
19
|
+
name,
|
|
20
|
+
displayName,
|
|
21
|
+
category: `${platform.title} Page roles`,
|
|
22
|
+
handler: async () => {
|
|
23
|
+
return {
|
|
24
|
+
$and: [
|
|
25
|
+
{
|
|
26
|
+
'platform.id': {
|
|
27
|
+
$eq: platform.id
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
'pageType.uid': {
|
|
32
|
+
$eq: pageType.uid
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
uid: {
|
|
37
|
+
$eq: pageType.uid
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
const pageTypePermissions = pageTypes.map((pageType) => {
|
|
47
|
+
const name = `pageType-permission-${pageType.uid}`;
|
|
48
|
+
const displayName = `pageType ${pageType.title}`;
|
|
49
|
+
return {
|
|
50
|
+
plugin: 'page-builder',
|
|
51
|
+
name,
|
|
52
|
+
displayName,
|
|
53
|
+
category: `Platform pageType roles`,
|
|
54
|
+
handler: async () => {
|
|
55
|
+
return {
|
|
56
|
+
uid: {
|
|
57
|
+
$eq: pageType.uid
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
const platformCollectiontypePermissions = platforms.map((platform) => {
|
|
64
|
+
const name = `platform-is-${platform.title}`;
|
|
65
|
+
const displayName = platform.title;
|
|
13
66
|
return {
|
|
14
67
|
plugin: 'page-builder',
|
|
15
68
|
name,
|
|
16
69
|
displayName,
|
|
17
|
-
category: '
|
|
70
|
+
category: 'Platform CollectionType roles',
|
|
18
71
|
handler: async () => {
|
|
19
72
|
return {
|
|
20
73
|
$or: [
|
|
21
74
|
{
|
|
22
|
-
'
|
|
23
|
-
$eq:
|
|
75
|
+
'platform.id': {
|
|
76
|
+
$eq: platform.id
|
|
24
77
|
}
|
|
25
78
|
},
|
|
26
79
|
{
|
|
27
|
-
|
|
28
|
-
$eq:
|
|
80
|
+
id: {
|
|
81
|
+
$eq: platform.id
|
|
29
82
|
}
|
|
30
83
|
}
|
|
31
84
|
]
|
|
@@ -33,8 +86,13 @@ exports.default = async ({ strapi }) => {
|
|
|
33
86
|
}
|
|
34
87
|
};
|
|
35
88
|
});
|
|
89
|
+
const allPermissions = [
|
|
90
|
+
...platformPagePermissions.flat(),
|
|
91
|
+
...pageTypePermissions.flat(),
|
|
92
|
+
...platformCollectiontypePermissions
|
|
93
|
+
];
|
|
36
94
|
// @ts-ignore shitty types
|
|
37
|
-
await strapi.admin.services.permission.conditionProvider.registerMany(
|
|
95
|
+
await strapi.admin.services.permission.conditionProvider.registerMany(allPermissions);
|
|
38
96
|
}
|
|
39
97
|
catch {
|
|
40
98
|
console.log('Cannot set page permissions');
|
|
@@ -10,7 +10,7 @@ const getPageBySlug = (strapi) => {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
type Query {
|
|
13
|
-
getPageBySlug(path: String, _locale: String, _publicationState: PublicationState): PageEntity
|
|
13
|
+
getPageBySlug(path: String, _domain: String, _locale: String, _publicationState: PublicationState): PageEntity
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
`;
|
|
@@ -22,45 +22,52 @@ const getPageBySlug = (strapi) => {
|
|
|
22
22
|
getPageBySlug: {
|
|
23
23
|
resolve: async (_parent, args, ctx) => {
|
|
24
24
|
var _a;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const getPage = async () => {
|
|
30
|
-
var _a, _b, _c;
|
|
31
|
-
const transformedArgs = transformArgs(filteredArgs, {
|
|
32
|
-
contentType: strapi.contentTypes[constants_1.PAGE_UID],
|
|
33
|
-
usePagination: false
|
|
34
|
-
});
|
|
35
|
-
const results = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_UID, {
|
|
36
|
-
filters: transformedArgs,
|
|
37
|
-
locale: args._locale,
|
|
38
|
-
publicationState: args._publicationState,
|
|
39
|
-
populate: '*'
|
|
40
|
-
}));
|
|
41
|
-
const entityResponse = toEntityResponse((results === null || results === void 0 ? void 0 : results[0]) || {}, {
|
|
42
|
-
args: transformedArgs,
|
|
43
|
-
resourceUID: constants_1.PAGE_UID
|
|
44
|
-
});
|
|
45
|
-
if (!(entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) || Object.keys(entityResponse.value).length === 0) {
|
|
46
|
-
throw new Error(ctx.koaContext.response.message);
|
|
47
|
-
}
|
|
48
|
-
const collectionTypeDataFilter = (_c = (_b = entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) === null || _b === void 0 ? void 0 : _b.collectionTypeData) === null || _c === void 0 ? void 0 : _c.filter(Boolean);
|
|
49
|
-
const collectionType = collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter === null || collectionTypeDataFilter === void 0 ? void 0 : collectionTypeDataFilter[0] : null;
|
|
50
|
-
const addedAttributes = {
|
|
51
|
-
collectionType: collectionType
|
|
25
|
+
try {
|
|
26
|
+
const filteredArgs = {
|
|
27
|
+
...(0, filter_underscore_arguments_1.filterUnderscoreArguments)(args),
|
|
28
|
+
platform: { domain: args._domain }
|
|
52
29
|
};
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
30
|
+
const { toEntityResponse } = strapi.plugin('graphql').service('format').returnTypes;
|
|
31
|
+
const getPage = async () => {
|
|
32
|
+
var _a, _b, _c;
|
|
33
|
+
const transformedArgs = transformArgs(filteredArgs, {
|
|
34
|
+
contentType: strapi.contentTypes[constants_1.PAGE_UID],
|
|
35
|
+
usePagination: false
|
|
36
|
+
});
|
|
37
|
+
const results = await ((_a = strapi.entityService) === null || _a === void 0 ? void 0 : _a.findMany(constants_1.PAGE_UID, {
|
|
38
|
+
filters: filteredArgs,
|
|
39
|
+
locale: args._locale,
|
|
40
|
+
publicationState: args._publicationState,
|
|
41
|
+
populate: '*'
|
|
42
|
+
}));
|
|
43
|
+
const entityResponse = toEntityResponse((results === null || results === void 0 ? void 0 : results[0]) || {}, {
|
|
44
|
+
args: transformedArgs,
|
|
45
|
+
resourceUID: constants_1.PAGE_UID
|
|
46
|
+
});
|
|
47
|
+
if (!(entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) || Object.keys(entityResponse.value).length === 0) {
|
|
48
|
+
throw new Error(ctx.koaContext.response.message);
|
|
49
|
+
}
|
|
50
|
+
const collectionTypeDataFilter = (_c = (_b = entityResponse === null || entityResponse === void 0 ? void 0 : entityResponse.value) === null || _b === void 0 ? void 0 : _b.collectionTypeData) === null || _c === void 0 ? void 0 : _c.filter(Boolean);
|
|
51
|
+
const collectionType = collectionTypeDataFilter.length === 1 ? collectionTypeDataFilter === null || collectionTypeDataFilter === void 0 ? void 0 : collectionTypeDataFilter[0] : null;
|
|
52
|
+
const addedAttributes = {
|
|
53
|
+
collectionType: collectionType
|
|
54
|
+
};
|
|
55
|
+
const result = {
|
|
56
|
+
...entityResponse.value,
|
|
57
|
+
...addedAttributes
|
|
58
|
+
};
|
|
59
|
+
return result;
|
|
56
60
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
const results = await getPage();
|
|
62
|
+
if (((_a = Object.values(results)) === null || _a === void 0 ? void 0 : _a.filter(Boolean).length) > 0) {
|
|
63
|
+
return results;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new Error(ctx.koaContext.response.message);
|
|
67
|
+
}
|
|
62
68
|
}
|
|
63
|
-
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.log('Error in getPageBySlug:', error);
|
|
64
71
|
throw new Error(ctx.koaContext.response.message);
|
|
65
72
|
}
|
|
66
73
|
}
|