strapi-plugin-comments 2.0.10 → 2.1.0-beta.1
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 +164 -120
- package/admin/src/components/ActionButton/styles.d.ts +2 -0
- package/admin/src/components/ActionButton/styles.js +13 -8
- package/admin/src/components/ConfirmationDialog/index.d.ts +26 -0
- package/admin/src/components/ConfirmationDialog/index.js +36 -55
- package/admin/src/components/DiscussionStatus/index.d.ts +9 -0
- package/admin/src/components/DiscussionStatus/index.js +22 -31
- package/admin/src/components/DiscussionThread/index.d.ts +16 -0
- package/admin/src/components/DiscussionThread/index.js +39 -56
- package/admin/src/components/DiscussionThreadItem/index.d.ts +9 -0
- package/admin/src/components/DiscussionThreadItem/index.js +28 -52
- package/admin/src/components/DiscussionThreadItem/styles.d.ts +4 -0
- package/admin/src/components/DiscussionThreadItem/styles.js +16 -11
- package/admin/src/components/DiscussionThreadItemActions/index.d.ts +19 -0
- package/admin/src/components/DiscussionThreadItemActions/index.js +121 -158
- package/admin/src/components/DiscussionThreadItemActions/styles.d.ts +2 -0
- package/admin/src/components/DiscussionThreadItemActions/styles.js +13 -7
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.d.ts +17 -0
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +38 -48
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.d.ts +2 -0
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +12 -6
- package/admin/src/components/DiscussionThreadItemFooter/index.d.ts +16 -0
- package/admin/src/components/DiscussionThreadItemFooter/index.js +35 -42
- package/admin/src/components/DiscussionThreadItemFooter/styles.d.ts +3 -0
- package/admin/src/components/DiscussionThreadItemFooter/styles.js +17 -12
- package/admin/src/components/DiscussionThreadItemReviewAction/index.d.ts +30 -0
- package/admin/src/components/DiscussionThreadItemReviewAction/index.js +77 -91
- package/admin/src/components/FormSwitch/index.d.ts +7 -0
- package/admin/src/components/FormSwitch/index.js +15 -18
- package/admin/src/components/FormSwitch/styles.d.ts +2 -0
- package/admin/src/components/FormSwitch/styles.js +14 -8
- package/admin/src/components/IconButton/styles.d.ts +2 -0
- package/admin/src/components/IconButton/styles.js +16 -9
- package/admin/src/components/Initializer/index.d.ts +5 -0
- package/admin/src/components/Initializer/index.js +12 -24
- package/admin/src/components/LoadingIndicatorOverlay/index.d.ts +3 -0
- package/admin/src/components/LoadingIndicatorOverlay/index.js +12 -15
- package/admin/src/components/LoadingIndicatorOverlay/styles.d.ts +3 -0
- package/admin/src/components/LoadingIndicatorOverlay/styles.js +22 -17
- package/admin/src/components/Nav/index.d.ts +7 -0
- package/admin/src/components/Nav/index.js +25 -48
- package/admin/src/components/PluginIcon/index.d.ts +3 -0
- package/admin/src/components/PluginIcon/index.js +10 -12
- package/admin/src/components/ReportsReviewModal/index.d.ts +21 -0
- package/admin/src/components/ReportsReviewModal/index.js +31 -46
- package/admin/src/components/ReportsReviewTable/index.d.ts +21 -0
- package/admin/src/components/ReportsReviewTable/index.js +120 -140
- package/admin/src/components/StatusBadge/index.d.ts +7 -0
- package/admin/src/components/StatusBadge/index.js +12 -17
- package/admin/src/components/StatusBadge/styles.d.ts +2 -0
- package/admin/src/components/StatusBadge/styles.js +19 -13
- package/admin/src/components/TableFilters/index.d.ts +10 -0
- package/admin/src/components/TableFilters/index.js +52 -49
- package/admin/src/components/TablePagination/index.d.ts +17 -0
- package/admin/src/components/TablePagination/index.js +27 -29
- package/admin/src/components/icons/comments.d.ts +6 -0
- package/admin/src/components/icons/comments.js +11 -8
- package/admin/src/components/icons/index.d.ts +6 -0
- package/admin/src/components/icons/index.js +15 -6
- package/admin/src/components/icons/lock.d.ts +7 -0
- package/admin/src/components/icons/lock.js +11 -21
- package/admin/src/components/icons/review.d.ts +7 -0
- package/admin/src/components/icons/review.js +11 -17
- package/admin/src/components/icons/unlock.d.ts +7 -0
- package/admin/src/components/icons/unlock.js +11 -19
- package/admin/src/hooks/useConfig.d.ts +8 -0
- package/admin/src/hooks/useConfig.js +40 -45
- package/admin/src/index.d.ts +7 -0
- package/admin/src/index.js +98 -92
- package/admin/src/pages/App/index.d.ts +4 -0
- package/admin/src/pages/App/index.js +43 -67
- package/admin/src/pages/App/reducer/actions.d.ts +8 -0
- package/admin/src/pages/App/reducer/actions.js +11 -7
- package/admin/src/pages/App/reducer/constants.d.ts +4 -0
- package/admin/src/pages/App/reducer/constants.js +7 -4
- package/admin/src/pages/App/reducer/index.d.ts +9 -0
- package/admin/src/pages/App/reducer/index.js +24 -22
- package/admin/src/pages/App/reducer/init.d.ts +3 -0
- package/admin/src/pages/App/reducer/init.js +6 -4
- package/admin/src/pages/App/reducer/selectors.d.ts +6 -0
- package/admin/src/pages/App/reducer/selectors.js +17 -34
- package/admin/src/pages/App/utils/api.d.ts +2 -0
- package/admin/src/pages/App/utils/api.js +14 -11
- package/admin/src/pages/ComingSoonPage/index.d.ts +3 -0
- package/admin/src/pages/ComingSoonPage/index.js +42 -24
- package/admin/src/pages/Details/components/DetailsEntity/index.d.ts +18 -0
- package/admin/src/pages/Details/components/DetailsEntity/index.js +49 -77
- package/admin/src/pages/Details/components/DetailsFilters/index.d.ts +12 -0
- package/admin/src/pages/Details/components/DetailsFilters/index.js +19 -26
- package/admin/src/pages/Details/components/DetailsFilters/styles.d.ts +2 -0
- package/admin/src/pages/Details/components/DetailsFilters/styles.js +14 -8
- package/admin/src/pages/Details/index.d.ts +4 -0
- package/admin/src/pages/Details/index.js +94 -133
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.d.ts +20 -0
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +128 -139
- package/admin/src/pages/Discover/components/DiscoverTableRow/styles.d.ts +2 -0
- package/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +14 -8
- package/admin/src/pages/Discover/index.d.ts +4 -0
- package/admin/src/pages/Discover/index.js +129 -170
- package/admin/src/pages/Discover/utils/api.d.ts +2 -0
- package/admin/src/pages/Discover/utils/api.js +15 -13
- package/admin/src/pages/Discover/utils/filtersSchema.d.ts +11 -0
- package/admin/src/pages/Discover/utils/filtersSchema.js +8 -6
- package/admin/src/pages/Settings/components/RestartAlert/styles.d.ts +2 -0
- package/admin/src/pages/Settings/components/RestartAlert/styles.js +14 -8
- package/admin/src/pages/Settings/index.d.ts +3 -0
- package/admin/src/pages/Settings/index.js +225 -391
- package/admin/src/pages/Settings/utils/api.d.ts +7 -0
- package/admin/src/pages/Settings/utils/api.js +60 -55
- package/admin/src/pages/utils/api.d.ts +12 -0
- package/admin/src/pages/utils/api.js +58 -53
- package/admin/src/permissions.d.ts +28 -0
- package/admin/src/permissions.js +31 -17
- package/admin/src/pluginId.d.ts +2 -0
- package/admin/src/pluginId.js +29 -5
- package/admin/src/reducers.d.ts +7 -0
- package/admin/src/reducers.js +10 -6
- package/admin/src/translations/en.json +131 -131
- package/admin/src/translations/fr.json +1 -1
- package/admin/src/utils/axiosInstance.d.ts +3 -0
- package/admin/src/utils/axiosInstance.js +21 -27
- package/admin/src/utils/constants.d.ts +25 -0
- package/admin/src/utils/constants.js +23 -22
- package/admin/src/utils/getApiUrl.d.ts +3 -0
- package/admin/src/utils/getApiUrl.js +6 -5
- package/admin/src/utils/getMessage.d.ts +4 -0
- package/admin/src/utils/getMessage.js +15 -15
- package/admin/src/utils/getRelatedGroups.d.ts +4 -0
- package/admin/src/utils/getRelatedGroups.js +5 -3
- package/admin/src/utils/getUrl.d.ts +3 -0
- package/admin/src/utils/getUrl.js +6 -5
- package/admin/src/utils/handleAPIError.d.ts +4 -0
- package/admin/src/utils/handleAPIError.js +12 -11
- package/admin/src/utils/index.d.ts +12 -0
- package/admin/src/utils/index.js +29 -11
- package/admin/src/utils/parseRegExp.d.ts +6 -0
- package/admin/src/utils/parseRegExp.js +6 -5
- package/admin/src/utils/renderEntryTitle.d.ts +4 -0
- package/admin/src/utils/renderEntryTitle.js +11 -12
- package/admin/src/utils/renderInitials.d.ts +3 -0
- package/admin/src/utils/renderInitials.js +10 -5
- package/admin/src/utils/resolveCommentStatus.d.ts +4 -0
- package/admin/src/utils/resolveCommentStatus.js +17 -21
- package/admin/src/utils/resolveCommentStatusColor.d.ts +4 -0
- package/admin/src/utils/resolveCommentStatusColor.js +19 -19
- package/content-types/comment.d.ts +91 -0
- package/content-types/comment.js +87 -88
- package/content-types/index.d.ts +143 -0
- package/content-types/index.js +15 -10
- package/content-types/report.d.ts +48 -0
- package/content-types/report.js +44 -49
- package/package.json +24 -19
- package/permissions.d.ts +18 -0
- package/permissions.js +12 -13
- package/server/bootstrap.d.ts +4 -0
- package/server/bootstrap.js +56 -62
- package/server/config/index.d.ts +4 -0
- package/server/config/index.js +17 -15
- package/server/controllers/admin.d.ts +4 -0
- package/server/controllers/admin.js +134 -167
- package/server/controllers/client.d.ts +4 -0
- package/server/controllers/client.js +104 -112
- package/server/controllers/index.d.ts +6 -0
- package/server/controllers/index.js +12 -8
- package/server/controllers/utils/functions.d.ts +7 -0
- package/server/controllers/utils/functions.js +22 -17
- package/server/controllers/utils/parsers.d.ts +15 -0
- package/server/controllers/utils/parsers.js +17 -17
- package/server/destroy.d.ts +3 -0
- package/server/destroy.js +3 -4
- package/server/graphql/index.d.ts +4 -0
- package/server/graphql/index.js +27 -25
- package/server/graphql/mutations/createAbuseReport.d.ts +11 -0
- package/server/graphql/mutations/createAbuseReport.js +22 -24
- package/server/graphql/mutations/createComment.d.ts +14 -0
- package/server/graphql/mutations/createComment.js +22 -24
- package/server/graphql/mutations/index.d.ts +4 -0
- package/server/graphql/mutations/index.js +24 -19
- package/server/graphql/mutations/removeComment.d.ts +11 -0
- package/server/graphql/mutations/removeComment.js +22 -24
- package/server/graphql/mutations/updateComment.d.ts +11 -0
- package/server/graphql/mutations/updateComment.js +22 -24
- package/server/graphql/queries/findAllFlat.d.ts +19 -0
- package/server/graphql/queries/findAllFlat.js +31 -34
- package/server/graphql/queries/findAllInHierarchy.d.ts +18 -0
- package/server/graphql/queries/findAllInHierarchy.js +26 -30
- package/server/graphql/queries/index.d.ts +4 -0
- package/server/graphql/queries/index.js +20 -17
- package/server/graphql/resolvers-config.d.ts +23 -0
- package/server/graphql/resolvers-config.js +11 -11
- package/server/graphql/types/comment-author.d.ts +4 -0
- package/server/graphql/types/comment-author.js +10 -8
- package/server/graphql/types/comment-nested.d.ts +4 -0
- package/server/graphql/types/comment-nested.js +17 -15
- package/server/graphql/types/comment.d.ts +4 -0
- package/server/graphql/types/comment.js +16 -14
- package/server/graphql/types/create-comment-author.d.ts +4 -0
- package/server/graphql/types/create-comment-author.js +10 -8
- package/server/graphql/types/create-comment.d.ts +4 -0
- package/server/graphql/types/create-comment.js +10 -8
- package/server/graphql/types/create-report.d.ts +4 -0
- package/server/graphql/types/create-report.js +10 -8
- package/server/graphql/types/id.d.ts +4 -0
- package/server/graphql/types/id.js +24 -23
- package/server/graphql/types/identify-comment-author.d.ts +4 -0
- package/server/graphql/types/identify-comment-author.js +7 -5
- package/server/graphql/types/index.d.ts +4 -0
- package/server/graphql/types/index.js +36 -17
- package/server/graphql/types/remove-comment.d.ts +4 -0
- package/server/graphql/types/remove-comment.js +9 -7
- package/server/graphql/types/report-reason.d.ts +4 -0
- package/server/graphql/types/report-reason.js +10 -8
- package/server/graphql/types/report.d.ts +4 -0
- package/server/graphql/types/report.js +12 -10
- package/server/graphql/types/response-find-all.d.ts +4 -0
- package/server/graphql/types/response-find-all.js +8 -6
- package/server/graphql/types/response-meta.d.ts +4 -0
- package/server/graphql/types/response-meta.js +7 -5
- package/server/graphql/types/response-pagination.d.ts +4 -0
- package/server/graphql/types/response-pagination.js +12 -10
- package/server/graphql/types/update-comment.d.ts +4 -0
- package/server/graphql/types/update-comment.js +10 -8
- package/server/index.d.ts +26 -0
- package/server/index.js +24 -21
- package/server/register.d.ts +3 -0
- package/server/register.js +3 -4
- package/server/routes/admin.d.ts +4 -0
- package/server/routes/admin.js +103 -109
- package/server/routes/client.d.ts +4 -0
- package/server/routes/client.js +48 -46
- package/server/routes/index.d.ts +11 -0
- package/server/routes/index.js +18 -14
- package/server/services/admin.d.ts +5 -0
- package/server/services/admin.js +126 -158
- package/server/services/client.d.ts +5 -0
- package/server/services/client.js +135 -151
- package/server/services/common.d.ts +5 -0
- package/server/services/common.js +165 -194
- package/server/services/graphql.d.ts +5 -0
- package/server/services/graphql.js +117 -182
- package/server/services/index.d.ts +8 -0
- package/server/services/index.js +15 -12
- package/server/services/utils/functions.d.ts +13 -0
- package/server/services/utils/functions.js +100 -109
- package/server/utils/constants.d.ts +9 -0
- package/server/utils/constants.js +19 -23
- package/server/utils/error.d.ts +19 -0
- package/server/utils/error.js +23 -18
- package/server/utils/functions.d.ts +6 -0
- package/server/utils/functions.js +35 -18
- package/strapi-admin.d.ts +3 -0
- package/strapi-admin.js +8 -3
- package/strapi-server.d.ts +177 -0
- package/strapi-server.js +43 -46
- package/tsconfig.tsbuildinfo +1 -0
- package/types/contentTypes.d.ts +44 -0
- package/types/contentTypes.js +3 -0
- package/.husky/pre-commit +0 -4
- package/LICENSE.md +0 -7
- package/__mocks__/initSetup.js +0 -108
- package/jest.config.js +0 -7
- package/server/controllers/utils/__tests__/functions.test.js +0 -43
- package/server/controllers/utils/__tests__/parsers.test.js +0 -94
- package/server/services/__tests__/common.test.js +0 -399
- package/server/services/utils/__tests__/functions.test.js +0 -53
- package/server/utils/__tests__/functions.test.js +0 -17
|
@@ -1,107 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
filterOurResolvedReports,
|
|
12
|
-
buildAuthorModel,
|
|
13
|
-
buildConfigQueryProp,
|
|
14
|
-
} = require('./utils/functions');
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Comments Plugin - common services
|
|
18
|
-
*/
|
|
19
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const bad_words_1 = __importDefault(require("bad-words"));
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const constants_1 = require("../utils/constants");
|
|
8
|
+
const error_1 = __importDefault(require("./../utils/error"));
|
|
9
|
+
const functions_1 = require("./utils/functions");
|
|
10
|
+
const PAGE_SIZE = 10;
|
|
20
11
|
module.exports = ({ strapi }) => ({
|
|
21
|
-
|
|
22
12
|
async getConfig(prop, defaultValue, useLocal = false) {
|
|
23
|
-
const queryProp = buildConfigQueryProp(prop);
|
|
13
|
+
const queryProp = (0, functions_1.buildConfigQueryProp)(prop);
|
|
24
14
|
const pluginStore = await this.getPluginStore();
|
|
25
|
-
const config = await pluginStore.get({
|
|
26
|
-
|
|
15
|
+
const config = await pluginStore.get({
|
|
16
|
+
key: "config",
|
|
17
|
+
});
|
|
27
18
|
let result;
|
|
28
19
|
if (config && !useLocal) {
|
|
29
|
-
result = queryProp ? get(config, queryProp, defaultValue) : config;
|
|
30
|
-
}
|
|
20
|
+
result = queryProp ? (0, lodash_1.get)(config, queryProp, defaultValue) : config;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
31
23
|
result = this.getLocalConfig(queryProp, defaultValue);
|
|
32
24
|
}
|
|
33
|
-
return isNil(result) ? defaultValue : result;
|
|
25
|
+
return (0, lodash_1.isNil)(result) ? defaultValue : result;
|
|
34
26
|
},
|
|
35
|
-
|
|
36
27
|
async getPluginStore() {
|
|
37
|
-
return strapi.store({ type:
|
|
28
|
+
return strapi.store({ type: "plugin", name: "comments" });
|
|
38
29
|
},
|
|
39
|
-
|
|
40
30
|
getLocalConfig(prop, defaultValue) {
|
|
41
|
-
const queryProp = buildConfigQueryProp(prop);
|
|
42
|
-
const result = strapi.config.get(`plugin.comments${
|
|
43
|
-
return isNil(result) ? defaultValue : result;
|
|
31
|
+
const queryProp = (0, functions_1.buildConfigQueryProp)(prop);
|
|
32
|
+
const result = strapi.config.get(`plugin.comments${queryProp ? "." + queryProp : ""}`);
|
|
33
|
+
return (0, lodash_1.isNil)(result) ? defaultValue : result;
|
|
44
34
|
},
|
|
45
|
-
|
|
46
|
-
// Find comments in the flat structure
|
|
47
|
-
async findAllFlat({
|
|
48
|
-
query = {},
|
|
49
|
-
populate = {},
|
|
50
|
-
sort,
|
|
51
|
-
pagination }, relatedEntity = null) {
|
|
52
|
-
|
|
35
|
+
async findAllFlat({ query = {}, populate = {}, sort, pagination }, relatedEntity = null) {
|
|
53
36
|
const defaultPopulate = {
|
|
54
37
|
authorUser: true,
|
|
55
38
|
};
|
|
56
|
-
|
|
57
39
|
let queryExtension = {};
|
|
58
|
-
|
|
59
|
-
if (sort && (isString(sort) || isArray(sort))) {
|
|
40
|
+
if (sort && ((0, lodash_1.isString)(sort) || (0, lodash_1.isArray)(sort))) {
|
|
60
41
|
queryExtension = {
|
|
61
42
|
...queryExtension,
|
|
62
|
-
orderBy: (isString(sort) ? [sort] : sort)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const [type =
|
|
66
|
-
return { ...set(prev, parts.reverse().join(
|
|
67
|
-
}, {})
|
|
43
|
+
orderBy: ((0, lodash_1.isString)(sort) ? [sort] : sort)
|
|
44
|
+
.map((_) => (constants_1.REGEX.sorting.test(_) ? _ : `${_}:asc`))
|
|
45
|
+
.reduce((prev, curr) => {
|
|
46
|
+
const [type = "asc", ...parts] = curr.split(":").reverse();
|
|
47
|
+
return { ...(0, lodash_1.set)(prev, parts.reverse().join("."), type) };
|
|
48
|
+
}, {}),
|
|
68
49
|
};
|
|
69
50
|
}
|
|
70
|
-
|
|
71
51
|
let meta = {};
|
|
72
|
-
if (pagination && isObject(pagination)) {
|
|
73
|
-
const
|
|
52
|
+
if (pagination && (0, lodash_1.isObject)(pagination)) {
|
|
53
|
+
const parsedpagination = Object.keys(pagination).reduce((prev, curr) => ({
|
|
74
54
|
...prev,
|
|
75
|
-
[curr]: parseInt(pagination
|
|
55
|
+
[curr]: (0, lodash_1.parseInt)((0, lodash_1.get)(pagination, curr)),
|
|
76
56
|
}), {});
|
|
77
|
-
const { page = 1, pageSize =
|
|
78
|
-
const paginationByPage = !isNil(
|
|
79
|
-
|
|
57
|
+
const { page = 1, pageSize = PAGE_SIZE, start = 0, limit = PAGE_SIZE, } = parsedpagination;
|
|
58
|
+
const paginationByPage = !(0, lodash_1.isNil)(parsedpagination?.page) || !(0, lodash_1.isNil)(parsedpagination?.pageSize);
|
|
80
59
|
queryExtension = {
|
|
81
60
|
...queryExtension,
|
|
82
61
|
offset: paginationByPage ? (page - 1) * pageSize : start,
|
|
83
62
|
limit: paginationByPage ? pageSize : limit,
|
|
84
63
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
64
|
+
const metapagination = paginationByPage
|
|
65
|
+
? {
|
|
66
|
+
pagination: {
|
|
67
|
+
page,
|
|
68
|
+
pageSize,
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
: {
|
|
72
|
+
pagination: {
|
|
73
|
+
start,
|
|
74
|
+
limit,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
98
77
|
meta = {
|
|
99
|
-
...
|
|
78
|
+
...metapagination,
|
|
100
79
|
};
|
|
101
80
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
81
|
+
const entries = await strapi.db
|
|
82
|
+
.query((0, functions_1.getModelUid)("comment"))
|
|
83
|
+
.findMany({
|
|
105
84
|
where: {
|
|
106
85
|
...query,
|
|
107
86
|
},
|
|
@@ -111,178 +90,169 @@ module.exports = ({ strapi }) => ({
|
|
|
111
90
|
},
|
|
112
91
|
...queryExtension,
|
|
113
92
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const total = await strapi.db
|
|
93
|
+
if (pagination?.withCount &&
|
|
94
|
+
(pagination.withCount === "true" || pagination.withCount === true)) {
|
|
95
|
+
const total = await strapi.db
|
|
96
|
+
.query((0, functions_1.getModelUid)("comment"))
|
|
117
97
|
.count({
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
98
|
+
where: {
|
|
99
|
+
...query,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
const pageSize = meta.pagination.pageSize || PAGE_SIZE;
|
|
103
|
+
const pageCount = Math.floor(total / pageSize);
|
|
123
104
|
meta = {
|
|
124
105
|
...meta,
|
|
125
106
|
pagination: {
|
|
126
107
|
...meta.pagination,
|
|
127
|
-
pageCount: !isNil(meta.pagination.page)
|
|
128
|
-
total %
|
|
129
|
-
|
|
108
|
+
pageCount: !(0, lodash_1.isNil)(meta.pagination.page)
|
|
109
|
+
? total % pageSize === 0
|
|
110
|
+
? pageCount
|
|
111
|
+
: pageCount + 1
|
|
112
|
+
: undefined,
|
|
130
113
|
total,
|
|
131
114
|
},
|
|
132
115
|
};
|
|
133
116
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
.findWithCount({
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return {
|
|
117
|
+
const entriesWithThreads = await Promise.all(entries.map(async (_) => {
|
|
118
|
+
const [nestedEntries, count] = await strapi.db
|
|
119
|
+
.query((0, functions_1.getModelUid)("comment"))
|
|
120
|
+
.findWithCount({
|
|
121
|
+
where: {
|
|
122
|
+
threadOf: _.id,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
id: _.id,
|
|
127
|
+
itemsInTread: count,
|
|
128
|
+
firstThreadItemId: (0, lodash_1.first)(nestedEntries)?.id,
|
|
129
|
+
};
|
|
143
130
|
}));
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const result = entries
|
|
149
|
-
.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
131
|
+
const relatedEntities = relatedEntity !== null
|
|
132
|
+
? [relatedEntity]
|
|
133
|
+
: await this.findRelatedEntitiesFor([...entries]);
|
|
134
|
+
const hasRelatedEntitiesToMap = relatedEntities.filter((_) => _).length > 0;
|
|
135
|
+
const result = entries.map((_) => {
|
|
136
|
+
const threadedItem = entriesWithThreads.find((item) => item.id === _.id);
|
|
137
|
+
const parsedThreadOf = (0, lodash_1.isString)(query.threadOf)
|
|
138
|
+
? (0, lodash_1.parseInt)(query.threadOf)
|
|
139
|
+
: query.threadOf;
|
|
140
|
+
return this.sanitizeCommentEntity({
|
|
141
|
+
..._,
|
|
142
|
+
threadOf: parsedThreadOf || _.threadOf || null,
|
|
143
|
+
gotThread: (threadedItem?.itemsInTread || 0) > 0,
|
|
144
|
+
threadFirstItemId: threadedItem?.firstThreadItemId,
|
|
157
145
|
});
|
|
158
|
-
|
|
146
|
+
});
|
|
159
147
|
return {
|
|
160
|
-
data: hasRelatedEntitiesToMap
|
|
161
|
-
result.map(_ => this.mergeRelatedEntityTo(_, relatedEntities))
|
|
162
|
-
result,
|
|
163
|
-
...(isEmpty(meta) ? {} : { meta }),
|
|
164
|
-
};
|
|
148
|
+
data: hasRelatedEntitiesToMap
|
|
149
|
+
? result.map((_) => this.mergeRelatedEntityTo(_, relatedEntities))
|
|
150
|
+
: result,
|
|
151
|
+
...((0, lodash_1.isEmpty)(meta) ? {} : { meta }),
|
|
152
|
+
};
|
|
165
153
|
},
|
|
166
|
-
|
|
167
|
-
// Find comments and create relations tree structure
|
|
168
|
-
async findAllInHierarchy ({
|
|
169
|
-
query,
|
|
170
|
-
populate = {},
|
|
171
|
-
sort,
|
|
172
|
-
startingFromId = null,
|
|
173
|
-
dropBlockedThreads = false,
|
|
174
|
-
}, relatedEntity) {
|
|
154
|
+
async findAllInHierarchy({ query, populate = {}, sort, startingFromId = null, dropBlockedThreads = false, }, relatedEntity) {
|
|
175
155
|
const entities = await this.findAllFlat({ query, populate, sort }, relatedEntity);
|
|
176
|
-
return buildNestedStructure(entities?.data, startingFromId,
|
|
156
|
+
return (0, functions_1.buildNestedStructure)(entities?.data, startingFromId, "threadOf", dropBlockedThreads, false);
|
|
177
157
|
},
|
|
178
|
-
|
|
179
|
-
// Find single comment
|
|
180
158
|
async findOne(criteria) {
|
|
181
|
-
const entity = await strapi.db
|
|
159
|
+
const entity = await strapi.db
|
|
160
|
+
.query((0, functions_1.getModelUid)("comment"))
|
|
182
161
|
.findOne({
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (!entity){
|
|
190
|
-
throw new
|
|
162
|
+
where: criteria,
|
|
163
|
+
populate: {
|
|
164
|
+
reports: true,
|
|
165
|
+
authorUser: true,
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
if (!entity) {
|
|
169
|
+
throw new error_1.default(404, "Comment does not exist. Check your payload please.");
|
|
191
170
|
}
|
|
192
|
-
return filterOurResolvedReports(this.sanitizeCommentEntity(entity));
|
|
171
|
+
return (0, functions_1.filterOurResolvedReports)(this.sanitizeCommentEntity(entity));
|
|
193
172
|
},
|
|
194
|
-
|
|
195
|
-
// Find all related entiries
|
|
196
173
|
async findRelatedEntitiesFor(entities = []) {
|
|
197
|
-
const data = entities.reduce((acc,
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
);
|
|
208
|
-
return Promise.all(
|
|
209
|
-
|
|
210
|
-
.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
})
|
|
218
|
-
))
|
|
219
|
-
)
|
|
220
|
-
)
|
|
221
|
-
.then(result => result.flat(2));
|
|
174
|
+
const data = entities.reduce((acc, curr) => {
|
|
175
|
+
const [relatedUid, relatedStringId] = (0, functions_1.getRelatedGroups)(curr.related);
|
|
176
|
+
const parsedRelatedId = (0, lodash_1.parseInt)(relatedStringId);
|
|
177
|
+
const relatedId = (0, lodash_1.isNumber)(parsedRelatedId)
|
|
178
|
+
? parsedRelatedId
|
|
179
|
+
: relatedStringId;
|
|
180
|
+
return {
|
|
181
|
+
...acc,
|
|
182
|
+
[relatedUid]: [...(acc[relatedUid] || []), relatedId],
|
|
183
|
+
};
|
|
184
|
+
}, {});
|
|
185
|
+
return Promise.all(Object.entries(data).map(async ([relatedUid, relatedStringIds]) => strapi.db
|
|
186
|
+
.query(relatedUid)
|
|
187
|
+
.findMany({
|
|
188
|
+
where: { id: Array.from(new Set(relatedStringIds)) },
|
|
189
|
+
})
|
|
190
|
+
.then((relatedEntities) => relatedEntities.map((_) => ({
|
|
191
|
+
..._,
|
|
192
|
+
uid: relatedUid,
|
|
193
|
+
}))))).then((result) => result.flat(2));
|
|
222
194
|
},
|
|
223
|
-
|
|
224
|
-
// Merge related entity with comment
|
|
225
195
|
mergeRelatedEntityTo(entity, relatedEntities = []) {
|
|
226
196
|
return {
|
|
227
197
|
...entity,
|
|
228
|
-
related: relatedEntities.find(relatedEntity => entity.related === `${relatedEntity.uid}:${relatedEntity.id}`)
|
|
198
|
+
related: relatedEntities.find((relatedEntity) => entity.related === `${relatedEntity.uid}:${relatedEntity.id}`),
|
|
229
199
|
};
|
|
230
200
|
},
|
|
231
|
-
|
|
232
201
|
async modifiedNestedNestedComments(id, fieldName, value) {
|
|
233
202
|
try {
|
|
234
|
-
const entitiesToChange = await strapi.
|
|
203
|
+
const entitiesToChange = await strapi.db
|
|
204
|
+
.query((0, functions_1.getModelUid)("comment"))
|
|
235
205
|
.findMany({
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const changedEntities = await strapi.
|
|
206
|
+
where: { threadOf: id },
|
|
207
|
+
});
|
|
208
|
+
const changedEntities = await strapi.db
|
|
209
|
+
.query((0, functions_1.getModelUid)("comment"))
|
|
239
210
|
.updateMany({
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
);
|
|
211
|
+
where: { id: entitiesToChange.map((_) => _.id) },
|
|
212
|
+
data: { [fieldName]: value },
|
|
213
|
+
});
|
|
214
|
+
if (entitiesToChange.length === changedEntities.length &&
|
|
215
|
+
changedEntities.length > 0) {
|
|
216
|
+
const nestedTransactions = await Promise.all(changedEntities.map((item) => this.modifiedNestedNestedComments(item.id, fieldName, value)));
|
|
247
217
|
return nestedTransactions.length === changedEntities.length;
|
|
248
218
|
}
|
|
249
219
|
return true;
|
|
250
|
-
}
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
251
222
|
return false;
|
|
252
223
|
}
|
|
253
224
|
},
|
|
254
|
-
|
|
255
225
|
sanitizeCommentEntity(entity) {
|
|
256
226
|
return {
|
|
257
|
-
...buildAuthorModel({
|
|
227
|
+
...(0, functions_1.buildAuthorModel)({
|
|
258
228
|
...entity,
|
|
259
|
-
threadOf:
|
|
229
|
+
threadOf: (0, lodash_1.isObject)(entity.threadOf)
|
|
230
|
+
? (0, functions_1.buildAuthorModel)(entity.threadOf)
|
|
231
|
+
: entity.threadOf,
|
|
260
232
|
}),
|
|
261
233
|
};
|
|
262
234
|
},
|
|
263
|
-
|
|
264
235
|
isValidUserContext(user) {
|
|
265
|
-
return user ? !isNil(user?.id) : true;
|
|
236
|
+
return user ? !(0, lodash_1.isNil)(user?.id) : true;
|
|
266
237
|
},
|
|
267
|
-
|
|
268
238
|
async parseRelationString(relation) {
|
|
269
|
-
const [
|
|
270
|
-
const parsedRelatedId = parseInt(relatedStringId);
|
|
271
|
-
const relatedId = isNumber(parsedRelatedId)
|
|
272
|
-
|
|
273
|
-
|
|
239
|
+
const [uid, relatedStringId] = (0, functions_1.getRelatedGroups)(relation);
|
|
240
|
+
const parsedRelatedId = (0, lodash_1.parseInt)(relatedStringId);
|
|
241
|
+
const relatedId = (0, lodash_1.isNumber)(parsedRelatedId)
|
|
242
|
+
? parsedRelatedId
|
|
243
|
+
: relatedStringId;
|
|
244
|
+
const enabledCollections = await this.getConfig(constants_1.CONFIG_PARAMS.ENABLED_COLLECTIONS, []);
|
|
274
245
|
if (!enabledCollections.includes(uid)) {
|
|
275
|
-
throw new
|
|
246
|
+
throw new error_1.default(403, `Action not allowed for collection '${uid}'. Use one of: ${enabledCollections.join(", ")}`);
|
|
276
247
|
}
|
|
277
|
-
return [
|
|
248
|
+
return [uid, relatedId];
|
|
278
249
|
},
|
|
279
|
-
|
|
280
250
|
async checkBadWords(content) {
|
|
281
|
-
const config = await this.getConfig(CONFIG_PARAMS.BAD_WORDS, true);
|
|
251
|
+
const config = await this.getConfig(constants_1.CONFIG_PARAMS.BAD_WORDS, true);
|
|
282
252
|
if (config) {
|
|
283
|
-
const filter = new
|
|
253
|
+
const filter = new bad_words_1.default((0, lodash_1.isObject)(config) ? config : undefined);
|
|
284
254
|
if (content && filter.isProfane(content)) {
|
|
285
|
-
throw new
|
|
255
|
+
throw new error_1.default(400, "Bad language used! Please polite your comment...", {
|
|
286
256
|
content: {
|
|
287
257
|
original: content,
|
|
288
258
|
filtered: content && filter.clean(content),
|
|
@@ -293,3 +263,4 @@ module.exports = ({ strapi }) => ({
|
|
|
293
263
|
return content;
|
|
294
264
|
},
|
|
295
265
|
});
|
|
266
|
+
//# sourceMappingURL=common.js.map
|