strapi-plugin-comments 2.0.8 → 2.0.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 +45 -11
- package/admin/src/translations/en.json +1 -0
- package/admin/src/translations/fr.json +132 -1
- package/admin/src/translations/pt-BR.json +132 -0
- package/build/README.md +818 -0
- package/build/admin/src/components/ActionButton/styles.d.ts +2 -0
- package/build/admin/src/components/ActionButton/styles.js +17 -0
- package/build/admin/src/components/ConfirmationDialog/index.d.ts +26 -0
- package/build/admin/src/components/ConfirmationDialog/index.js +104 -0
- package/build/admin/src/components/DiscussionStatus/index.d.ts +9 -0
- package/build/admin/src/components/DiscussionStatus/index.js +38 -0
- package/build/admin/src/components/DiscussionThread/index.d.ts +16 -0
- package/build/admin/src/components/DiscussionThread/index.js +99 -0
- package/build/admin/src/components/DiscussionThreadItem/index.d.ts +9 -0
- package/build/admin/src/components/DiscussionThreadItem/index.js +72 -0
- package/build/admin/src/components/DiscussionThreadItem/styles.d.ts +4 -0
- package/build/admin/src/components/DiscussionThreadItem/styles.js +27 -0
- package/build/admin/src/components/DiscussionThreadItemActions/index.d.ts +19 -0
- package/build/admin/src/components/DiscussionThreadItemActions/index.js +414 -0
- package/build/admin/src/components/DiscussionThreadItemActions/styles.d.ts +2 -0
- package/build/admin/src/components/DiscussionThreadItemActions/styles.js +17 -0
- package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.d.ts +17 -0
- package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +103 -0
- package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.d.ts +2 -0
- package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +15 -0
- package/build/admin/src/components/DiscussionThreadItemFooter/index.d.ts +16 -0
- package/build/admin/src/components/DiscussionThreadItemFooter/index.js +73 -0
- package/build/admin/src/components/DiscussionThreadItemFooter/styles.d.ts +3 -0
- package/build/admin/src/components/DiscussionThreadItemFooter/styles.js +25 -0
- package/build/admin/src/components/DiscussionThreadItemReviewAction/index.d.ts +30 -0
- package/build/admin/src/components/DiscussionThreadItemReviewAction/index.js +233 -0
- package/build/admin/src/components/FormSwitch/index.d.ts +11 -0
- package/build/admin/src/components/FormSwitch/index.js +39 -0
- package/build/admin/src/components/FormSwitch/styles.d.ts +2 -0
- package/build/admin/src/components/FormSwitch/styles.js +16 -0
- package/build/admin/src/components/IconButton/styles.d.ts +2 -0
- package/build/admin/src/components/IconButton/styles.js +27 -0
- package/build/admin/src/components/Initializer/index.d.ts +3 -0
- package/build/admin/src/components/Initializer/index.js +14 -0
- package/build/admin/src/components/LoadingIndicatorOverlay/index.d.ts +3 -0
- package/build/admin/src/components/LoadingIndicatorOverlay/index.js +18 -0
- package/build/admin/src/components/LoadingIndicatorOverlay/styles.d.ts +3 -0
- package/build/admin/src/components/LoadingIndicatorOverlay/styles.js +32 -0
- package/build/admin/src/components/Nav/index.d.ts +7 -0
- package/build/admin/src/components/Nav/index.js +72 -0
- package/build/admin/src/components/PluginIcon/index.d.ts +3 -0
- package/build/admin/src/components/PluginIcon/index.js +13 -0
- package/build/admin/src/components/ReportsReviewModal/index.d.ts +21 -0
- package/build/admin/src/components/ReportsReviewModal/index.js +72 -0
- package/build/admin/src/components/ReportsReviewTable/index.d.ts +21 -0
- package/build/admin/src/components/ReportsReviewTable/index.js +321 -0
- package/build/admin/src/components/StatusBadge/index.d.ts +11 -0
- package/build/admin/src/components/StatusBadge/index.js +22 -0
- package/build/admin/src/components/StatusBadge/styles.d.ts +2 -0
- package/build/admin/src/components/StatusBadge/styles.js +25 -0
- package/build/admin/src/components/TableFilters/index.d.ts +10 -0
- package/build/admin/src/components/TableFilters/index.js +109 -0
- package/build/admin/src/components/TablePagination/index.d.ts +15 -0
- package/build/admin/src/components/TablePagination/index.js +45 -0
- package/build/admin/src/components/icons/comments.d.ts +9 -0
- package/build/admin/src/components/icons/comments.js +23 -0
- package/build/admin/src/components/icons/index.d.ts +6 -0
- package/build/admin/src/components/icons/index.js +21 -0
- package/build/admin/src/components/icons/lock.d.ts +11 -0
- package/build/admin/src/components/icons/lock.js +29 -0
- package/build/admin/src/components/icons/review.d.ts +11 -0
- package/build/admin/src/components/icons/review.js +31 -0
- package/build/admin/src/components/icons/unlock.d.ts +11 -0
- package/build/admin/src/components/icons/unlock.js +29 -0
- package/build/admin/src/hooks/useConfig.d.ts +8 -0
- package/build/admin/src/hooks/useConfig.js +52 -0
- package/build/admin/src/index.d.ts +7 -0
- package/build/admin/src/index.js +137 -0
- package/build/admin/src/pages/App/index.d.ts +4 -0
- package/build/admin/src/pages/App/index.js +90 -0
- package/build/admin/src/pages/App/reducer/actions.d.ts +8 -0
- package/build/admin/src/pages/App/reducer/actions.js +12 -0
- package/build/admin/src/pages/App/reducer/constants.d.ts +4 -0
- package/build/admin/src/pages/App/reducer/constants.js +7 -0
- package/build/admin/src/pages/App/reducer/index.d.ts +14 -0
- package/build/admin/src/pages/App/reducer/index.js +31 -0
- package/build/admin/src/pages/App/reducer/init.d.ts +3 -0
- package/build/admin/src/pages/App/reducer/init.js +9 -0
- package/build/admin/src/pages/App/reducer/selectors.d.ts +6 -0
- package/build/admin/src/pages/App/reducer/selectors.js +20 -0
- package/build/admin/src/pages/App/utils/api.d.ts +2 -0
- package/build/admin/src/pages/App/utils/api.js +16 -0
- package/build/admin/src/pages/ComingSoonPage/index.d.ts +3 -0
- package/build/admin/src/pages/ComingSoonPage/index.js +78 -0
- package/build/admin/src/pages/Details/components/DetailsEntity/index.d.ts +18 -0
- package/build/admin/src/pages/Details/components/DetailsEntity/index.js +132 -0
- package/build/admin/src/pages/Details/components/DetailsFilters/index.d.ts +12 -0
- package/build/admin/src/pages/Details/components/DetailsFilters/index.js +48 -0
- package/build/admin/src/pages/Details/components/DetailsFilters/styles.d.ts +2 -0
- package/build/admin/src/pages/Details/components/DetailsFilters/styles.js +16 -0
- package/build/admin/src/pages/Details/index.d.ts +4 -0
- package/build/admin/src/pages/Details/index.js +216 -0
- package/build/admin/src/pages/Discover/components/DiscoverTableRow/index.d.ts +20 -0
- package/build/admin/src/pages/Discover/components/DiscoverTableRow/index.js +344 -0
- package/build/admin/src/pages/Discover/components/DiscoverTableRow/styles.d.ts +2 -0
- package/build/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +16 -0
- package/build/admin/src/pages/Discover/index.d.ts +4 -0
- package/build/admin/src/pages/Discover/index.js +332 -0
- package/build/admin/src/pages/Discover/utils/api.d.ts +2 -0
- package/build/admin/src/pages/Discover/utils/api.js +23 -0
- package/build/admin/src/pages/Discover/utils/filtersSchema.d.ts +11 -0
- package/build/admin/src/pages/Discover/utils/filtersSchema.js +11 -0
- package/build/admin/src/pages/Settings/components/RestartAlert/styles.d.ts +2 -0
- package/build/admin/src/pages/Settings/components/RestartAlert/styles.js +16 -0
- package/build/admin/src/pages/Settings/index.d.ts +3 -0
- package/build/admin/src/pages/Settings/index.js +712 -0
- package/build/admin/src/pages/Settings/utils/api.d.ts +7 -0
- package/build/admin/src/pages/Settings/utils/api.js +80 -0
- package/build/admin/src/pages/utils/api.d.ts +12 -0
- package/build/admin/src/pages/utils/api.js +83 -0
- package/build/admin/src/permissions.d.ts +28 -0
- package/build/admin/src/permissions.js +65 -0
- package/build/admin/src/pluginId.d.ts +2 -0
- package/build/admin/src/pluginId.js +50 -0
- package/build/admin/src/reducers.d.ts +12 -0
- package/build/admin/src/reducers.js +14 -0
- package/build/admin/src/translations/en.json +132 -0
- package/build/admin/src/translations/fr.json +1 -0
- package/build/admin/src/translations/pt-BR.json +132 -0
- package/build/admin/src/utils/axiosInstance.d.ts +3 -0
- package/build/admin/src/utils/axiosInstance.js +37 -0
- package/build/admin/src/utils/constants.d.ts +25 -0
- package/build/admin/src/utils/constants.js +30 -0
- package/build/admin/src/utils/getApiUrl.d.ts +3 -0
- package/build/admin/src/utils/getApiUrl.js +6 -0
- package/build/admin/src/utils/getMessage.d.ts +4 -0
- package/build/admin/src/utils/getMessage.js +25 -0
- package/build/admin/src/utils/getRelatedGroups.d.ts +4 -0
- package/build/admin/src/utils/getRelatedGroups.js +6 -0
- package/build/admin/src/utils/getUrl.d.ts +3 -0
- package/build/admin/src/utils/getUrl.js +6 -0
- package/build/admin/src/utils/handleAPIError.d.ts +4 -0
- package/build/admin/src/utils/handleAPIError.js +20 -0
- package/build/admin/src/utils/index.d.ts +12 -0
- package/build/admin/src/utils/index.js +97 -0
- package/build/admin/src/utils/parseRegExp.d.ts +6 -0
- package/build/admin/src/utils/parseRegExp.js +11 -0
- package/build/admin/src/utils/renderEntryTitle.d.ts +4 -0
- package/build/admin/src/utils/renderEntryTitle.js +16 -0
- package/build/admin/src/utils/renderInitials.d.ts +3 -0
- package/build/admin/src/utils/renderInitials.js +11 -0
- package/build/admin/src/utils/resolveCommentStatus.d.ts +4 -0
- package/build/admin/src/utils/resolveCommentStatus.js +32 -0
- package/build/admin/src/utils/resolveCommentStatusColor.d.ts +4 -0
- package/build/admin/src/utils/resolveCommentStatusColor.js +22 -0
- package/build/content-types/comment.d.ts +91 -0
- package/build/content-types/comment.js +92 -0
- package/build/content-types/index.d.ts +143 -0
- package/build/content-types/index.js +18 -0
- package/build/content-types/report.d.ts +48 -0
- package/build/content-types/report.js +49 -0
- package/build/package.json +94 -0
- package/build/permissions.d.ts +18 -0
- package/build/permissions.js +18 -0
- package/build/server/bootstrap.d.ts +4 -0
- package/build/server/bootstrap.js +65 -0
- package/build/server/config/index.d.ts +4 -0
- package/build/server/config/index.js +19 -0
- package/build/server/controllers/admin.d.ts +4 -0
- package/build/server/controllers/admin.js +124 -0
- package/build/server/controllers/client.d.ts +4 -0
- package/build/server/controllers/client.js +111 -0
- package/build/server/controllers/index.d.ts +6 -0
- package/build/server/controllers/index.js +15 -0
- package/build/server/controllers/utils/functions.d.ts +7 -0
- package/build/server/controllers/utils/functions.js +24 -0
- package/build/server/controllers/utils/parsers.d.ts +15 -0
- package/build/server/controllers/utils/parsers.js +25 -0
- package/build/server/destroy.d.ts +3 -0
- package/build/server/destroy.js +3 -0
- package/build/server/graphql/index.d.ts +4 -0
- package/build/server/graphql/index.js +37 -0
- package/build/server/graphql/mutations/createAbuseReport.d.ts +11 -0
- package/build/server/graphql/mutations/createAbuseReport.js +27 -0
- package/build/server/graphql/mutations/createComment.d.ts +14 -0
- package/build/server/graphql/mutations/createComment.js +26 -0
- package/build/server/graphql/mutations/index.d.ts +4 -0
- package/build/server/graphql/mutations/index.js +28 -0
- package/build/server/graphql/mutations/removeComment.d.ts +11 -0
- package/build/server/graphql/mutations/removeComment.js +27 -0
- package/build/server/graphql/mutations/updateComment.d.ts +11 -0
- package/build/server/graphql/mutations/updateComment.js +27 -0
- package/build/server/graphql/queries/findAllFlat.d.ts +19 -0
- package/build/server/graphql/queries/findAllFlat.js +47 -0
- package/build/server/graphql/queries/findAllInHierarchy.d.ts +18 -0
- package/build/server/graphql/queries/findAllInHierarchy.js +38 -0
- package/build/server/graphql/queries/index.d.ts +4 -0
- package/build/server/graphql/queries/index.js +24 -0
- package/build/server/graphql/resolvers-config.d.ts +23 -0
- package/build/server/graphql/resolvers-config.js +13 -0
- package/build/server/graphql/types/comment-author.d.ts +4 -0
- package/build/server/graphql/types/comment-author.js +12 -0
- package/build/server/graphql/types/comment-nested.d.ts +4 -0
- package/build/server/graphql/types/comment-nested.js +19 -0
- package/build/server/graphql/types/comment.d.ts +4 -0
- package/build/server/graphql/types/comment.js +18 -0
- package/build/server/graphql/types/create-comment-author.d.ts +4 -0
- package/build/server/graphql/types/create-comment-author.js +12 -0
- package/build/server/graphql/types/create-comment.d.ts +4 -0
- package/build/server/graphql/types/create-comment.js +12 -0
- package/build/server/graphql/types/create-report.d.ts +4 -0
- package/build/server/graphql/types/create-report.js +12 -0
- package/build/server/graphql/types/id.d.ts +4 -0
- package/build/server/graphql/types/id.js +26 -0
- package/build/server/graphql/types/identify-comment-author.d.ts +4 -0
- package/build/server/graphql/types/identify-comment-author.js +9 -0
- package/build/server/graphql/types/index.d.ts +4 -0
- package/build/server/graphql/types/index.js +44 -0
- package/build/server/graphql/types/remove-comment.d.ts +4 -0
- package/build/server/graphql/types/remove-comment.js +11 -0
- package/build/server/graphql/types/report-reason.d.ts +4 -0
- package/build/server/graphql/types/report-reason.js +12 -0
- package/build/server/graphql/types/report.d.ts +4 -0
- package/build/server/graphql/types/report.js +14 -0
- package/build/server/graphql/types/response-find-all.d.ts +4 -0
- package/build/server/graphql/types/response-find-all.js +10 -0
- package/build/server/graphql/types/response-meta.d.ts +4 -0
- package/build/server/graphql/types/response-meta.js +9 -0
- package/build/server/graphql/types/response-pagination.d.ts +4 -0
- package/build/server/graphql/types/response-pagination.js +14 -0
- package/build/server/graphql/types/update-comment.d.ts +4 -0
- package/build/server/graphql/types/update-comment.js +12 -0
- package/build/server/index.d.ts +26 -0
- package/build/server/index.js +25 -0
- package/build/server/register.d.ts +3 -0
- package/build/server/register.js +3 -0
- package/build/server/routes/admin.d.ts +4 -0
- package/build/server/routes/admin.js +118 -0
- package/build/server/routes/client.d.ts +4 -0
- package/build/server/routes/client.js +54 -0
- package/build/server/routes/index.d.ts +11 -0
- package/build/server/routes/index.js +21 -0
- package/build/server/services/admin.d.ts +5 -0
- package/build/server/services/admin.js +296 -0
- package/build/server/services/client.d.ts +5 -0
- package/build/server/services/client.js +247 -0
- package/build/server/services/common.d.ts +5 -0
- package/build/server/services/common.js +266 -0
- package/build/server/services/graphql.d.ts +5 -0
- package/build/server/services/graphql.js +136 -0
- package/build/server/services/index.d.ts +8 -0
- package/build/server/services/index.js +16 -0
- package/build/server/services/utils/functions.d.ts +13 -0
- package/build/server/services/utils/functions.js +141 -0
- package/build/server/utils/constants.d.ts +9 -0
- package/build/server/utils/constants.js +23 -0
- package/build/server/utils/error.d.ts +23 -0
- package/build/server/utils/error.js +29 -0
- package/build/server/utils/functions.d.ts +14 -0
- package/build/server/utils/functions.js +50 -0
- package/build/strapi-admin.d.ts +3 -0
- package/build/strapi-admin.js +10 -0
- package/build/strapi-server.d.ts +177 -0
- package/build/strapi-server.js +46 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/build/types/contentTypes.d.ts +46 -0
- package/build/types/contentTypes.js +3 -0
- package/package.json +3 -3
- package/server/controllers/client.js +0 -3
- package/server/graphql/queries/findAllFlat.js +6 -2
- package/server/services/common.js +2 -2
|
@@ -0,0 +1,266 @@
|
|
|
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;
|
|
11
|
+
module.exports = ({ strapi }) => ({
|
|
12
|
+
async getConfig(prop, defaultValue, useLocal = false) {
|
|
13
|
+
const queryProp = (0, functions_1.buildConfigQueryProp)(prop);
|
|
14
|
+
const pluginStore = await this.getPluginStore();
|
|
15
|
+
const config = await pluginStore.get({
|
|
16
|
+
key: "config",
|
|
17
|
+
});
|
|
18
|
+
let result;
|
|
19
|
+
if (config && !useLocal) {
|
|
20
|
+
result = queryProp ? (0, lodash_1.get)(config, queryProp, defaultValue) : config;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
result = this.getLocalConfig(queryProp, defaultValue);
|
|
24
|
+
}
|
|
25
|
+
return (0, lodash_1.isNil)(result) ? defaultValue : result;
|
|
26
|
+
},
|
|
27
|
+
async getPluginStore() {
|
|
28
|
+
return strapi.store({ type: "plugin", name: "comments" });
|
|
29
|
+
},
|
|
30
|
+
getLocalConfig(prop, defaultValue) {
|
|
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;
|
|
34
|
+
},
|
|
35
|
+
async findAllFlat({ query = {}, populate = {}, sort, pagination }, relatedEntity = null) {
|
|
36
|
+
const defaultPopulate = {
|
|
37
|
+
authorUser: true,
|
|
38
|
+
};
|
|
39
|
+
let queryExtension = {};
|
|
40
|
+
if (sort && ((0, lodash_1.isString)(sort) || (0, lodash_1.isArray)(sort))) {
|
|
41
|
+
queryExtension = {
|
|
42
|
+
...queryExtension,
|
|
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
|
+
}, {}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
let meta = {};
|
|
52
|
+
if (pagination && (0, lodash_1.isObject)(pagination)) {
|
|
53
|
+
const parsedpagination = Object.keys(pagination).reduce((prev, curr) => ({
|
|
54
|
+
...prev,
|
|
55
|
+
[curr]: (0, lodash_1.parseInt)((0, lodash_1.get)(pagination, curr)),
|
|
56
|
+
}), {});
|
|
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);
|
|
59
|
+
queryExtension = {
|
|
60
|
+
...queryExtension,
|
|
61
|
+
offset: paginationByPage ? (page - 1) * pageSize : start,
|
|
62
|
+
limit: paginationByPage ? pageSize : limit,
|
|
63
|
+
};
|
|
64
|
+
const metapagination = paginationByPage
|
|
65
|
+
? {
|
|
66
|
+
pagination: {
|
|
67
|
+
page,
|
|
68
|
+
pageSize,
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
: {
|
|
72
|
+
pagination: {
|
|
73
|
+
start,
|
|
74
|
+
limit,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
meta = {
|
|
78
|
+
...metapagination,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const entries = await strapi.db
|
|
82
|
+
.query((0, functions_1.getModelUid)("comment"))
|
|
83
|
+
.findMany({
|
|
84
|
+
where: {
|
|
85
|
+
...query,
|
|
86
|
+
},
|
|
87
|
+
populate: {
|
|
88
|
+
...defaultPopulate,
|
|
89
|
+
...populate,
|
|
90
|
+
},
|
|
91
|
+
...queryExtension,
|
|
92
|
+
});
|
|
93
|
+
if (pagination?.withCount &&
|
|
94
|
+
(pagination.withCount === "true" || pagination.withCount === true)) {
|
|
95
|
+
const total = await strapi.db
|
|
96
|
+
.query((0, functions_1.getModelUid)("comment"))
|
|
97
|
+
.count({
|
|
98
|
+
where: {
|
|
99
|
+
...query,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
const pageSize = meta.pagination.pageSize || PAGE_SIZE;
|
|
103
|
+
const pageCount = Math.floor(total / pageSize);
|
|
104
|
+
meta = {
|
|
105
|
+
...meta,
|
|
106
|
+
pagination: {
|
|
107
|
+
...meta.pagination,
|
|
108
|
+
pageCount: !(0, lodash_1.isNil)(meta.pagination.page)
|
|
109
|
+
? total % pageSize === 0
|
|
110
|
+
? pageCount
|
|
111
|
+
: pageCount + 1
|
|
112
|
+
: undefined,
|
|
113
|
+
total,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
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
|
+
};
|
|
130
|
+
}));
|
|
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,
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
data: hasRelatedEntitiesToMap
|
|
149
|
+
? result.map((_) => this.mergeRelatedEntityTo(_, relatedEntities))
|
|
150
|
+
: result,
|
|
151
|
+
...((0, lodash_1.isEmpty)(meta) ? {} : { meta }),
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
async findAllInHierarchy({ query, populate = {}, sort, startingFromId = null, dropBlockedThreads = false, }, relatedEntity) {
|
|
155
|
+
const entities = await this.findAllFlat({ query, populate, sort }, relatedEntity);
|
|
156
|
+
return (0, functions_1.buildNestedStructure)(entities?.data, startingFromId, "threadOf", dropBlockedThreads, false);
|
|
157
|
+
},
|
|
158
|
+
async findOne(criteria) {
|
|
159
|
+
const entity = await strapi.db
|
|
160
|
+
.query((0, functions_1.getModelUid)("comment"))
|
|
161
|
+
.findOne({
|
|
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.");
|
|
170
|
+
}
|
|
171
|
+
return (0, functions_1.filterOurResolvedReports)(this.sanitizeCommentEntity(entity));
|
|
172
|
+
},
|
|
173
|
+
async findRelatedEntitiesFor(entities = []) {
|
|
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));
|
|
194
|
+
},
|
|
195
|
+
mergeRelatedEntityTo(entity, relatedEntities = []) {
|
|
196
|
+
return {
|
|
197
|
+
...entity,
|
|
198
|
+
related: relatedEntities.find((relatedEntity) => entity.related === `${relatedEntity.uid}:${relatedEntity.id}`),
|
|
199
|
+
};
|
|
200
|
+
},
|
|
201
|
+
async modifiedNestedNestedComments(id, fieldName, value) {
|
|
202
|
+
try {
|
|
203
|
+
const entitiesToChange = await strapi.db
|
|
204
|
+
.query((0, functions_1.getModelUid)("comment"))
|
|
205
|
+
.findMany({
|
|
206
|
+
where: { threadOf: id },
|
|
207
|
+
});
|
|
208
|
+
const changedEntities = await strapi.db
|
|
209
|
+
.query((0, functions_1.getModelUid)("comment"))
|
|
210
|
+
.updateMany({
|
|
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)));
|
|
217
|
+
return nestedTransactions.length === changedEntities.length;
|
|
218
|
+
}
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
catch (e) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
sanitizeCommentEntity(entity) {
|
|
226
|
+
return {
|
|
227
|
+
...(0, functions_1.buildAuthorModel)({
|
|
228
|
+
...entity,
|
|
229
|
+
threadOf: (0, lodash_1.isObject)(entity.threadOf)
|
|
230
|
+
? (0, functions_1.buildAuthorModel)(entity.threadOf)
|
|
231
|
+
: entity.threadOf,
|
|
232
|
+
}),
|
|
233
|
+
};
|
|
234
|
+
},
|
|
235
|
+
isValidUserContext(user) {
|
|
236
|
+
return user ? !(0, lodash_1.isNil)(user?.id) : true;
|
|
237
|
+
},
|
|
238
|
+
async parseRelationString(relation) {
|
|
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, []);
|
|
245
|
+
if (!enabledCollections.includes(uid)) {
|
|
246
|
+
throw new error_1.default(403, `Action not allowed for collection '${uid}'. Use one of: ${enabledCollections.join(", ")}`);
|
|
247
|
+
}
|
|
248
|
+
return [uid, relatedId];
|
|
249
|
+
},
|
|
250
|
+
async checkBadWords(content) {
|
|
251
|
+
const config = await this.getConfig(constants_1.CONFIG_PARAMS.BAD_WORDS, true);
|
|
252
|
+
if (config) {
|
|
253
|
+
const filter = new bad_words_1.default((0, lodash_1.isObject)(config) ? config : undefined);
|
|
254
|
+
if (content && filter.isProfane(content)) {
|
|
255
|
+
throw new error_1.default(400, "Bad language used! Please polite your comment...", {
|
|
256
|
+
content: {
|
|
257
|
+
original: content,
|
|
258
|
+
filtered: content && filter.clean(content),
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return content;
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fp_1 = require("lodash/fp");
|
|
3
|
+
const nexus_1 = require("nexus");
|
|
4
|
+
const virtualScalarAttributes = ["id"];
|
|
5
|
+
module.exports = ({ strapi }) => {
|
|
6
|
+
const { service: getService } = strapi.plugin("graphql");
|
|
7
|
+
const rootLevelOperators = () => {
|
|
8
|
+
const { operators } = strapi.plugin("graphql").service("builders").filters;
|
|
9
|
+
return [operators.and, operators.or, operators.not];
|
|
10
|
+
};
|
|
11
|
+
const buildContentTypeFilters = (contentType) => {
|
|
12
|
+
const utils = strapi.plugin("graphql").service("utils");
|
|
13
|
+
const extension = strapi.plugin("graphql").service("extension");
|
|
14
|
+
const { getFiltersInputTypeName, getScalarFilterInputTypeName } =
|
|
15
|
+
utils.naming;
|
|
16
|
+
const { isStrapiScalar, isRelation } = utils.attributes;
|
|
17
|
+
const { attributes } = contentType;
|
|
18
|
+
const filtersTypeName = getFiltersInputTypeName(contentType);
|
|
19
|
+
return (0, nexus_1.inputObjectType)({
|
|
20
|
+
name: filtersTypeName,
|
|
21
|
+
definition(t) {
|
|
22
|
+
const validAttributes = Object.entries(attributes).filter(
|
|
23
|
+
([attributeName]) =>
|
|
24
|
+
extension
|
|
25
|
+
.shadowCRUD(contentType.uid)
|
|
26
|
+
.field(attributeName)
|
|
27
|
+
.hasFiltersEnabeld()
|
|
28
|
+
);
|
|
29
|
+
const isIDFilterEnabled = extension
|
|
30
|
+
.shadowCRUD(contentType.uid)
|
|
31
|
+
.field("id")
|
|
32
|
+
.hasFiltersEnabeld();
|
|
33
|
+
if (contentType.kind === "collectionType" && isIDFilterEnabled) {
|
|
34
|
+
t.field("id", { type: getScalarFilterInputTypeName("ID") });
|
|
35
|
+
}
|
|
36
|
+
for (const [attributeName, attribute] of validAttributes) {
|
|
37
|
+
if (isStrapiScalar(attribute)) {
|
|
38
|
+
addScalarAttribute(t, attributeName, attribute);
|
|
39
|
+
} else if (isRelation(attribute)) {
|
|
40
|
+
addRelationalAttribute(t, attributeName, attribute);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
for (const operator of rootLevelOperators()) {
|
|
44
|
+
operator.add(t, filtersTypeName);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const addScalarAttribute = (builder, attributeName, attribute) => {
|
|
50
|
+
const { naming, mappers } = strapi.plugin("graphql").service("utils");
|
|
51
|
+
const gqlType = mappers.strapiScalarToGraphQLScalar(attribute.type);
|
|
52
|
+
builder.field(attributeName, {
|
|
53
|
+
type: naming.getScalarFilterInputTypeName(gqlType),
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
const addRelationalAttribute = (builder, attributeName, attribute) => {
|
|
57
|
+
const utils = strapi.plugin("graphql").service("utils");
|
|
58
|
+
const extension = strapi.plugin("graphql").service("extension");
|
|
59
|
+
const { getFiltersInputTypeName } = utils.naming;
|
|
60
|
+
const { isMorphRelation } = utils.attributes;
|
|
61
|
+
const model = strapi.getModel(attribute.target);
|
|
62
|
+
if (!model || isMorphRelation(attribute)) return;
|
|
63
|
+
if (extension.shadowCRUD(model.uid).isDisabled()) return;
|
|
64
|
+
builder.field(attributeName, { type: getFiltersInputTypeName(model) });
|
|
65
|
+
};
|
|
66
|
+
const recursivelyReplaceScalarOperators = (data) => {
|
|
67
|
+
const { operators } = getService("builders").filters;
|
|
68
|
+
if (Array.isArray(data)) {
|
|
69
|
+
return data.map(recursivelyReplaceScalarOperators);
|
|
70
|
+
}
|
|
71
|
+
if ((0, fp_1.isDate)(data) || !(0, fp_1.isObject)(data)) {
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
const result = {};
|
|
75
|
+
for (const [key, value] of Object.entries(data)) {
|
|
76
|
+
const isOperator = !!operators[key];
|
|
77
|
+
const newKey = isOperator ? operators[key].strapiOperator : key;
|
|
78
|
+
result[newKey] = recursivelyReplaceScalarOperators(value);
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
const graphQLFiltersToStrapiQuery = (filters, contentType = {}) => {
|
|
83
|
+
const { isStrapiScalar, isMedia, isRelation } =
|
|
84
|
+
getService("utils").attributes;
|
|
85
|
+
const { operators } = getService("builders").filters;
|
|
86
|
+
const ROOT_LEVEL_OPERATORS = [operators.and, operators.or, operators.not];
|
|
87
|
+
if ((0, fp_1.isNil)(filters)) {
|
|
88
|
+
return {};
|
|
89
|
+
}
|
|
90
|
+
if (Array.isArray(filters)) {
|
|
91
|
+
return filters.map((filtersItem) =>
|
|
92
|
+
graphQLFiltersToStrapiQuery(filtersItem, contentType)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const resultMap = {};
|
|
96
|
+
const { attributes } = contentType;
|
|
97
|
+
const isAttribute = (attributeName) => {
|
|
98
|
+
return (
|
|
99
|
+
virtualScalarAttributes.includes(attributeName) ||
|
|
100
|
+
(0, fp_1.has)(attributeName, attributes)
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
104
|
+
if (isAttribute(key)) {
|
|
105
|
+
const attribute = attributes[key];
|
|
106
|
+
if (
|
|
107
|
+
virtualScalarAttributes.includes(key) ||
|
|
108
|
+
isStrapiScalar(attribute)
|
|
109
|
+
) {
|
|
110
|
+
resultMap[key] = recursivelyReplaceScalarOperators(value);
|
|
111
|
+
} else if (isRelation(attribute) || isMedia(attribute)) {
|
|
112
|
+
const relModel = strapi.getModel(attribute.target);
|
|
113
|
+
resultMap[key] = graphQLFiltersToStrapiQuery(value, relModel);
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
const rootLevelOperator = ROOT_LEVEL_OPERATORS.find(
|
|
117
|
+
(0, fp_1.propEq)("fieldName", key)
|
|
118
|
+
);
|
|
119
|
+
if (rootLevelOperator) {
|
|
120
|
+
const { strapiOperator } = rootLevelOperator;
|
|
121
|
+
resultMap[strapiOperator] = graphQLFiltersToStrapiQuery(
|
|
122
|
+
value,
|
|
123
|
+
contentType
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return resultMap;
|
|
129
|
+
};
|
|
130
|
+
const serviceMethods = {
|
|
131
|
+
buildContentTypeFilters,
|
|
132
|
+
graphQLFiltersToStrapiQuery,
|
|
133
|
+
};
|
|
134
|
+
return serviceMethods;
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=graphql.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
admin: ({ strapi }: import("strapi-typed").StrapiContext) => import("../../types").IServiceAdmin;
|
|
3
|
+
client: ({ strapi }: import("strapi-typed").StrapiContext) => import("../../types").IServiceClient;
|
|
4
|
+
common: ({ strapi }: import("strapi-typed").StrapiContext) => import("../../types").IServiceCommon;
|
|
5
|
+
gql: ({ strapi }: import("strapi-typed").StrapiContext) => import("../../types").IServiceGraphQL;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
const admin_1 = __importDefault(require("./admin"));
|
|
7
|
+
const client_1 = __importDefault(require("./client"));
|
|
8
|
+
const common_1 = __importDefault(require("./common"));
|
|
9
|
+
const graphql_1 = __importDefault(require("./graphql"));
|
|
10
|
+
exports.default = {
|
|
11
|
+
admin: admin_1.default,
|
|
12
|
+
client: client_1.default,
|
|
13
|
+
common: common_1.default,
|
|
14
|
+
gql: graphql_1.default,
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Id, StrapiUser } from "strapi-typed";
|
|
2
|
+
import { Comment, ToBeFixed } from "../../../types";
|
|
3
|
+
import PluginError from "./../../utils/error";
|
|
4
|
+
export declare const buildNestedStructure: (entities: Array<Comment>, id?: Id | null, field?: string, dropBlockedThreads?: boolean, blockNestedThreads?: boolean) => Array<Comment>;
|
|
5
|
+
export declare const isEqualEntity: (existing: Comment, data: ToBeFixed, user: StrapiUser) => boolean;
|
|
6
|
+
export declare const getRelatedGroups: (related: string) => Array<string>;
|
|
7
|
+
export declare const getModelUid: (name: string) => string;
|
|
8
|
+
export declare const filterOurResolvedReports: (item: Comment) => Comment;
|
|
9
|
+
export declare const convertContentTypeNameToSlug: (str: string) => string;
|
|
10
|
+
export declare const buildAuthorModel: (item: Comment) => Comment;
|
|
11
|
+
export declare const buildConfigQueryProp: (prop?: undefined | string | Array<string>) => string;
|
|
12
|
+
export declare const resolveUserContextError: (user: StrapiUser) => PluginError;
|
|
13
|
+
//# sourceMappingURL=functions.d.ts.map
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault =
|
|
3
|
+
(this && this.__importDefault) ||
|
|
4
|
+
function (mod) {
|
|
5
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.resolveUserContextError =
|
|
9
|
+
exports.buildConfigQueryProp =
|
|
10
|
+
exports.buildAuthorModel =
|
|
11
|
+
exports.convertContentTypeNameToSlug =
|
|
12
|
+
exports.filterOurResolvedReports =
|
|
13
|
+
exports.getModelUid =
|
|
14
|
+
exports.getRelatedGroups =
|
|
15
|
+
exports.isEqualEntity =
|
|
16
|
+
exports.buildNestedStructure =
|
|
17
|
+
void 0;
|
|
18
|
+
const error_1 = __importDefault(require("./../../utils/error"));
|
|
19
|
+
const constants_1 = require("./../../utils/constants");
|
|
20
|
+
const lodash_1 = require("lodash");
|
|
21
|
+
const buildNestedStructure = (
|
|
22
|
+
entities,
|
|
23
|
+
id = null,
|
|
24
|
+
field = "threadOf",
|
|
25
|
+
dropBlockedThreads = false,
|
|
26
|
+
blockNestedThreads = false
|
|
27
|
+
) =>
|
|
28
|
+
entities
|
|
29
|
+
.filter((entity) => {
|
|
30
|
+
const entityField = (0, lodash_1.get)(entity, field);
|
|
31
|
+
if (entityField === null && id === null) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
let data = entityField;
|
|
35
|
+
if (data && typeof id === "string") {
|
|
36
|
+
data = data.toString();
|
|
37
|
+
}
|
|
38
|
+
return (
|
|
39
|
+
(data && data === id) ||
|
|
40
|
+
((0, lodash_1.isObject)(entityField) && entityField.id === id)
|
|
41
|
+
);
|
|
42
|
+
})
|
|
43
|
+
.map((entity) => ({
|
|
44
|
+
...entity,
|
|
45
|
+
[field]: undefined,
|
|
46
|
+
related: undefined,
|
|
47
|
+
blockedThread: blockNestedThreads || entity.blockedThread,
|
|
48
|
+
children:
|
|
49
|
+
entity.blockedThread && dropBlockedThreads
|
|
50
|
+
? []
|
|
51
|
+
: (0, exports.buildNestedStructure)(
|
|
52
|
+
entities,
|
|
53
|
+
entity.id,
|
|
54
|
+
field,
|
|
55
|
+
dropBlockedThreads,
|
|
56
|
+
entity.blockedThread
|
|
57
|
+
),
|
|
58
|
+
}));
|
|
59
|
+
exports.buildNestedStructure = buildNestedStructure;
|
|
60
|
+
const isEqualEntity = (existing, data, user) => {
|
|
61
|
+
const { author: existingAuthor = {} } = existing;
|
|
62
|
+
const { author } = data;
|
|
63
|
+
if (data.approvalStatus && existing.approvalStatus !== data.approvalStatus) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (user) {
|
|
67
|
+
const existingUserId = existingAuthor?.id || existingAuthor;
|
|
68
|
+
const receivedUserId = user?.id || author?.id;
|
|
69
|
+
return receivedUserId && existingUserId === receivedUserId;
|
|
70
|
+
}
|
|
71
|
+
return existingAuthor.id === author?.id;
|
|
72
|
+
};
|
|
73
|
+
exports.isEqualEntity = isEqualEntity;
|
|
74
|
+
const getRelatedGroups = (related) =>
|
|
75
|
+
related.split(constants_1.REGEX.relatedUid).filter((s) => s && s.length > 0);
|
|
76
|
+
exports.getRelatedGroups = getRelatedGroups;
|
|
77
|
+
const getModelUid = (name) => {
|
|
78
|
+
return strapi.plugin("comments").contentTypes[name]?.uid;
|
|
79
|
+
};
|
|
80
|
+
exports.getModelUid = getModelUid;
|
|
81
|
+
const filterOurResolvedReports = (item) =>
|
|
82
|
+
item
|
|
83
|
+
? {
|
|
84
|
+
...item,
|
|
85
|
+
reports: (item.reports || []).filter((report) => !report.resolved),
|
|
86
|
+
}
|
|
87
|
+
: item;
|
|
88
|
+
exports.filterOurResolvedReports = filterOurResolvedReports;
|
|
89
|
+
const convertContentTypeNameToSlug = (str) => {
|
|
90
|
+
const plainConversion = str.replace(
|
|
91
|
+
/[A-Z]/g,
|
|
92
|
+
(letter) => `-${letter.toLowerCase()}`
|
|
93
|
+
);
|
|
94
|
+
return (0, lodash_1.first)(plainConversion) === "-"
|
|
95
|
+
? plainConversion.slice(1, plainConversion.length)
|
|
96
|
+
: plainConversion;
|
|
97
|
+
};
|
|
98
|
+
exports.convertContentTypeNameToSlug = convertContentTypeNameToSlug;
|
|
99
|
+
const buildAuthorModel = (item) => {
|
|
100
|
+
const {
|
|
101
|
+
authorUser,
|
|
102
|
+
authorId,
|
|
103
|
+
authorName,
|
|
104
|
+
authorEmail,
|
|
105
|
+
authorAvatar,
|
|
106
|
+
...rest
|
|
107
|
+
} = item;
|
|
108
|
+
let author = {};
|
|
109
|
+
if (authorUser) {
|
|
110
|
+
author = {
|
|
111
|
+
id: authorUser.id,
|
|
112
|
+
name: authorUser.username,
|
|
113
|
+
email: authorUser.email,
|
|
114
|
+
avatar: authorUser.avatar,
|
|
115
|
+
};
|
|
116
|
+
} else if (authorId) {
|
|
117
|
+
author = {
|
|
118
|
+
id: authorId,
|
|
119
|
+
name: authorName,
|
|
120
|
+
email: authorEmail,
|
|
121
|
+
avatar: authorAvatar,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
...rest,
|
|
126
|
+
author: (0, lodash_1.isEmpty)(author) ? undefined : author,
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
exports.buildAuthorModel = buildAuthorModel;
|
|
130
|
+
const buildConfigQueryProp = (prop = "") =>
|
|
131
|
+
(0, lodash_1.isArray)(prop) ? prop.join(".") : prop ?? "";
|
|
132
|
+
exports.buildConfigQueryProp = buildConfigQueryProp;
|
|
133
|
+
const resolveUserContextError = (user) => {
|
|
134
|
+
if (user) {
|
|
135
|
+
throw new error_1.default(401, "Not authenticated");
|
|
136
|
+
} else {
|
|
137
|
+
throw new error_1.default(403, "Not authorized");
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
exports.resolveUserContextError = resolveUserContextError;
|
|
141
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConfigParamKeys, RegExpCollection } from "../../types";
|
|
2
|
+
export declare const CONFIG_PARAMS: ConfigParamKeys;
|
|
3
|
+
export declare const APPROVAL_STATUS: {
|
|
4
|
+
PENDING: string;
|
|
5
|
+
APPROVED: string;
|
|
6
|
+
REJECTED: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const REGEX: RegExpCollection;
|
|
9
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REGEX = exports.APPROVAL_STATUS = exports.CONFIG_PARAMS = void 0;
|
|
4
|
+
exports.CONFIG_PARAMS = {
|
|
5
|
+
ENABLED_COLLECTIONS: "enabledCollections",
|
|
6
|
+
APPROVAL_FLOW: "approvalFlow",
|
|
7
|
+
ENTRY_LABEL: "entryLabel",
|
|
8
|
+
MODERATOR_ROLES: "moderatorRoles",
|
|
9
|
+
BAD_WORDS: "badWords",
|
|
10
|
+
};
|
|
11
|
+
exports.APPROVAL_STATUS = {
|
|
12
|
+
PENDING: "PENDING",
|
|
13
|
+
APPROVED: "APPROVED",
|
|
14
|
+
REJECTED: "REJECTED",
|
|
15
|
+
};
|
|
16
|
+
exports.REGEX = {
|
|
17
|
+
uid: /^(?<type>[a-z0-9-]+)\:{2}(?<api>[a-z0-9-]+)\.{1}(?<contentType>[a-z0-9-]+)$/i,
|
|
18
|
+
relatedUid:
|
|
19
|
+
/^(?<uid>[a-z0-9-]+\:{2}[a-z0-9-]+\.[a-z0-9-]+)\:{1}(?<id>[a-z0-9-]+)$/i,
|
|
20
|
+
email: /\S+@\S+\.\S+/,
|
|
21
|
+
sorting: /^(?<path>[a-z0-9-_\:\.]+)\:+(asc|desc)$/i,
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare type ErrorPayload =
|
|
2
|
+
| {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}
|
|
5
|
+
| undefined;
|
|
6
|
+
interface IPluginError extends Error {
|
|
7
|
+
status: number;
|
|
8
|
+
payload: ErrorPayload;
|
|
9
|
+
}
|
|
10
|
+
export default class PluginError extends Error implements IPluginError {
|
|
11
|
+
status: number;
|
|
12
|
+
payload: ErrorPayload;
|
|
13
|
+
constructor(status: number, message: string, payload?: ErrorPayload);
|
|
14
|
+
toString(e?: PluginError): string;
|
|
15
|
+
toJSON():
|
|
16
|
+
| this
|
|
17
|
+
| {
|
|
18
|
+
name: string;
|
|
19
|
+
message: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class PluginError extends Error {
|
|
4
|
+
status;
|
|
5
|
+
payload;
|
|
6
|
+
constructor(status, message, payload = undefined) {
|
|
7
|
+
super();
|
|
8
|
+
this.name = "Strapi:Plugin:Comments";
|
|
9
|
+
this.status = status || 500;
|
|
10
|
+
this.message = message || "Internal error";
|
|
11
|
+
this.payload = payload;
|
|
12
|
+
Object.setPrototypeOf(this, PluginError.prototype);
|
|
13
|
+
}
|
|
14
|
+
toString(e = this) {
|
|
15
|
+
return `${e.name} - ${e.message}`;
|
|
16
|
+
}
|
|
17
|
+
toJSON() {
|
|
18
|
+
if (this.payload) {
|
|
19
|
+
return {
|
|
20
|
+
name: this.name,
|
|
21
|
+
message: this.message,
|
|
22
|
+
...(this.payload || {}),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.default = PluginError;
|
|
29
|
+
//# sourceMappingURL=error.js.map
|