strapi-plugin-comments 2.2.10 → 2.2.11
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/README.md +116 -23
- package/admin/src/index.js +1 -1
- package/package.json +3 -3
- package/server/controllers/client.js +18 -0
- package/server/graphql/queries/findAllPerAuthor.d.ts +21 -0
- package/server/graphql/queries/findAllPerAuthor.js +40 -0
- package/server/graphql/queries/index.js +2 -0
- package/server/graphql/types/comment-author-type.d.ts +4 -0
- package/server/graphql/types/comment-author-type.js +8 -0
- package/server/graphql/types/index.js +4 -0
- package/server/graphql/types/response-find-all-per-author.d.ts +4 -0
- package/server/graphql/types/response-find-all-per-author.js +9 -0
- package/server/routes/client.js +28 -0
- package/server/services/common.js +30 -48
- package/server/services/utils/parsers.d.ts +6 -0
- package/server/services/utils/parsers.js +63 -0
- package/server/utils/constants.d.ts +4 -0
- package/server/utils/constants.js +5 -1
- package/tsconfig.tsbuildinfo +1 -1
package/README.md
CHANGED
|
@@ -134,7 +134,7 @@ In our minimum support we're following [official Node.js releases timelines](htt
|
|
|
134
134
|
|
|
135
135
|
**Supported Strapi versions**:
|
|
136
136
|
|
|
137
|
-
- Strapi v4.
|
|
137
|
+
- Strapi v4.10.7 (recently tested)
|
|
138
138
|
- Strapi v4.x
|
|
139
139
|
|
|
140
140
|
> This plugin is designed for **Strapi v4** and is not working with v3.x. To get version for **Strapi v3** install version [v1.x](https://github.com/VirtusLab-Open-Source/strapi-plugin-comments/tree/strapi-v3).
|
|
@@ -361,6 +361,50 @@ Return a flat structure of comments for specified instance of Content Type like
|
|
|
361
361
|
- [sorting](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/sort-pagination.html#sorting)
|
|
362
362
|
- [pagination](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/sort-pagination.html#pagination)
|
|
363
363
|
|
|
364
|
+
### Get Comments (by Author)
|
|
365
|
+
|
|
366
|
+
_GraphQL equivalent: [Public GraphQL API -> Get Comments (by Author)](#get-comments-by-author-1)_
|
|
367
|
+
|
|
368
|
+
`GET <host>/api/comments/author/<id>/<?type>`
|
|
369
|
+
|
|
370
|
+
Return a flat structure of comments by specified Author for example `Author` with `ID: 1`
|
|
371
|
+
|
|
372
|
+
**Example URL**: `https://localhost:1337/api/comments/author/1` - get comments by `ID:1` of Strapi User
|
|
373
|
+
**Example URL**: `https://localhost:1337/api/comments/author/1/generic` - get comments by `ID:1` of Generic User
|
|
374
|
+
|
|
375
|
+
**Example response body**
|
|
376
|
+
|
|
377
|
+
```json
|
|
378
|
+
{
|
|
379
|
+
"data": [
|
|
380
|
+
{
|
|
381
|
+
// -- Comment Model fields ---
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
// -- Comment Model fields ---
|
|
385
|
+
}
|
|
386
|
+
// ...
|
|
387
|
+
],
|
|
388
|
+
"meta": {
|
|
389
|
+
"pagination": {
|
|
390
|
+
// payload based on Strapi REST Pagination specification
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
**Possible response codes**
|
|
397
|
+
|
|
398
|
+
- `200` - Successful. Response with list of comments (can be empty)
|
|
399
|
+
- `400` - Bad Request. Requested list for not valid / not existing Content Type
|
|
400
|
+
|
|
401
|
+
#### Strapi REST API properties support:
|
|
402
|
+
|
|
403
|
+
- [filtering](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/filtering-locale-publication.html#filtering)
|
|
404
|
+
- [field selection](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/populating-fields.html#field-selection)
|
|
405
|
+
- [sorting](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/sort-pagination.html#sorting)
|
|
406
|
+
- [pagination](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/sort-pagination.html#pagination)
|
|
407
|
+
|
|
364
408
|
### Post a Comment
|
|
365
409
|
|
|
366
410
|
_GraphQL equivalent: [Public GraphQL API -> Post a Comments](#post-a-comment-1)_
|
|
@@ -534,13 +578,14 @@ _REST API equivalent: [Public REST API -> Get Comments](#get-comments)_
|
|
|
534
578
|
|
|
535
579
|
```graphql
|
|
536
580
|
query {
|
|
537
|
-
|
|
538
|
-
relation: "api::page.page:1"
|
|
539
|
-
filters: { content: { contains: "Test" } }
|
|
540
|
-
) {
|
|
581
|
+
findAllInHierarchy(relation: "api::page.page:1") {
|
|
541
582
|
id
|
|
542
583
|
content
|
|
543
584
|
blocked
|
|
585
|
+
children {
|
|
586
|
+
id
|
|
587
|
+
content
|
|
588
|
+
}
|
|
544
589
|
threadOf {
|
|
545
590
|
id
|
|
546
591
|
}
|
|
@@ -557,20 +602,28 @@ query {
|
|
|
557
602
|
```json
|
|
558
603
|
{
|
|
559
604
|
"data": {
|
|
560
|
-
"
|
|
605
|
+
"findAllInHierarchy": [
|
|
561
606
|
{
|
|
562
|
-
"id":
|
|
607
|
+
"id": 1,
|
|
563
608
|
"content": "Test",
|
|
564
609
|
"blocked": false,
|
|
610
|
+
"children": [
|
|
611
|
+
{
|
|
612
|
+
"id": 6,
|
|
613
|
+
"content": "Text to search for"
|
|
614
|
+
}
|
|
615
|
+
// ...
|
|
616
|
+
],
|
|
565
617
|
"threadOf": null,
|
|
566
618
|
"author": {
|
|
567
619
|
"id": "123456",
|
|
568
620
|
"name": "Joe Doe"
|
|
569
621
|
}
|
|
570
|
-
}
|
|
622
|
+
}
|
|
571
623
|
// ...
|
|
572
624
|
]
|
|
573
625
|
}
|
|
626
|
+
}
|
|
574
627
|
```
|
|
575
628
|
|
|
576
629
|
#### Strapi GraphQL API properties support:
|
|
@@ -585,14 +638,13 @@ _REST API equivalent: [Public REST API -> Get Comments (flat structure)](#get-co
|
|
|
585
638
|
|
|
586
639
|
```graphql
|
|
587
640
|
query {
|
|
588
|
-
|
|
641
|
+
findAllFlat(
|
|
642
|
+
relation: "api::page.page:1"
|
|
643
|
+
filters: { content: { contains: "Test" } }
|
|
644
|
+
) {
|
|
589
645
|
id
|
|
590
646
|
content
|
|
591
647
|
blocked
|
|
592
|
-
children {
|
|
593
|
-
id
|
|
594
|
-
content
|
|
595
|
-
}
|
|
596
648
|
threadOf {
|
|
597
649
|
id
|
|
598
650
|
}
|
|
@@ -609,28 +661,69 @@ query {
|
|
|
609
661
|
```json
|
|
610
662
|
{
|
|
611
663
|
"data": {
|
|
612
|
-
"
|
|
664
|
+
"findAllFlat": [
|
|
613
665
|
{
|
|
614
|
-
"id":
|
|
666
|
+
"id": 3,
|
|
615
667
|
"content": "Test",
|
|
616
668
|
"blocked": false,
|
|
617
|
-
"children": [
|
|
618
|
-
{
|
|
619
|
-
"id": 6,
|
|
620
|
-
"content": "Text to search for"
|
|
621
|
-
}
|
|
622
|
-
// ...
|
|
623
|
-
],
|
|
624
669
|
"threadOf": null,
|
|
625
670
|
"author": {
|
|
626
671
|
"id": "123456",
|
|
627
672
|
"name": "Joe Doe"
|
|
628
673
|
}
|
|
629
|
-
}
|
|
674
|
+
},
|
|
630
675
|
// ...
|
|
631
676
|
]
|
|
632
677
|
}
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
#### Strapi GraphQL API properties support:
|
|
681
|
+
|
|
682
|
+
- [filtering](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/graphql-api.html#filters)
|
|
683
|
+
- [sorting](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/graphql-api.html#sorting)
|
|
684
|
+
- [pagination](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/graphql-api.html#pagination)
|
|
685
|
+
|
|
686
|
+
### Get Comments (by Author)
|
|
687
|
+
|
|
688
|
+
_REST API equivalent: [Public REST API -> Get Comments (by Author)](#get-comments-by-author)_
|
|
689
|
+
|
|
690
|
+
**Example request**
|
|
691
|
+
|
|
692
|
+
```graphql
|
|
693
|
+
query {
|
|
694
|
+
findAllPerAuthor(authorId: 1, authorType: STRAPI) { // authorType might be one of [GENERIC, STRAPI]
|
|
695
|
+
data {
|
|
696
|
+
id
|
|
697
|
+
content
|
|
698
|
+
blocked
|
|
699
|
+
threadOf {
|
|
700
|
+
id
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
633
704
|
}
|
|
705
|
+
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
**Example response**
|
|
709
|
+
|
|
710
|
+
```json
|
|
711
|
+
{
|
|
712
|
+
"data": {
|
|
713
|
+
"findAllPerAuthor": {
|
|
714
|
+
"data": [
|
|
715
|
+
{
|
|
716
|
+
"id": 4,
|
|
717
|
+
"content": "Hackaton test comment",
|
|
718
|
+
"blocked": false,
|
|
719
|
+
"threadOf": {
|
|
720
|
+
"id": 1
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
// ...
|
|
724
|
+
]
|
|
725
|
+
}
|
|
726
|
+
}
|
|
634
727
|
```
|
|
635
728
|
|
|
636
729
|
#### Strapi GraphQL API properties support:
|
package/admin/src/index.js
CHANGED
|
@@ -83,7 +83,7 @@ exports.default = {
|
|
|
83
83
|
});
|
|
84
84
|
(0, custom_fields_1.registerCustomFields)(app);
|
|
85
85
|
},
|
|
86
|
-
registerTrads({ locales }) {
|
|
86
|
+
registerTrads({ locales = [] }) {
|
|
87
87
|
return locales.map((locale) => {
|
|
88
88
|
return {
|
|
89
89
|
data: (0, helper_plugin_1.prefixPluginTranslations)((0, lodash_1.get)(translations_1.default, locale), pluginId_1.pluginId, {}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strapi-plugin-comments",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.11",
|
|
4
4
|
"description": "Strapi - Comments plugin",
|
|
5
5
|
"strapi": {
|
|
6
6
|
"name": "comments",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"url": "https://github.com/VirtusLab-Open-Source/strapi-plugin-comments"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@strapi/plugin-graphql": "^4.
|
|
18
|
-
"@strapi/utils": "^4.
|
|
17
|
+
"@strapi/plugin-graphql": "^4.10.7",
|
|
18
|
+
"@strapi/utils": "^4.10.7",
|
|
19
19
|
"@types/axios": "^0.14.0",
|
|
20
20
|
"@types/react-intl": "^3.0.0",
|
|
21
21
|
"@types/react-query": "^1.2.9",
|
|
@@ -7,6 +7,7 @@ const functions_1 = require("./../utils/functions");
|
|
|
7
7
|
const functions_2 = require("./utils/functions");
|
|
8
8
|
const parsers_1 = require("./utils/parsers");
|
|
9
9
|
const error_1 = __importDefault(require("../utils/error"));
|
|
10
|
+
const constants_1 = require("../utils/constants");
|
|
10
11
|
const controllers = {
|
|
11
12
|
getService(name = "client") {
|
|
12
13
|
return (0, functions_1.getPluginService)(name);
|
|
@@ -49,6 +50,23 @@ const controllers = {
|
|
|
49
50
|
throw (0, functions_2.throwError)(ctx, e);
|
|
50
51
|
}
|
|
51
52
|
},
|
|
53
|
+
async findAllPerAuthor(ctx) {
|
|
54
|
+
const { params = {}, query, sort, pagination } = ctx;
|
|
55
|
+
const { id, type } = (0, functions_2.parseParams)(params);
|
|
56
|
+
const { sort: querySort, pagination: queryPagination, fields, ...filterQuery } = query || {};
|
|
57
|
+
try {
|
|
58
|
+
(0, functions_1.assertParamsPresent)(params, ["id"]);
|
|
59
|
+
return this.getService("common").findAllPerAuthor((0, parsers_1.flatInput)({
|
|
60
|
+
query: filterQuery,
|
|
61
|
+
sort: sort || querySort,
|
|
62
|
+
pagination: pagination || queryPagination,
|
|
63
|
+
fields,
|
|
64
|
+
}), id, ![constants_1.AUTHOR_TYPE.GENERIC.toLowerCase(), constants_1.AUTHOR_TYPE.GENERIC].includes(type));
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
throw (0, functions_2.throwError)(ctx, e);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
52
70
|
async post(ctx) {
|
|
53
71
|
const { request, params, state = {} } = ctx;
|
|
54
72
|
const { relation } = (0, functions_2.parseParams)(params);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Id, StrapiGraphQLContext, ToBeFixed } from "../../../types";
|
|
2
|
+
type ResponseFindAllPerAuthorResolverProps = {
|
|
3
|
+
authorId: Id;
|
|
4
|
+
authorType: 'STRAPI' | 'GENERIC' | undefined;
|
|
5
|
+
filters: ToBeFixed;
|
|
6
|
+
sort: ToBeFixed;
|
|
7
|
+
pagination: ToBeFixed;
|
|
8
|
+
};
|
|
9
|
+
declare const _default: ({ strapi, nexus }: StrapiGraphQLContext) => {
|
|
10
|
+
type: string;
|
|
11
|
+
args: {
|
|
12
|
+
authorId: any;
|
|
13
|
+
authorType: any;
|
|
14
|
+
filters: any;
|
|
15
|
+
pagination: any;
|
|
16
|
+
sort: any;
|
|
17
|
+
};
|
|
18
|
+
resolve(obj: Object, args: ResponseFindAllPerAuthorResolverProps): Promise<import("strapi-typed").StrapiPaginatedResponse<import("../../../types").Comment<import("../../../types").CommentAuthor>>>;
|
|
19
|
+
};
|
|
20
|
+
export = _default;
|
|
21
|
+
//# sourceMappingURL=findAllPerAuthor.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const comment_1 = __importDefault(require("../../../content-types/comment"));
|
|
7
|
+
const parsers_1 = require("../../controllers/utils/parsers");
|
|
8
|
+
const functions_1 = require("../../utils/functions");
|
|
9
|
+
const constants_1 = require("../../utils/constants");
|
|
10
|
+
module.exports = ({ strapi, nexus }) => {
|
|
11
|
+
const { nonNull, intArg, arg } = nexus;
|
|
12
|
+
const { service: getService } = strapi.plugin("graphql");
|
|
13
|
+
const { args } = getService("internals");
|
|
14
|
+
const { naming: { getFiltersInputTypeName }, } = getService("utils");
|
|
15
|
+
return {
|
|
16
|
+
type: "ResponseFindAllPerAuthor",
|
|
17
|
+
args: {
|
|
18
|
+
authorId: nonNull(intArg()),
|
|
19
|
+
authorType: arg({ type: 'AuthorType' }),
|
|
20
|
+
filters: getFiltersInputTypeName(comment_1.default),
|
|
21
|
+
pagination: args.PaginationArg,
|
|
22
|
+
sort: args.SortArg,
|
|
23
|
+
},
|
|
24
|
+
async resolve(obj, args) {
|
|
25
|
+
const { authorId, authorType, filters, sort, pagination } = args;
|
|
26
|
+
const isStrapiUser = authorType !== constants_1.AUTHOR_TYPE.GENERIC;
|
|
27
|
+
return await (0, functions_1.getPluginService)("common").findAllPerAuthor((0, parsers_1.flatInput)({
|
|
28
|
+
query: (0, functions_1.getPluginService)("gql").graphQLFiltersToStrapiQuery(filters, comment_1.default),
|
|
29
|
+
sort,
|
|
30
|
+
pagination: pagination
|
|
31
|
+
? {
|
|
32
|
+
...pagination,
|
|
33
|
+
withCount: !(0, lodash_1.isEmpty)(pagination),
|
|
34
|
+
}
|
|
35
|
+
: undefined,
|
|
36
|
+
}), authorId, isStrapiUser);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=findAllPerAuthor.js.map
|
|
@@ -4,10 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
const findAllFlat_1 = __importDefault(require("./findAllFlat"));
|
|
6
6
|
const findAllInHierarchy_1 = __importDefault(require("./findAllInHierarchy"));
|
|
7
|
+
const findAllPerAuthor_1 = __importDefault(require("./findAllPerAuthor"));
|
|
7
8
|
module.exports = (context) => {
|
|
8
9
|
const queries = {
|
|
9
10
|
findAllFlat: findAllFlat_1.default,
|
|
10
11
|
findAllInHierarchy: findAllInHierarchy_1.default,
|
|
12
|
+
findAllPerAuthor: findAllPerAuthor_1.default,
|
|
11
13
|
};
|
|
12
14
|
return context.nexus.extendType({
|
|
13
15
|
type: "Query",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const constants_1 = require("../../utils/constants");
|
|
3
|
+
module.exports = ({ nexus }) => nexus.enumType({
|
|
4
|
+
name: 'AuthorType',
|
|
5
|
+
description: "User type which was the author of comment - Strapi built-in or generic",
|
|
6
|
+
members: Object.values(constants_1.AUTHOR_TYPE),
|
|
7
|
+
});
|
|
8
|
+
//# sourceMappingURL=comment-author-type.js.map
|
|
@@ -6,6 +6,7 @@ const id_1 = __importDefault(require("./id"));
|
|
|
6
6
|
const comment_1 = __importDefault(require("./comment"));
|
|
7
7
|
const comment_nested_1 = __importDefault(require("./comment-nested"));
|
|
8
8
|
const comment_author_1 = __importDefault(require("./comment-author"));
|
|
9
|
+
const comment_author_type_1 = __importDefault(require("./comment-author-type"));
|
|
9
10
|
const create_comment_1 = __importDefault(require("./create-comment"));
|
|
10
11
|
const create_comment_author_1 = __importDefault(require("./create-comment-author"));
|
|
11
12
|
const update_comment_1 = __importDefault(require("./update-comment"));
|
|
@@ -17,11 +18,13 @@ const create_report_1 = __importDefault(require("./create-report"));
|
|
|
17
18
|
const response_pagination_1 = __importDefault(require("./response-pagination"));
|
|
18
19
|
const response_meta_1 = __importDefault(require("./response-meta"));
|
|
19
20
|
const response_find_all_1 = __importDefault(require("./response-find-all"));
|
|
21
|
+
const response_find_all_per_author_1 = __importDefault(require("./response-find-all-per-author"));
|
|
20
22
|
const typesFactories = [
|
|
21
23
|
id_1.default,
|
|
22
24
|
comment_1.default,
|
|
23
25
|
comment_nested_1.default,
|
|
24
26
|
comment_author_1.default,
|
|
27
|
+
comment_author_type_1.default,
|
|
25
28
|
create_comment_1.default,
|
|
26
29
|
create_comment_author_1.default,
|
|
27
30
|
update_comment_1.default,
|
|
@@ -33,6 +36,7 @@ const typesFactories = [
|
|
|
33
36
|
response_pagination_1.default,
|
|
34
37
|
response_meta_1.default,
|
|
35
38
|
response_find_all_1.default,
|
|
39
|
+
response_find_all_per_author_1.default,
|
|
36
40
|
];
|
|
37
41
|
module.exports = (context) => typesFactories.map((factory) => factory(context));
|
|
38
42
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = ({ nexus }) => nexus.objectType({
|
|
3
|
+
name: "ResponseFindAllPerAuthor",
|
|
4
|
+
definition(t) {
|
|
5
|
+
t.list.field("data", { type: "CommentSingle" });
|
|
6
|
+
t.field("meta", { type: "ResponseMeta" });
|
|
7
|
+
},
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=response-find-all-per-author.js.map
|
package/server/routes/client.js
CHANGED
|
@@ -85,6 +85,34 @@ const routes = [
|
|
|
85
85
|
},
|
|
86
86
|
},
|
|
87
87
|
},
|
|
88
|
+
{
|
|
89
|
+
method: "GET",
|
|
90
|
+
path: "/author/:id",
|
|
91
|
+
handler: "client.findAllPerAuthor",
|
|
92
|
+
config: {
|
|
93
|
+
policies: [],
|
|
94
|
+
description: "Find all comments created by Strapi user",
|
|
95
|
+
tag: {
|
|
96
|
+
plugin: "comments",
|
|
97
|
+
name: "Comments",
|
|
98
|
+
actionType: "find",
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
method: "GET",
|
|
104
|
+
path: "/author/:id/:type",
|
|
105
|
+
handler: "client.findAllPerAuthor",
|
|
106
|
+
config: {
|
|
107
|
+
policies: [],
|
|
108
|
+
description: "Find all comments created by specified type of user",
|
|
109
|
+
tag: {
|
|
110
|
+
plugin: "comments",
|
|
111
|
+
name: "Comments",
|
|
112
|
+
actionType: "find",
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
88
116
|
];
|
|
89
117
|
exports.default = routes;
|
|
90
118
|
//# sourceMappingURL=client.js.map
|
|
@@ -7,6 +7,7 @@ const lodash_1 = require("lodash");
|
|
|
7
7
|
const constants_1 = require("../utils/constants");
|
|
8
8
|
const error_1 = __importDefault(require("./../utils/error"));
|
|
9
9
|
const functions_1 = require("./utils/functions");
|
|
10
|
+
const parsers_1 = require("./utils/parsers");
|
|
10
11
|
const PAGE_SIZE = 10;
|
|
11
12
|
module.exports = ({ strapi }) => ({
|
|
12
13
|
async getConfig(prop, defaultValue, useLocal = false) {
|
|
@@ -41,54 +42,9 @@ module.exports = ({ strapi }) => ({
|
|
|
41
42
|
const doNotPopulateAuthor = isAdmin
|
|
42
43
|
? []
|
|
43
44
|
: await this.getConfig(constants_1.CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
...queryExtension,
|
|
48
|
-
orderBy: ((0, lodash_1.isString)(sort) ? [sort] : sort)
|
|
49
|
-
.map((_) => (constants_1.REGEX.sorting.test(_) ? _ : `${_}:asc`))
|
|
50
|
-
.reduce((prev, curr) => {
|
|
51
|
-
const [type = "asc", ...parts] = curr.split(":").reverse();
|
|
52
|
-
return { ...(0, lodash_1.set)(prev, parts.reverse().join("."), type) };
|
|
53
|
-
}, {}),
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
if (!(0, lodash_1.isNil)(fields)) {
|
|
57
|
-
queryExtension = {
|
|
58
|
-
...queryExtension,
|
|
59
|
-
select: (0, lodash_1.isArray)(fields) ? (0, lodash_1.uniq)([...fields, ...defaultSelect]) : fields,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
let meta = {};
|
|
63
|
-
if (pagination && (0, lodash_1.isObject)(pagination)) {
|
|
64
|
-
const parsedpagination = Object.keys(pagination).reduce((prev, curr) => ({
|
|
65
|
-
...prev,
|
|
66
|
-
[curr]: (0, lodash_1.parseInt)((0, lodash_1.get)(pagination, curr)),
|
|
67
|
-
}), {});
|
|
68
|
-
const { page = 1, pageSize = PAGE_SIZE, start = 0, limit = PAGE_SIZE, } = parsedpagination;
|
|
69
|
-
const paginationByPage = !(0, lodash_1.isNil)(parsedpagination?.page) || !(0, lodash_1.isNil)(parsedpagination?.pageSize);
|
|
70
|
-
queryExtension = {
|
|
71
|
-
...queryExtension,
|
|
72
|
-
offset: paginationByPage ? (page - 1) * pageSize : start,
|
|
73
|
-
limit: paginationByPage ? pageSize : limit,
|
|
74
|
-
};
|
|
75
|
-
const metapagination = paginationByPage
|
|
76
|
-
? {
|
|
77
|
-
pagination: {
|
|
78
|
-
page,
|
|
79
|
-
pageSize,
|
|
80
|
-
},
|
|
81
|
-
}
|
|
82
|
-
: {
|
|
83
|
-
pagination: {
|
|
84
|
-
start,
|
|
85
|
-
limit,
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
meta = {
|
|
89
|
-
...metapagination,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
45
|
+
const sortQuery = (0, parsers_1.parseSortQuery)(sort);
|
|
46
|
+
const fieldsQuery = (0, parsers_1.parseFieldsQuery)(fields, sortQuery, defaultSelect);
|
|
47
|
+
let [meta, queryExtension = {}] = (0, parsers_1.parsePaginationsQuery)(pagination, fieldsQuery, { PAGE_SIZE });
|
|
92
48
|
const entries = await strapi.db
|
|
93
49
|
.query((0, functions_1.getModelUid)("comment"))
|
|
94
50
|
.findMany({
|
|
@@ -191,6 +147,32 @@ module.exports = ({ strapi }) => ({
|
|
|
191
147
|
const doNotPopulateAuthor = await this.getConfig(constants_1.CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
|
|
192
148
|
return (0, functions_1.filterOurResolvedReports)(this.sanitizeCommentEntity(entity, doNotPopulateAuthor));
|
|
193
149
|
},
|
|
150
|
+
async findAllPerAuthor({ query = {}, populate = {}, pagination, sort, fields, isAdmin = false, }, authorId, isStrapiAuthor = false) {
|
|
151
|
+
if ((0, lodash_1.isNil)(authorId)) {
|
|
152
|
+
return {
|
|
153
|
+
data: [],
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const { related, ...restQuery } = query;
|
|
157
|
+
const authorQuery = isStrapiAuthor ? {
|
|
158
|
+
authorUser: {
|
|
159
|
+
id: authorId
|
|
160
|
+
},
|
|
161
|
+
} : {
|
|
162
|
+
authorId,
|
|
163
|
+
};
|
|
164
|
+
const response = await this.findAllFlat({
|
|
165
|
+
query: {
|
|
166
|
+
...restQuery,
|
|
167
|
+
...authorQuery,
|
|
168
|
+
},
|
|
169
|
+
pagination, populate, sort, fields, isAdmin
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
...response,
|
|
173
|
+
data: response.data.map(({ author, ...rest }) => rest),
|
|
174
|
+
};
|
|
175
|
+
},
|
|
194
176
|
async findRelatedEntitiesFor(entities = []) {
|
|
195
177
|
const data = entities.reduce((acc, curr) => {
|
|
196
178
|
const [relatedUid, relatedStringId] = (0, functions_1.getRelatedGroups)(curr.related);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { StrapiDBQueryArgs, StrapiPagination, StrapiResponseMeta, StringMap } from "strapi-typed";
|
|
2
|
+
import { CommentModelKeys, ToBeFixed } from "../../../types";
|
|
3
|
+
export declare const parseSortQuery: (sort: StringMap<unknown> | undefined, query?: StrapiDBQueryArgs<CommentModelKeys>) => StrapiDBQueryArgs<CommentModelKeys>;
|
|
4
|
+
export declare const parseFieldsQuery: (fields: ToBeFixed, query?: StrapiDBQueryArgs<CommentModelKeys>, defaultSelect?: Array<CommentModelKeys>) => StrapiDBQueryArgs<CommentModelKeys>;
|
|
5
|
+
export declare const parsePaginationsQuery: (pagination: StrapiPagination | undefined, query?: StrapiDBQueryArgs<CommentModelKeys>, defaults?: any) => [StrapiResponseMeta, StrapiDBQueryArgs<CommentModelKeys>];
|
|
6
|
+
//# sourceMappingURL=parsers.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePaginationsQuery = exports.parseFieldsQuery = exports.parseSortQuery = void 0;
|
|
4
|
+
const constants_1 = require("./../../utils/constants");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const parseSortQuery = (sort, query = {}) => {
|
|
7
|
+
if (sort && ((0, lodash_1.isString)(sort) || (0, lodash_1.isArray)(sort))) {
|
|
8
|
+
return {
|
|
9
|
+
...query,
|
|
10
|
+
orderBy: ((0, lodash_1.isString)(sort) ? [sort] : sort)
|
|
11
|
+
.map((_) => (constants_1.REGEX.sorting.test(_) ? _ : `${_}:asc`))
|
|
12
|
+
.reduce((prev, curr) => {
|
|
13
|
+
const [type = "asc", ...parts] = curr.split(":").reverse();
|
|
14
|
+
return { ...(0, lodash_1.set)(prev, parts.reverse().join("."), type) };
|
|
15
|
+
}, {}),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return query;
|
|
19
|
+
};
|
|
20
|
+
exports.parseSortQuery = parseSortQuery;
|
|
21
|
+
const parseFieldsQuery = (fields, query = {}, defaultSelect = []) => {
|
|
22
|
+
if (!(0, lodash_1.isNil)(fields)) {
|
|
23
|
+
return {
|
|
24
|
+
...query,
|
|
25
|
+
select: (0, lodash_1.isArray)(fields) ? (0, lodash_1.uniq)([...fields, ...defaultSelect]) : fields,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return query;
|
|
29
|
+
};
|
|
30
|
+
exports.parseFieldsQuery = parseFieldsQuery;
|
|
31
|
+
const parsePaginationsQuery = (pagination, query = {}, defaults = []) => {
|
|
32
|
+
if (pagination && (0, lodash_1.isObject)(pagination)) {
|
|
33
|
+
const parsedpagination = Object.keys(pagination).reduce((prev, curr) => ({
|
|
34
|
+
...prev,
|
|
35
|
+
[curr]: parseInt((0, lodash_1.get)(pagination, curr)),
|
|
36
|
+
}), {});
|
|
37
|
+
const { page = 1, pageSize = defaults.PAGE_SIZE, start = 0, limit = defaults.PAGE_SIZE, } = parsedpagination;
|
|
38
|
+
const paginationByPage = !(0, lodash_1.isNil)(parsedpagination?.page) || !(0, lodash_1.isNil)(parsedpagination?.pageSize);
|
|
39
|
+
const metapagination = paginationByPage
|
|
40
|
+
? {
|
|
41
|
+
pagination: {
|
|
42
|
+
page,
|
|
43
|
+
pageSize,
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
: {
|
|
47
|
+
pagination: {
|
|
48
|
+
start,
|
|
49
|
+
limit,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
return [{
|
|
53
|
+
...metapagination,
|
|
54
|
+
}, {
|
|
55
|
+
...query,
|
|
56
|
+
offset: paginationByPage ? (page - 1) * pageSize : start,
|
|
57
|
+
limit: paginationByPage ? pageSize : limit,
|
|
58
|
+
}];
|
|
59
|
+
}
|
|
60
|
+
return [{}, query];
|
|
61
|
+
};
|
|
62
|
+
exports.parsePaginationsQuery = parsePaginationsQuery;
|
|
63
|
+
//# sourceMappingURL=parsers.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REGEX = exports.APPROVAL_STATUS = exports.CONFIG_PARAMS = void 0;
|
|
3
|
+
exports.REGEX = exports.AUTHOR_TYPE = exports.APPROVAL_STATUS = exports.CONFIG_PARAMS = void 0;
|
|
4
4
|
exports.CONFIG_PARAMS = {
|
|
5
5
|
ENABLED_COLLECTIONS: "enabledCollections",
|
|
6
6
|
APPROVAL_FLOW: "approvalFlow",
|
|
@@ -14,6 +14,10 @@ exports.APPROVAL_STATUS = {
|
|
|
14
14
|
APPROVED: "APPROVED",
|
|
15
15
|
REJECTED: "REJECTED",
|
|
16
16
|
};
|
|
17
|
+
exports.AUTHOR_TYPE = {
|
|
18
|
+
GENERIC: 'GENERIC',
|
|
19
|
+
STRAPI: 'STRAPI',
|
|
20
|
+
};
|
|
17
21
|
exports.REGEX = {
|
|
18
22
|
uid: /^(?<type>[a-z0-9-]+)\:{2}(?<api>[a-z0-9-]+)\.{1}(?<contentType>[a-z0-9-]+)$/i,
|
|
19
23
|
relatedUid: /^(?<uid>[a-z0-9-]+\:{2}[a-z0-9-]+\.[a-z0-9-]+)\:{1}(?<id>[a-z0-9-]+)$/i,
|