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.
Files changed (266) hide show
  1. package/README.md +164 -120
  2. package/admin/src/components/ActionButton/styles.d.ts +2 -0
  3. package/admin/src/components/ActionButton/styles.js +13 -8
  4. package/admin/src/components/ConfirmationDialog/index.d.ts +26 -0
  5. package/admin/src/components/ConfirmationDialog/index.js +36 -55
  6. package/admin/src/components/DiscussionStatus/index.d.ts +9 -0
  7. package/admin/src/components/DiscussionStatus/index.js +22 -31
  8. package/admin/src/components/DiscussionThread/index.d.ts +16 -0
  9. package/admin/src/components/DiscussionThread/index.js +39 -56
  10. package/admin/src/components/DiscussionThreadItem/index.d.ts +9 -0
  11. package/admin/src/components/DiscussionThreadItem/index.js +28 -52
  12. package/admin/src/components/DiscussionThreadItem/styles.d.ts +4 -0
  13. package/admin/src/components/DiscussionThreadItem/styles.js +16 -11
  14. package/admin/src/components/DiscussionThreadItemActions/index.d.ts +19 -0
  15. package/admin/src/components/DiscussionThreadItemActions/index.js +121 -158
  16. package/admin/src/components/DiscussionThreadItemActions/styles.d.ts +2 -0
  17. package/admin/src/components/DiscussionThreadItemActions/styles.js +13 -7
  18. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.d.ts +17 -0
  19. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +38 -48
  20. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.d.ts +2 -0
  21. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +12 -6
  22. package/admin/src/components/DiscussionThreadItemFooter/index.d.ts +16 -0
  23. package/admin/src/components/DiscussionThreadItemFooter/index.js +35 -42
  24. package/admin/src/components/DiscussionThreadItemFooter/styles.d.ts +3 -0
  25. package/admin/src/components/DiscussionThreadItemFooter/styles.js +17 -12
  26. package/admin/src/components/DiscussionThreadItemReviewAction/index.d.ts +30 -0
  27. package/admin/src/components/DiscussionThreadItemReviewAction/index.js +77 -91
  28. package/admin/src/components/FormSwitch/index.d.ts +7 -0
  29. package/admin/src/components/FormSwitch/index.js +15 -18
  30. package/admin/src/components/FormSwitch/styles.d.ts +2 -0
  31. package/admin/src/components/FormSwitch/styles.js +14 -8
  32. package/admin/src/components/IconButton/styles.d.ts +2 -0
  33. package/admin/src/components/IconButton/styles.js +16 -9
  34. package/admin/src/components/Initializer/index.d.ts +5 -0
  35. package/admin/src/components/Initializer/index.js +12 -24
  36. package/admin/src/components/LoadingIndicatorOverlay/index.d.ts +3 -0
  37. package/admin/src/components/LoadingIndicatorOverlay/index.js +12 -15
  38. package/admin/src/components/LoadingIndicatorOverlay/styles.d.ts +3 -0
  39. package/admin/src/components/LoadingIndicatorOverlay/styles.js +22 -17
  40. package/admin/src/components/Nav/index.d.ts +7 -0
  41. package/admin/src/components/Nav/index.js +25 -48
  42. package/admin/src/components/PluginIcon/index.d.ts +3 -0
  43. package/admin/src/components/PluginIcon/index.js +10 -12
  44. package/admin/src/components/ReportsReviewModal/index.d.ts +21 -0
  45. package/admin/src/components/ReportsReviewModal/index.js +31 -46
  46. package/admin/src/components/ReportsReviewTable/index.d.ts +21 -0
  47. package/admin/src/components/ReportsReviewTable/index.js +120 -140
  48. package/admin/src/components/StatusBadge/index.d.ts +7 -0
  49. package/admin/src/components/StatusBadge/index.js +12 -17
  50. package/admin/src/components/StatusBadge/styles.d.ts +2 -0
  51. package/admin/src/components/StatusBadge/styles.js +19 -13
  52. package/admin/src/components/TableFilters/index.d.ts +10 -0
  53. package/admin/src/components/TableFilters/index.js +52 -49
  54. package/admin/src/components/TablePagination/index.d.ts +17 -0
  55. package/admin/src/components/TablePagination/index.js +27 -29
  56. package/admin/src/components/icons/comments.d.ts +6 -0
  57. package/admin/src/components/icons/comments.js +11 -8
  58. package/admin/src/components/icons/index.d.ts +6 -0
  59. package/admin/src/components/icons/index.js +15 -6
  60. package/admin/src/components/icons/lock.d.ts +7 -0
  61. package/admin/src/components/icons/lock.js +11 -21
  62. package/admin/src/components/icons/review.d.ts +7 -0
  63. package/admin/src/components/icons/review.js +11 -17
  64. package/admin/src/components/icons/unlock.d.ts +7 -0
  65. package/admin/src/components/icons/unlock.js +11 -19
  66. package/admin/src/hooks/useConfig.d.ts +8 -0
  67. package/admin/src/hooks/useConfig.js +40 -45
  68. package/admin/src/index.d.ts +7 -0
  69. package/admin/src/index.js +98 -92
  70. package/admin/src/pages/App/index.d.ts +4 -0
  71. package/admin/src/pages/App/index.js +43 -67
  72. package/admin/src/pages/App/reducer/actions.d.ts +8 -0
  73. package/admin/src/pages/App/reducer/actions.js +11 -7
  74. package/admin/src/pages/App/reducer/constants.d.ts +4 -0
  75. package/admin/src/pages/App/reducer/constants.js +7 -4
  76. package/admin/src/pages/App/reducer/index.d.ts +9 -0
  77. package/admin/src/pages/App/reducer/index.js +24 -22
  78. package/admin/src/pages/App/reducer/init.d.ts +3 -0
  79. package/admin/src/pages/App/reducer/init.js +6 -4
  80. package/admin/src/pages/App/reducer/selectors.d.ts +6 -0
  81. package/admin/src/pages/App/reducer/selectors.js +17 -34
  82. package/admin/src/pages/App/utils/api.d.ts +2 -0
  83. package/admin/src/pages/App/utils/api.js +14 -11
  84. package/admin/src/pages/ComingSoonPage/index.d.ts +3 -0
  85. package/admin/src/pages/ComingSoonPage/index.js +42 -24
  86. package/admin/src/pages/Details/components/DetailsEntity/index.d.ts +18 -0
  87. package/admin/src/pages/Details/components/DetailsEntity/index.js +49 -77
  88. package/admin/src/pages/Details/components/DetailsFilters/index.d.ts +12 -0
  89. package/admin/src/pages/Details/components/DetailsFilters/index.js +19 -26
  90. package/admin/src/pages/Details/components/DetailsFilters/styles.d.ts +2 -0
  91. package/admin/src/pages/Details/components/DetailsFilters/styles.js +14 -8
  92. package/admin/src/pages/Details/index.d.ts +4 -0
  93. package/admin/src/pages/Details/index.js +94 -133
  94. package/admin/src/pages/Discover/components/DiscoverTableRow/index.d.ts +20 -0
  95. package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +128 -139
  96. package/admin/src/pages/Discover/components/DiscoverTableRow/styles.d.ts +2 -0
  97. package/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +14 -8
  98. package/admin/src/pages/Discover/index.d.ts +4 -0
  99. package/admin/src/pages/Discover/index.js +129 -170
  100. package/admin/src/pages/Discover/utils/api.d.ts +2 -0
  101. package/admin/src/pages/Discover/utils/api.js +15 -13
  102. package/admin/src/pages/Discover/utils/filtersSchema.d.ts +11 -0
  103. package/admin/src/pages/Discover/utils/filtersSchema.js +8 -6
  104. package/admin/src/pages/Settings/components/RestartAlert/styles.d.ts +2 -0
  105. package/admin/src/pages/Settings/components/RestartAlert/styles.js +14 -8
  106. package/admin/src/pages/Settings/index.d.ts +3 -0
  107. package/admin/src/pages/Settings/index.js +225 -391
  108. package/admin/src/pages/Settings/utils/api.d.ts +7 -0
  109. package/admin/src/pages/Settings/utils/api.js +60 -55
  110. package/admin/src/pages/utils/api.d.ts +12 -0
  111. package/admin/src/pages/utils/api.js +58 -53
  112. package/admin/src/permissions.d.ts +28 -0
  113. package/admin/src/permissions.js +31 -17
  114. package/admin/src/pluginId.d.ts +2 -0
  115. package/admin/src/pluginId.js +29 -5
  116. package/admin/src/reducers.d.ts +7 -0
  117. package/admin/src/reducers.js +10 -6
  118. package/admin/src/translations/en.json +131 -131
  119. package/admin/src/translations/fr.json +1 -1
  120. package/admin/src/utils/axiosInstance.d.ts +3 -0
  121. package/admin/src/utils/axiosInstance.js +21 -27
  122. package/admin/src/utils/constants.d.ts +25 -0
  123. package/admin/src/utils/constants.js +23 -22
  124. package/admin/src/utils/getApiUrl.d.ts +3 -0
  125. package/admin/src/utils/getApiUrl.js +6 -5
  126. package/admin/src/utils/getMessage.d.ts +4 -0
  127. package/admin/src/utils/getMessage.js +15 -15
  128. package/admin/src/utils/getRelatedGroups.d.ts +4 -0
  129. package/admin/src/utils/getRelatedGroups.js +5 -3
  130. package/admin/src/utils/getUrl.d.ts +3 -0
  131. package/admin/src/utils/getUrl.js +6 -5
  132. package/admin/src/utils/handleAPIError.d.ts +4 -0
  133. package/admin/src/utils/handleAPIError.js +12 -11
  134. package/admin/src/utils/index.d.ts +12 -0
  135. package/admin/src/utils/index.js +29 -11
  136. package/admin/src/utils/parseRegExp.d.ts +6 -0
  137. package/admin/src/utils/parseRegExp.js +6 -5
  138. package/admin/src/utils/renderEntryTitle.d.ts +4 -0
  139. package/admin/src/utils/renderEntryTitle.js +11 -12
  140. package/admin/src/utils/renderInitials.d.ts +3 -0
  141. package/admin/src/utils/renderInitials.js +10 -5
  142. package/admin/src/utils/resolveCommentStatus.d.ts +4 -0
  143. package/admin/src/utils/resolveCommentStatus.js +17 -21
  144. package/admin/src/utils/resolveCommentStatusColor.d.ts +4 -0
  145. package/admin/src/utils/resolveCommentStatusColor.js +19 -19
  146. package/content-types/comment.d.ts +91 -0
  147. package/content-types/comment.js +87 -88
  148. package/content-types/index.d.ts +143 -0
  149. package/content-types/index.js +15 -10
  150. package/content-types/report.d.ts +48 -0
  151. package/content-types/report.js +44 -49
  152. package/package.json +24 -19
  153. package/permissions.d.ts +18 -0
  154. package/permissions.js +12 -13
  155. package/server/bootstrap.d.ts +4 -0
  156. package/server/bootstrap.js +56 -62
  157. package/server/config/index.d.ts +4 -0
  158. package/server/config/index.js +17 -15
  159. package/server/controllers/admin.d.ts +4 -0
  160. package/server/controllers/admin.js +134 -167
  161. package/server/controllers/client.d.ts +4 -0
  162. package/server/controllers/client.js +104 -112
  163. package/server/controllers/index.d.ts +6 -0
  164. package/server/controllers/index.js +12 -8
  165. package/server/controllers/utils/functions.d.ts +7 -0
  166. package/server/controllers/utils/functions.js +22 -17
  167. package/server/controllers/utils/parsers.d.ts +15 -0
  168. package/server/controllers/utils/parsers.js +17 -17
  169. package/server/destroy.d.ts +3 -0
  170. package/server/destroy.js +3 -4
  171. package/server/graphql/index.d.ts +4 -0
  172. package/server/graphql/index.js +27 -25
  173. package/server/graphql/mutations/createAbuseReport.d.ts +11 -0
  174. package/server/graphql/mutations/createAbuseReport.js +22 -24
  175. package/server/graphql/mutations/createComment.d.ts +14 -0
  176. package/server/graphql/mutations/createComment.js +22 -24
  177. package/server/graphql/mutations/index.d.ts +4 -0
  178. package/server/graphql/mutations/index.js +24 -19
  179. package/server/graphql/mutations/removeComment.d.ts +11 -0
  180. package/server/graphql/mutations/removeComment.js +22 -24
  181. package/server/graphql/mutations/updateComment.d.ts +11 -0
  182. package/server/graphql/mutations/updateComment.js +22 -24
  183. package/server/graphql/queries/findAllFlat.d.ts +19 -0
  184. package/server/graphql/queries/findAllFlat.js +31 -34
  185. package/server/graphql/queries/findAllInHierarchy.d.ts +18 -0
  186. package/server/graphql/queries/findAllInHierarchy.js +26 -30
  187. package/server/graphql/queries/index.d.ts +4 -0
  188. package/server/graphql/queries/index.js +20 -17
  189. package/server/graphql/resolvers-config.d.ts +23 -0
  190. package/server/graphql/resolvers-config.js +11 -11
  191. package/server/graphql/types/comment-author.d.ts +4 -0
  192. package/server/graphql/types/comment-author.js +10 -8
  193. package/server/graphql/types/comment-nested.d.ts +4 -0
  194. package/server/graphql/types/comment-nested.js +17 -15
  195. package/server/graphql/types/comment.d.ts +4 -0
  196. package/server/graphql/types/comment.js +16 -14
  197. package/server/graphql/types/create-comment-author.d.ts +4 -0
  198. package/server/graphql/types/create-comment-author.js +10 -8
  199. package/server/graphql/types/create-comment.d.ts +4 -0
  200. package/server/graphql/types/create-comment.js +10 -8
  201. package/server/graphql/types/create-report.d.ts +4 -0
  202. package/server/graphql/types/create-report.js +10 -8
  203. package/server/graphql/types/id.d.ts +4 -0
  204. package/server/graphql/types/id.js +24 -23
  205. package/server/graphql/types/identify-comment-author.d.ts +4 -0
  206. package/server/graphql/types/identify-comment-author.js +7 -5
  207. package/server/graphql/types/index.d.ts +4 -0
  208. package/server/graphql/types/index.js +36 -17
  209. package/server/graphql/types/remove-comment.d.ts +4 -0
  210. package/server/graphql/types/remove-comment.js +9 -7
  211. package/server/graphql/types/report-reason.d.ts +4 -0
  212. package/server/graphql/types/report-reason.js +10 -8
  213. package/server/graphql/types/report.d.ts +4 -0
  214. package/server/graphql/types/report.js +12 -10
  215. package/server/graphql/types/response-find-all.d.ts +4 -0
  216. package/server/graphql/types/response-find-all.js +8 -6
  217. package/server/graphql/types/response-meta.d.ts +4 -0
  218. package/server/graphql/types/response-meta.js +7 -5
  219. package/server/graphql/types/response-pagination.d.ts +4 -0
  220. package/server/graphql/types/response-pagination.js +12 -10
  221. package/server/graphql/types/update-comment.d.ts +4 -0
  222. package/server/graphql/types/update-comment.js +10 -8
  223. package/server/index.d.ts +26 -0
  224. package/server/index.js +24 -21
  225. package/server/register.d.ts +3 -0
  226. package/server/register.js +3 -4
  227. package/server/routes/admin.d.ts +4 -0
  228. package/server/routes/admin.js +103 -109
  229. package/server/routes/client.d.ts +4 -0
  230. package/server/routes/client.js +48 -46
  231. package/server/routes/index.d.ts +11 -0
  232. package/server/routes/index.js +18 -14
  233. package/server/services/admin.d.ts +5 -0
  234. package/server/services/admin.js +126 -158
  235. package/server/services/client.d.ts +5 -0
  236. package/server/services/client.js +135 -151
  237. package/server/services/common.d.ts +5 -0
  238. package/server/services/common.js +165 -194
  239. package/server/services/graphql.d.ts +5 -0
  240. package/server/services/graphql.js +117 -182
  241. package/server/services/index.d.ts +8 -0
  242. package/server/services/index.js +15 -12
  243. package/server/services/utils/functions.d.ts +13 -0
  244. package/server/services/utils/functions.js +100 -109
  245. package/server/utils/constants.d.ts +9 -0
  246. package/server/utils/constants.js +19 -23
  247. package/server/utils/error.d.ts +19 -0
  248. package/server/utils/error.js +23 -18
  249. package/server/utils/functions.d.ts +6 -0
  250. package/server/utils/functions.js +35 -18
  251. package/strapi-admin.d.ts +3 -0
  252. package/strapi-admin.js +8 -3
  253. package/strapi-server.d.ts +177 -0
  254. package/strapi-server.js +43 -46
  255. package/tsconfig.tsbuildinfo +1 -0
  256. package/types/contentTypes.d.ts +44 -0
  257. package/types/contentTypes.js +3 -0
  258. package/.husky/pre-commit +0 -4
  259. package/LICENSE.md +0 -7
  260. package/__mocks__/initSetup.js +0 -108
  261. package/jest.config.js +0 -7
  262. package/server/controllers/utils/__tests__/functions.test.js +0 -43
  263. package/server/controllers/utils/__tests__/parsers.test.js +0 -94
  264. package/server/services/__tests__/common.test.js +0 -399
  265. package/server/services/utils/__tests__/functions.test.js +0 -53
  266. package/server/utils/__tests__/functions.test.js +0 -17
