@webbio/strapi-plugin-page-builder 0.9.13-authentication → 0.9.14-authentication
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/dist/package.json +1 -1
- package/dist/server/content-types/category/category.js +0 -0
- package/dist/server/content-types/category/category.json +27 -0
- package/dist/server/content-types/page-version/schema.json +16 -0
- package/dist/server/controllers/page-version.js +7 -0
- package/dist/server/graphql/page-by-path.js +1 -1
- package/dist/server/graphql/page-by-slug.js +89 -0
- package/dist/server/middlewares/private-content.js +13 -0
- package/dist/server/routes/page-version.js +7 -0
- package/dist/server/services/authentication.js +186 -0
- package/dist/server/services/page-version.js +7 -0
- package/dist/server/services/private-content/acceptedMail/acceptMail.email.template.text.js +12 -0
- package/dist/server/services/private-content/acceptedMail/acceptMail.interface.js +2 -0
- package/dist/server/services/private-content/graphql/resolvers/find.js +0 -0
- package/dist/server/services/private-content/graphql/resolvers/findAll.js +0 -0
- package/dist/server/services/private-content/graphql/resolvers/findOnePage.js +1 -1
- package/dist/server/services/private-content/graphql/resolvers/findPage.js +5 -4
- package/dist/server/utils/graphql.js +100 -0
- package/dist/server/utils/paginationValidation.js +31 -0
- package/dist/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/server/graphql/page-by-path.ts +1 -1
- package/server/services/private-content/graphql/resolvers/findOnePage.ts +1 -1
- package/server/services/private-content/graphql/resolvers/findPage.ts +4 -4
package/dist/package.json
CHANGED
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kind": "collectionType",
|
|
3
|
+
"collectionName": "categories",
|
|
4
|
+
"info": {
|
|
5
|
+
"singularName": "category",
|
|
6
|
+
"pluralName": "categories",
|
|
7
|
+
"displayName": "Category"
|
|
8
|
+
},
|
|
9
|
+
"options": {
|
|
10
|
+
"draftAndPublish": false
|
|
11
|
+
},
|
|
12
|
+
"pluginOptions": {
|
|
13
|
+
"i18n": {
|
|
14
|
+
"localized": true
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"attributes": {
|
|
18
|
+
"title": {
|
|
19
|
+
"pluginOptions": {
|
|
20
|
+
"i18n": {
|
|
21
|
+
"localized": true
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"type": "string"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kind": "collectionType",
|
|
3
|
+
"collectionName": "page_versions",
|
|
4
|
+
"info": {
|
|
5
|
+
"singularName": "page-version",
|
|
6
|
+
"pluralName": "page-versions",
|
|
7
|
+
"displayName": "page-version"
|
|
8
|
+
},
|
|
9
|
+
"options": {
|
|
10
|
+
"draftAndPublish": false,
|
|
11
|
+
"comment": ""
|
|
12
|
+
},
|
|
13
|
+
"attributes": {
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -63,7 +63,7 @@ const getPageByPath = (strapi) => {
|
|
|
63
63
|
};
|
|
64
64
|
const results = await getPage();
|
|
65
65
|
if (((_a = Object.values(results)) === null || _a === void 0 ? void 0 : _a.filter(Boolean).length) > 0) {
|
|
66
|
-
if (!((_b = results === null || results === void 0 ? void 0 : results.platform) === null || _b === void 0 ? void 0 : _b.isPrivate) && !results.isPrivate) {
|
|
66
|
+
if (!((_b = results === null || results === void 0 ? void 0 : results.platform) === null || _b === void 0 ? void 0 : _b.isPrivate) && !(results === null || results === void 0 ? void 0 : results.isPrivate)) {
|
|
67
67
|
return results;
|
|
68
68
|
}
|
|
69
69
|
if ((((_c = results === null || results === void 0 ? void 0 : results.platform) === null || _c === void 0 ? void 0 : _c.isPrivate) === true && ctx.koaContext.req.headers.authorization) ||
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const filter_underscore_arguments_1 = require("../utils/filter-underscore-arguments");
|
|
4
|
+
const constants_1 = require("../../shared/utils/constants");
|
|
5
|
+
const getPageBySlug = (strapi) => {
|
|
6
|
+
const typeDefs = () => {
|
|
7
|
+
return `
|
|
8
|
+
extend type Page {
|
|
9
|
+
collectionType: GenericMorph
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type Query {
|
|
13
|
+
getPageBySlug(path: String, _domain: String, _locale: String, _publicationState: PublicationState): PageEntity
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
`;
|
|
17
|
+
};
|
|
18
|
+
const resolvers = (strapi) => {
|
|
19
|
+
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
20
|
+
return {
|
|
21
|
+
Query: {
|
|
22
|
+
getPageBySlug: {
|
|
23
|
+
resolve: async (_parent, args, ctx) => {
|
|
24
|
+
var _a;
|
|
25
|
+
try {
|
|
26
|
+
const filteredArgs = {
|
|
27
|
+
...(0, filter_underscore_arguments_1.filterUnderscoreArguments)(args),
|
|
28
|
+
platform: { domain: args._domain }
|
|
29
|
+
};
|
|
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;
|
|
60
|
+
};
|
|
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
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.log('Error in getPageBySlug:', error);
|
|
71
|
+
throw new Error(ctx.koaContext.response.message);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const resolversConfig = {
|
|
79
|
+
'Query.getPageBySlug': {
|
|
80
|
+
auth: false
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
typeDefs: typeDefs(),
|
|
85
|
+
resolvers: resolvers(strapi),
|
|
86
|
+
resolversConfig
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
exports.default = getPageBySlug;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `private-content` middleware
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = (config, { strapi }) => {
|
|
7
|
+
// Add your own logic here.
|
|
8
|
+
return async (ctx, next) => {
|
|
9
|
+
strapi.log.info('[PRIVATE CONTENT] Before');
|
|
10
|
+
await next();
|
|
11
|
+
strapi.log.info('[PRIVATE CONTENT] After');
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@strapi/utils");
|
|
4
|
+
const utils_2 = require("@strapi/utils");
|
|
5
|
+
const { ApplicationError } = utils_2.errors;
|
|
6
|
+
const registerSchema = utils_1.yup.object({
|
|
7
|
+
email: utils_1.yup.string().email().required(),
|
|
8
|
+
password: utils_1.yup.string().required(),
|
|
9
|
+
platformId: utils_1.yup.number().required()
|
|
10
|
+
});
|
|
11
|
+
exports.default = {
|
|
12
|
+
registerAuthentication() {
|
|
13
|
+
this.extendUser();
|
|
14
|
+
this.extendGraphQL();
|
|
15
|
+
},
|
|
16
|
+
extendUser() {
|
|
17
|
+
const user = strapi.contentType('plugin::users-permissions.user');
|
|
18
|
+
user.attributes = {
|
|
19
|
+
...user.attributes,
|
|
20
|
+
firstName: {
|
|
21
|
+
type: 'string'
|
|
22
|
+
},
|
|
23
|
+
lastName: {
|
|
24
|
+
type: 'string'
|
|
25
|
+
},
|
|
26
|
+
company: {
|
|
27
|
+
type: 'string'
|
|
28
|
+
},
|
|
29
|
+
jobTitle: {
|
|
30
|
+
type: 'string'
|
|
31
|
+
},
|
|
32
|
+
address: {
|
|
33
|
+
type: 'string'
|
|
34
|
+
},
|
|
35
|
+
postalCode: {
|
|
36
|
+
type: 'string'
|
|
37
|
+
},
|
|
38
|
+
city: {
|
|
39
|
+
type: 'string'
|
|
40
|
+
},
|
|
41
|
+
country: {
|
|
42
|
+
type: 'string'
|
|
43
|
+
},
|
|
44
|
+
phone: {
|
|
45
|
+
type: 'string'
|
|
46
|
+
},
|
|
47
|
+
platform: {
|
|
48
|
+
type: 'relation',
|
|
49
|
+
relation: 'oneToOne',
|
|
50
|
+
target: 'api::platform.platform'
|
|
51
|
+
},
|
|
52
|
+
categories: {
|
|
53
|
+
type: 'relation',
|
|
54
|
+
relation: 'oneToMany',
|
|
55
|
+
target: 'api::category.category'
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
delete user.attributes.username;
|
|
59
|
+
},
|
|
60
|
+
extendGraphQL() {
|
|
61
|
+
const extensionService = strapi.plugin('graphql').service('extension');
|
|
62
|
+
const extension = () => ({
|
|
63
|
+
typeDefs: `
|
|
64
|
+
input LoginInput {
|
|
65
|
+
email: String!
|
|
66
|
+
password: String!
|
|
67
|
+
platformId: ID!
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
input RegisterInput {
|
|
71
|
+
email: String!
|
|
72
|
+
password: String!
|
|
73
|
+
firstName: String
|
|
74
|
+
lastName: String
|
|
75
|
+
company: String
|
|
76
|
+
jobTitle: String
|
|
77
|
+
address: String
|
|
78
|
+
postalCode: String
|
|
79
|
+
city: String
|
|
80
|
+
country: String
|
|
81
|
+
phone: String
|
|
82
|
+
subscribeToNewsletter: Boolean
|
|
83
|
+
categories: [ID]
|
|
84
|
+
platformId: ID!
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
type LoginResponse {
|
|
88
|
+
jwt: String
|
|
89
|
+
user: User
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type RegisterResponse {
|
|
93
|
+
user: User
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
type ForgotPasswordResponse {
|
|
97
|
+
ok: Boolean!
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
type User {
|
|
101
|
+
id: ID!
|
|
102
|
+
email: String!
|
|
103
|
+
confirmed: Boolean
|
|
104
|
+
blocked: Boolean
|
|
105
|
+
activated: Boolean
|
|
106
|
+
platformId: ID!
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type Mutation {
|
|
110
|
+
platformLogin(input: LoginInput!): LoginResponse
|
|
111
|
+
platformRegister(input: RegisterInput!): RegisterResponse
|
|
112
|
+
platformForgotPassword(email: String!): ForgotPasswordResponse
|
|
113
|
+
}
|
|
114
|
+
`,
|
|
115
|
+
resolversConfig: {
|
|
116
|
+
'Mutation.platformLogin': {
|
|
117
|
+
auth: false
|
|
118
|
+
},
|
|
119
|
+
'Mutation.platformRegister': {
|
|
120
|
+
auth: false
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
resolvers: {
|
|
124
|
+
Mutation: {
|
|
125
|
+
platformLogin: {
|
|
126
|
+
resolve() {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
platformRegister: {
|
|
131
|
+
async resolve(parent, args) {
|
|
132
|
+
const pluginStore = strapi.store({ type: 'plugin', name: 'users-permissions' });
|
|
133
|
+
const settings = await pluginStore.get({ key: 'advanced' });
|
|
134
|
+
if (!settings.allow_register) {
|
|
135
|
+
throw new ApplicationError('Register action is currently disabled');
|
|
136
|
+
}
|
|
137
|
+
await (0, utils_1.validateYupSchema)(args.input, registerSchema);
|
|
138
|
+
const { email, platformId } = args.input;
|
|
139
|
+
const role = await strapi
|
|
140
|
+
.query('plugin::users-permissions.role')
|
|
141
|
+
.findOne({ where: { type: settings.default_role } });
|
|
142
|
+
if (!role) {
|
|
143
|
+
throw new ApplicationError('Impossible to find the default role');
|
|
144
|
+
}
|
|
145
|
+
const conflictingUserCount = await strapi.query('plugin::users-permissions.user').count({
|
|
146
|
+
where: {
|
|
147
|
+
email,
|
|
148
|
+
platform: {
|
|
149
|
+
id: platformId
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (conflictingUserCount > 0) {
|
|
154
|
+
throw new ApplicationError('Email is already taken');
|
|
155
|
+
}
|
|
156
|
+
const userData = {
|
|
157
|
+
...args.input,
|
|
158
|
+
role: role.id,
|
|
159
|
+
email: email.toLowerCase(),
|
|
160
|
+
confirmed: false,
|
|
161
|
+
provider: 'local',
|
|
162
|
+
categories: args.input.categories,
|
|
163
|
+
platform: {
|
|
164
|
+
set: platformId
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const createdUser = await strapi.query('plugin::users-permissions.user').create({
|
|
168
|
+
data: userData,
|
|
169
|
+
populate: ['role', 'platform', 'categories']
|
|
170
|
+
});
|
|
171
|
+
const userSchema = strapi.getModel('plugin::users-permissions.user');
|
|
172
|
+
const sanitizedUser = await utils_2.sanitize.contentAPI.output(createdUser, userSchema, {
|
|
173
|
+
auth: false
|
|
174
|
+
});
|
|
175
|
+
return {
|
|
176
|
+
user: sanitizedUser
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
extensionService.use(extension);
|
|
184
|
+
},
|
|
185
|
+
async register(ctx) { }
|
|
186
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.acceptMailTxtEmail = void 0;
|
|
7
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
+
const acceptMailTxtEmail = (acceptMailData) => {
|
|
9
|
+
const template = handlebars_1.default.compile(acceptMailData.text);
|
|
10
|
+
return template(acceptMailData);
|
|
11
|
+
};
|
|
12
|
+
exports.acceptMailTxtEmail = acceptMailTxtEmail;
|
|
File without changes
|
|
File without changes
|
|
@@ -16,7 +16,7 @@ exports.page = {
|
|
|
16
16
|
const sanitizedQuery = await utils_1.sanitize.contentAPI.query(populatedArgs, strapi.contentType(constants_1.PAGE_UID));
|
|
17
17
|
const value = await strapi.entityService.findOne(uid, args.id, (0, fp_1.omit)('id', sanitizedQuery));
|
|
18
18
|
// @ts-ignore Strapi types are the best
|
|
19
|
-
if (!((_a = value === null || value === void 0 ? void 0 : value.platform) === null || _a === void 0 ? void 0 : _a.isPrivate) && !value.isPrivate) {
|
|
19
|
+
if (!((_a = value === null || value === void 0 ? void 0 : value.platform) === null || _a === void 0 ? void 0 : _a.isPrivate) && !(value === null || value === void 0 ? void 0 : value.isPrivate)) {
|
|
20
20
|
return toEntityResponse(value, { args: transformedArgs, resourceUID: uid });
|
|
21
21
|
}
|
|
22
22
|
if (
|
|
@@ -21,15 +21,16 @@ exports.pages = {
|
|
|
21
21
|
if (decodedToken) {
|
|
22
22
|
// @ts-ignore
|
|
23
23
|
const filteredItems = value.filter((item) => {
|
|
24
|
+
var _a, _b;
|
|
24
25
|
// @ts-ignore
|
|
25
|
-
if (item.platform.isPrivate === true && user.platform.id === item.platform.id) {
|
|
26
|
+
if (((_a = item.platform) === null || _a === void 0 ? void 0 : _a.isPrivate) === true && user.platform.id === item.platform.id) {
|
|
26
27
|
return item;
|
|
27
28
|
}
|
|
28
|
-
if (item.isPrivate === true && user.platform.id === item.platform.id) {
|
|
29
|
+
if ((item === null || item === void 0 ? void 0 : item.isPrivate) === true && user.platform.id === item.platform.id) {
|
|
29
30
|
return item;
|
|
30
31
|
}
|
|
31
32
|
// @ts-ignore
|
|
32
|
-
if (item.platform.isPrivate !== true && item.isPrivate !== true) {
|
|
33
|
+
if (((_b = item.platform) === null || _b === void 0 ? void 0 : _b.isPrivate) !== true && (item === null || item === void 0 ? void 0 : item.isPrivate) !== true) {
|
|
33
34
|
return item;
|
|
34
35
|
}
|
|
35
36
|
});
|
|
@@ -37,7 +38,7 @@ exports.pages = {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
// @ts-ignore
|
|
40
|
-
const filteredItems = value.filter((item) => item.platform.isPrivate !== true && item.isPrivate !== true);
|
|
41
|
+
const filteredItems = value.filter((item) => { var _a; return ((_a = item.platform) === null || _a === void 0 ? void 0 : _a.isPrivate) !== true && (item === null || item === void 0 ? void 0 : item.isPrivate) !== true; });
|
|
41
42
|
return toEntityResponseCollection(filteredItems, { args: transformedArgs, resourceUID: uid });
|
|
42
43
|
}
|
|
43
44
|
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerGraphQLResolvers = void 0;
|
|
4
|
+
const constants_1 = require("../../shared/utils/constants");
|
|
5
|
+
const findPageByPath = (strapi) => {
|
|
6
|
+
const typeDefs = `
|
|
7
|
+
type Query {
|
|
8
|
+
findPageByPath(path: String, locale: I18NLocaleCode): PageEntityResponse
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
const resolvers = (strapi) => {
|
|
12
|
+
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
13
|
+
const { toEntityResponse, toEntityResponseCollection } = strapi.plugin('graphql').service('format').returnTypes;
|
|
14
|
+
return {
|
|
15
|
+
Query: {
|
|
16
|
+
findPageByPath: {
|
|
17
|
+
resolve: async (parent, args, ctx) => {
|
|
18
|
+
const contentType = strapi.getModel(constants_1.PAGE_UID);
|
|
19
|
+
const transformedArgs = transformArgs(args, { contentType });
|
|
20
|
+
const queryResult = await strapi.entityService.findMany(contentType.uid, {
|
|
21
|
+
filters: {
|
|
22
|
+
path: {
|
|
23
|
+
$eq: transformedArgs.path
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
locale: transformedArgs.locale
|
|
27
|
+
});
|
|
28
|
+
const result = queryResult === null || queryResult === void 0 ? void 0 : queryResult[0];
|
|
29
|
+
return toEntityResponse(result, {
|
|
30
|
+
args: transformedArgs,
|
|
31
|
+
resourceUID: contentType.uid
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const resolversConfig = {
|
|
39
|
+
'Query.findPageByPath': {
|
|
40
|
+
auth: false
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
typeDefs,
|
|
45
|
+
resolvers: resolvers(strapi),
|
|
46
|
+
resolversConfig
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const findPagePaths = (strapi) => {
|
|
50
|
+
const typeDefs = `
|
|
51
|
+
type PageByPath {
|
|
52
|
+
id: Int!
|
|
53
|
+
path: String!
|
|
54
|
+
title: String!
|
|
55
|
+
locale: String!
|
|
56
|
+
pageType: ENUM_PAGE_PAGETYPE
|
|
57
|
+
updatedAt: DateTime!
|
|
58
|
+
publishedAt: DateTime!
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type Query {
|
|
62
|
+
findPagePaths(locale: String, pageType: String = "all"): [PageByPath]
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
const resolvers = (strapi) => {
|
|
66
|
+
const { transformArgs } = strapi.plugin('graphql').service('builders').utils;
|
|
67
|
+
return {
|
|
68
|
+
Query: {
|
|
69
|
+
findPagePaths: {
|
|
70
|
+
resolve: async (parent, args, ctx) => {
|
|
71
|
+
const contentType = strapi.getModel(constants_1.PAGE_UID);
|
|
72
|
+
const transformedArgs = transformArgs(args, { contentType });
|
|
73
|
+
const queryResult = await strapi.entityService.findMany(contentType.uid, {
|
|
74
|
+
populate: '*',
|
|
75
|
+
locale: transformedArgs.locale
|
|
76
|
+
});
|
|
77
|
+
const result = queryResult.filter((page) => page === null || page === void 0 ? void 0 : page.path);
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
const resolversConfig = {
|
|
85
|
+
'Query.findPagePaths': {
|
|
86
|
+
auth: false
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
typeDefs,
|
|
91
|
+
resolvers: resolvers(strapi),
|
|
92
|
+
resolversConfig
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
const registerGraphQLResolvers = (strapi) => {
|
|
96
|
+
const extensionService = strapi.plugin('graphql').service('extension');
|
|
97
|
+
extensionService.use(findPageByPath(strapi));
|
|
98
|
+
extensionService.use(findPagePaths(strapi));
|
|
99
|
+
};
|
|
100
|
+
exports.registerGraphQLResolvers = registerGraphQLResolvers;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Pagination = void 0;
|
|
4
|
+
class Pagination {
|
|
5
|
+
static checkPagination(page, pageSize) {
|
|
6
|
+
const startPage = page === 1 ? 0 : page - 1;
|
|
7
|
+
const start = startPage * pageSize;
|
|
8
|
+
const limit = (startPage + 1) * pageSize;
|
|
9
|
+
return { start, limit };
|
|
10
|
+
}
|
|
11
|
+
static async getPaginationInfo(transformedpageArgs, transformArgs, start, pageSize, entityResponse, uid) {
|
|
12
|
+
var _a;
|
|
13
|
+
const total = await ((_a = strapi === null || strapi === void 0 ? void 0 : strapi.entityService) === null || _a === void 0 ? void 0 : _a.count(uid, {
|
|
14
|
+
filters: {
|
|
15
|
+
...transformArgs.filters,
|
|
16
|
+
hasPage: { $eq: true },
|
|
17
|
+
page: { ...transformedpageArgs.filters }
|
|
18
|
+
}
|
|
19
|
+
}));
|
|
20
|
+
const pageCount = Math.ceil(total / pageSize);
|
|
21
|
+
const page = Math.floor(start / pageSize) + 1;
|
|
22
|
+
entityResponse.metaInfo = {
|
|
23
|
+
total,
|
|
24
|
+
pageCount,
|
|
25
|
+
page,
|
|
26
|
+
pageSize
|
|
27
|
+
};
|
|
28
|
+
return entityResponse;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.Pagination = Pagination;
|