@@ -1,38 +1,29 @@
1
- 'use strict';
2
-
3
- const { getPluginService, parseParams } = require('./../utils/functions');
4
- const { isEmpty, isNil, isNumber, parseInt } = require('lodash');
5
- const PluginError = require('./../utils/error');
6
- const {
7
- getModelUid,
8
- getRelatedGroups,
9
- filterOurResolvedReports,
10
- } = require('./utils/functions');
11
- const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
12
-
13
- /**
14
- * Comments Plugin - Moderation services
15
- */
16
-
17
- module.exports = ({ strapi }) => ({
18
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const functions_1 = require("./../utils/functions");
6
+ const lodash_1 = require("lodash");
7
+ const error_1 = __importDefault(require("./../utils/error"));
8
+ const functions_2 = require("./utils/functions");
9
+ const constants_1 = require("./../utils/constants");
10
+ module.exports = ({ strapi }) => ({
19
11
  getCommonService() {
20
- return getPluginService('common');
12
+ return (0, functions_1.getPluginService)("common");
21
13
  },
22
-
23
- // Config
24
14
  async config(viaSettingsPage = false) {
25
15
  const pluginStore = await this.getCommonService().getPluginStore();
26
- const config = await pluginStore.get({ key: 'config' });
16
+ const config = await pluginStore.get({
17
+ key: "config",
18
+ });
27
19
  const additionalConfiguration = {
28
- regex: Object.keys(REGEX).reduce((prev, curr) => ({
20
+ regex: Object.keys(constants_1.REGEX).reduce((prev, curr) => ({
29
21
  ...prev,
30
- [curr]: REGEX[curr].toString(),
22
+ [curr]: constants_1.REGEX[curr].toString(),
31
23
  }), {}),
32
24
  };
33
-
34
- const isGQLPluginEnabled = !isNil(strapi.plugin('graphql'));
35
-
25
+ const getConfigProp = (key) => this.getCommonService().getLocalConfig(key);
26
+ const isGQLPluginEnabled = !(0, lodash_1.isNil)(strapi.plugin("graphql"));
36
27
  if (config) {
37
28
  return {
38
29
  ...config,
@@ -40,20 +31,18 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
40
31
  isGQLPluginEnabled: viaSettingsPage ? isGQLPluginEnabled : undefined,
41
32
  };
42
33
  }
43
-
44
- const entryLabel = this.getCommonService().getLocalConfig('entryLabel');
45
- const approvalFlow = this.getCommonService().getLocalConfig('approvalFlow');
46
- const reportReasons = this.getCommonService().getLocalConfig('reportReasons');
34
+ const entryLabel = getConfigProp("entryLabel");
35
+ const approvalFlow = getConfigProp("approvalFlow");
36
+ const reportReasons = getConfigProp("reportReasons");
47
37
  const result = {
48
38
  entryLabel,
49
39
  approvalFlow,
50
40
  reportReasons,
51
41
  ...additionalConfiguration,
52
42
  };
53
-
54
43
  if (viaSettingsPage) {
55
- const enabledCollections = this.getCommonService().getLocalConfig('enabledCollections');
56
- const moderatorRoles = this.getCommonService().getLocalConfig('moderatorRoles');
44
+ const enabledCollections = getConfigProp("enabledCollections");
45
+ const moderatorRoles = getConfigProp("moderatorRoles");
57
46
  return {
58
47
  ...result,
59
48
  enabledCollections,
@@ -61,49 +50,36 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
61
50
  isGQLPluginEnabled,
62
51
  };
63
52
  }
64
-
65
53
  return result;
66
54
  },
67
-
68
55
  async updateConfig(body) {
69
56
  const pluginStore = await this.getCommonService().getPluginStore();
70
-
71
- await pluginStore.set({ key: 'config', value: body });
72
-
57
+ await pluginStore.set({ key: "config", value: body });
73
58
  return this.config();
74
- },
75
-
76
- async restoreConfig() {
59
+ },
60
+ async restoreConfig() {
77
61
  const pluginStore = await this.getCommonService().getPluginStore();
78
-
79
- await pluginStore.delete({key: 'config'})
80
-
62
+ await pluginStore.delete({ key: "config" });
81
63
  return this.config();
82
- },
83
-
64
+ },
84
65
  async restart() {
85
66
  setImmediate(() => strapi.reload());
86
67
  },
87
-
88
- // Find all comments
89
68
  async findAll({ related, entity, ...query }) {
90
- const { _q, orderBy, pageSize = 10, page = 1, filters, ...rest } = parseParams(query);
91
-
69
+ const { _q, orderBy, pageSize = 10, page = 1, filters, } = (0, functions_1.parseParams)(query);
92
70
  const defaultWhere = {
93
- $or: [
94
- { removed: false },
95
- { removed: null },
96
- ],
71
+ $or: [{ removed: false }, { removed: null }],
97
72
  };
98
-
99
73
  let params = {
100
- where: !isEmpty(filters) ? {
101
- ...defaultWhere,
102
- ...filters,
103
- } : { ...defaultWhere },
104
- offset: (page - 1)*pageSize,
74
+ where: !(0, lodash_1.isEmpty)(filters)
75
+ ? {
76
+ ...defaultWhere,
77
+ ...filters,
78
+ }
79
+ : { ...defaultWhere },
80
+ offset: (page - 1) * pageSize,
105
81
  limit: pageSize,
106
- orderBy: orderBy || [{ createdAt: 'desc' }],
82
+ orderBy: orderBy || [{ createdAt: "desc" }],
107
83
  };
108
84
  if (_q) {
109
85
  params = {
@@ -111,34 +87,32 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
111
87
  where: {
112
88
  ...params.where,
113
89
  content: {
114
- $contains: _q
90
+ $contains: _q,
115
91
  },
116
- }
92
+ },
117
93
  };
118
94
  }
119
-
120
- const entities = await strapi.db.query(getModelUid('comment'))
95
+ const entities = await strapi.db
96
+ .query((0, functions_2.getModelUid)("comment"))
121
97
  .findMany({
122
- ...params,
123
- populate: {
124
- authorUser: true,
125
- threadOf: true,
126
- reports: {
127
- where: {
128
- resolved: false
129
- },
98
+ ...params,
99
+ populate: {
100
+ authorUser: true,
101
+ threadOf: true,
102
+ reports: {
103
+ where: {
104
+ resolved: false,
130
105
  },
131
106
  },
132
- });
133
- const total = await strapi.db.query(getModelUid('comment'))
134
- .count({
135
- where: params.where,
136
- });
107
+ },
108
+ });
109
+ const total = await strapi.db.query((0, functions_2.getModelUid)("comment")).count({
110
+ where: params.where,
111
+ });
137
112
  const relatedEntities = await this.getCommonService().findRelatedEntitiesFor(entities);
138
113
  const result = entities
139
- .map(_ => filterOurResolvedReports(this.getCommonService().sanitizeCommentEntity(_)))
140
- .map(_ => this.getCommonService().mergeRelatedEntityTo(_, relatedEntities));
141
-
114
+ .map((_) => (0, functions_2.filterOurResolvedReports)(this.getCommonService().sanitizeCommentEntity(_)))
115
+ .map((_) => this.getCommonService().mergeRelatedEntityTo(_, relatedEntities));
142
116
  const pageCount = Math.floor(total / pageSize);
143
117
  return {
144
118
  result,
@@ -150,147 +124,141 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
150
124
  },
151
125
  };
152
126
  },
153
-
154
- // Find single comment
155
127
  async findOneAndThread(id, { removed, ...query }) {
156
- const defaultWhere = !removed ? {
157
- $or: [
158
- { removed: false },
159
- { removed: null },
160
- ],
161
- } : {};
162
-
128
+ const defaultWhere = !removed
129
+ ? {
130
+ $or: [{ removed: false }, { removed: null }],
131
+ }
132
+ : {};
163
133
  const reportsPopulation = {
164
134
  reports: {
165
- where: {
135
+ where: {
166
136
  resolved: false,
167
137
  },
168
- }
138
+ },
169
139
  };
170
-
171
140
  const defaultPopulate = {
172
141
  populate: {
173
142
  authorUser: true,
174
143
  threadOf: {
175
- populate: {
144
+ populate: {
176
145
  authorUser: true,
177
- ...reportsPopulation
146
+ ...reportsPopulation,
178
147
  },
179
148
  },
180
149
  ...reportsPopulation,
181
150
  },
182
- }
183
-
184
- const entity = await strapi.db.query(getModelUid('comment')).findOne({
151
+ };
152
+ const entity = await strapi.db
153
+ .query((0, functions_2.getModelUid)("comment"))
154
+ .findOne({
185
155
  where: {
186
156
  id,
187
157
  },
188
158
  ...defaultPopulate,
189
159
  });
190
-
191
- if (!entity){
192
- throw new PluginError(404, 'Not found');
160
+ if (!entity) {
161
+ throw new error_1.default(404, "Not found");
193
162
  }
194
-
195
- const [relatedUid, relatedStringId] = getRelatedGroups(entity.related);
196
- const parsedRelatedId = parseInt(relatedStringId);
197
- const relatedId = isNumber(parsedRelatedId) ? parsedRelatedId : relatedStringId;
198
- const relatedEntity = await strapi.db.query(relatedUid).findOne({
199
- where: { id: relatedId }
200
- }).then(_ => ({
163
+ const [relatedUid, relatedStringId] = (0, functions_2.getRelatedGroups)(entity.related);
164
+ const parsedRelatedId = (0, lodash_1.parseInt)(relatedStringId);
165
+ const relatedId = (0, lodash_1.isNumber)(parsedRelatedId)
166
+ ? parsedRelatedId
167
+ : relatedStringId;
168
+ const relatedEntity = await strapi.db
169
+ .query(relatedUid)
170
+ .findOne({
171
+ where: { id: relatedId },
172
+ })
173
+ .then((_) => ({
201
174
  ..._,
202
175
  uid: relatedUid,
203
176
  }));
204
-
205
177
  if (!relatedEntity) {
206
- throw new PluginError(404, 'Relation not found');
178
+ throw new error_1.default(404, "Relation not found");
207
179
  }
208
-
209
180
  const levelThreadId = entity?.threadOf?.id || null;
210
- const entitiesOnSameLevel = await this.getCommonService()
211
- .findAllInHierarchy({
212
- query: {
213
- ...defaultWhere,
214
- ...query,
215
- threadOf: levelThreadId,
216
- related: entity.related,
217
- },
218
- ...defaultPopulate,
219
- startingFromId: levelThreadId,
220
- isAdmin: true
221
- }, false);
181
+ const entitiesOnSameLevel = await this.getCommonService().findAllInHierarchy({
182
+ query: {
183
+ ...defaultWhere,
184
+ ...query,
185
+ threadOf: levelThreadId,
186
+ related: entity.related,
187
+ },
188
+ ...defaultPopulate,
189
+ startingFromId: levelThreadId,
190
+ isAdmin: true,
191
+ }, false);
222
192
  const selectedEntity = this.getCommonService().sanitizeCommentEntity({
223
193
  ...entity,
224
194
  threadOf: entity.threadOf || null,
225
195
  });
226
-
227
196
  return {
228
197
  entity: relatedEntity,
229
198
  selected: selectedEntity,
230
199
  level: entitiesOnSameLevel,
231
200
  };
232
201
  },
233
-
234
- // Block / Unblock a comment
235
202
  async blockComment(id, forceStatus) {
236
203
  const existingEntity = await this.getCommonService().findOne({ id });
237
- const changedEntity = await strapi.db.query(getModelUid('comment')).update({
204
+ const changedEntity = await strapi.db
205
+ .query((0, functions_2.getModelUid)("comment"))
206
+ .update({
238
207
  where: { id },
239
- data: { blocked: !isNil(forceStatus) ? forceStatus : !existingEntity.blocked }
208
+ data: {
209
+ blocked: !(0, lodash_1.isNil)(forceStatus) ? forceStatus : !existingEntity.blocked,
210
+ },
240
211
  });
241
212
  return this.getCommonService().sanitizeCommentEntity(changedEntity);
242
213
  },
243
-
244
- // Block / Unblock a comment thread
245
214
  async blockCommentThread(id, forceStatus) {
246
215
  const existingEntity = await this.getCommonService().findOne({ id });
247
- const status = !isNil(forceStatus) ? forceStatus : !existingEntity.blockedThread;
248
- const changedEntity = await strapi.db.query(getModelUid('comment')).update({
216
+ const status = !(0, lodash_1.isNil)(forceStatus)
217
+ ? forceStatus
218
+ : !existingEntity.blockedThread;
219
+ const changedEntity = await strapi.db
220
+ .query((0, functions_2.getModelUid)("comment"))
221
+ .update({
249
222
  where: { id },
250
- data: {
223
+ data: {
251
224
  blocked: status,
252
225
  blockedThread: status,
253
226
  },
254
227
  });
255
228
  await this.blockNestedThreads(id, changedEntity.blockedThread);
256
-
257
229
  return this.getCommonService().sanitizeCommentEntity(changedEntity);
258
230
  },
259
-
260
- // Approve comment
261
231
  async approveComment(id) {
262
- const changedEntity = await strapi.db.query(getModelUid('comment'))
263
- .update({
264
- where: { id },
265
- data: { approvalStatus: APPROVAL_STATUS.APPROVED }
266
- });
267
-
232
+ const changedEntity = await strapi.db
233
+ .query((0, functions_2.getModelUid)("comment"))
234
+ .update({
235
+ where: { id },
236
+ data: { approvalStatus: constants_1.APPROVAL_STATUS.APPROVED },
237
+ });
268
238
  return this.getCommonService().sanitizeCommentEntity(changedEntity);
269
239
  },
270
-
271
240
  async rejectComment(id) {
272
- const changedEntity = await strapi.db.query(getModelUid('comment'))
273
- .update({
274
- where: { id },
275
- data: { approvalStatus: APPROVAL_STATUS.REJECTED }
276
- });
277
-
241
+ const changedEntity = await strapi.db
242
+ .query((0, functions_2.getModelUid)("comment"))
243
+ .update({
244
+ where: { id },
245
+ data: { approvalStatus: constants_1.APPROVAL_STATUS.REJECTED },
246
+ });
278
247
  return this.getCommonService().sanitizeCommentEntity(changedEntity);
279
248
  },
280
-
281
249
  async blockNestedThreads(id, blockStatus) {
282
- return await this.getCommonService()
283
- .modifiedNestedNestedComments(id, 'blockedThread', blockStatus)
250
+ return await this.getCommonService().modifiedNestedNestedComments(id, "blockedThread", blockStatus);
284
251
  },
285
-
286
- // Resolve reported abuse for comment
287
252
  async resolveAbuseReport(id, commentId) {
288
- return strapi.db.query(getModelUid('comment-report')).update({
253
+ return strapi.db
254
+ .query((0, functions_2.getModelUid)("comment-report"))
255
+ .update({
289
256
  where: {
290
257
  id,
291
258
  related: commentId,
292
259
  },
293
- data: { resolved: true }
260
+ data: { resolved: true },
294
261
  });
295
- },
262
+ },
296
263
  });
264
+ //# sourceMappingURL=admin.js.map
@@ -0,0 +1,5 @@
1
+ import { StrapiContext } from "strapi-typed";
2
+ import { IServiceClient } from "../../types";
3
+ declare const _default: ({ strapi }: StrapiContext) => IServiceClient;
4
+ export = _default;
5
+ //# sourceMappingURL=client.d.ts.map