strapi-plugin-comments 2.0.10 → 2.1.0

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 (269) hide show
  1. package/README.md +204 -124
  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/Avatar/index.d.ts +12 -0
  5. package/admin/src/components/Avatar/index.js +26 -0
  6. package/admin/src/components/ConfirmationDialog/index.d.ts +26 -0
  7. package/admin/src/components/ConfirmationDialog/index.js +36 -55
  8. package/admin/src/components/DiscussionStatus/index.d.ts +9 -0
  9. package/admin/src/components/DiscussionStatus/index.js +22 -31
  10. package/admin/src/components/DiscussionThread/index.d.ts +16 -0
  11. package/admin/src/components/DiscussionThread/index.js +39 -56
  12. package/admin/src/components/DiscussionThreadItem/index.d.ts +9 -0
  13. package/admin/src/components/DiscussionThreadItem/index.js +28 -52
  14. package/admin/src/components/DiscussionThreadItem/styles.d.ts +4 -0
  15. package/admin/src/components/DiscussionThreadItem/styles.js +16 -11
  16. package/admin/src/components/DiscussionThreadItemActions/index.d.ts +19 -0
  17. package/admin/src/components/DiscussionThreadItemActions/index.js +121 -158
  18. package/admin/src/components/DiscussionThreadItemActions/styles.d.ts +2 -0
  19. package/admin/src/components/DiscussionThreadItemActions/styles.js +13 -7
  20. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.d.ts +17 -0
  21. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +38 -48
  22. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.d.ts +2 -0
  23. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +12 -6
  24. package/admin/src/components/DiscussionThreadItemFooter/index.d.ts +16 -0
  25. package/admin/src/components/DiscussionThreadItemFooter/index.js +34 -42
  26. package/admin/src/components/DiscussionThreadItemFooter/styles.d.ts +3 -0
  27. package/admin/src/components/DiscussionThreadItemFooter/styles.js +17 -12
  28. package/admin/src/components/DiscussionThreadItemReviewAction/index.d.ts +30 -0
  29. package/admin/src/components/DiscussionThreadItemReviewAction/index.js +77 -91
  30. package/admin/src/components/FormSwitch/index.d.ts +7 -0
  31. package/admin/src/components/FormSwitch/index.js +15 -18
  32. package/admin/src/components/FormSwitch/styles.d.ts +2 -0
  33. package/admin/src/components/FormSwitch/styles.js +14 -8
  34. package/admin/src/components/IconButton/styles.d.ts +2 -0
  35. package/admin/src/components/IconButton/styles.js +16 -9
  36. package/admin/src/components/Initializer/index.d.ts +5 -0
  37. package/admin/src/components/Initializer/index.js +12 -24
  38. package/admin/src/components/LoadingIndicatorOverlay/index.d.ts +3 -0
  39. package/admin/src/components/LoadingIndicatorOverlay/index.js +12 -15
  40. package/admin/src/components/LoadingIndicatorOverlay/styles.d.ts +3 -0
  41. package/admin/src/components/LoadingIndicatorOverlay/styles.js +22 -17
  42. package/admin/src/components/Nav/index.d.ts +7 -0
  43. package/admin/src/components/Nav/index.js +25 -48
  44. package/admin/src/components/PluginIcon/index.d.ts +3 -0
  45. package/admin/src/components/PluginIcon/index.js +10 -12
  46. package/admin/src/components/ReportsReviewModal/index.d.ts +21 -0
  47. package/admin/src/components/ReportsReviewModal/index.js +31 -46
  48. package/admin/src/components/ReportsReviewTable/index.d.ts +21 -0
  49. package/admin/src/components/ReportsReviewTable/index.js +120 -140
  50. package/admin/src/components/StatusBadge/index.d.ts +7 -0
  51. package/admin/src/components/StatusBadge/index.js +12 -17
  52. package/admin/src/components/StatusBadge/styles.d.ts +2 -0
  53. package/admin/src/components/StatusBadge/styles.js +19 -13
  54. package/admin/src/components/TableFilters/index.d.ts +10 -0
  55. package/admin/src/components/TableFilters/index.js +52 -49
  56. package/admin/src/components/TablePagination/index.d.ts +17 -0
  57. package/admin/src/components/TablePagination/index.js +27 -29
  58. package/admin/src/components/icons/comments.d.ts +6 -0
  59. package/admin/src/components/icons/comments.js +11 -8
  60. package/admin/src/components/icons/index.d.ts +6 -0
  61. package/admin/src/components/icons/index.js +15 -6
  62. package/admin/src/components/icons/lock.d.ts +7 -0
  63. package/admin/src/components/icons/lock.js +11 -21
  64. package/admin/src/components/icons/review.d.ts +7 -0
  65. package/admin/src/components/icons/review.js +11 -17
  66. package/admin/src/components/icons/unlock.d.ts +7 -0
  67. package/admin/src/components/icons/unlock.js +11 -19
  68. package/admin/src/hooks/useConfig.d.ts +8 -0
  69. package/admin/src/hooks/useConfig.js +40 -45
  70. package/admin/src/index.d.ts +7 -0
  71. package/admin/src/index.js +98 -92
  72. package/admin/src/pages/App/index.d.ts +4 -0
  73. package/admin/src/pages/App/index.js +43 -67
  74. package/admin/src/pages/App/reducer/actions.d.ts +8 -0
  75. package/admin/src/pages/App/reducer/actions.js +11 -7
  76. package/admin/src/pages/App/reducer/constants.d.ts +4 -0
  77. package/admin/src/pages/App/reducer/constants.js +7 -4
  78. package/admin/src/pages/App/reducer/index.d.ts +9 -0
  79. package/admin/src/pages/App/reducer/index.js +24 -22
  80. package/admin/src/pages/App/reducer/init.d.ts +3 -0
  81. package/admin/src/pages/App/reducer/init.js +6 -4
  82. package/admin/src/pages/App/reducer/selectors.d.ts +6 -0
  83. package/admin/src/pages/App/reducer/selectors.js +17 -34
  84. package/admin/src/pages/App/utils/api.d.ts +2 -0
  85. package/admin/src/pages/App/utils/api.js +14 -11
  86. package/admin/src/pages/ComingSoonPage/index.d.ts +3 -0
  87. package/admin/src/pages/ComingSoonPage/index.js +42 -24
  88. package/admin/src/pages/Details/components/DetailsEntity/index.d.ts +18 -0
  89. package/admin/src/pages/Details/components/DetailsEntity/index.js +49 -77
  90. package/admin/src/pages/Details/components/DetailsFilters/index.d.ts +12 -0
  91. package/admin/src/pages/Details/components/DetailsFilters/index.js +19 -26
  92. package/admin/src/pages/Details/components/DetailsFilters/styles.d.ts +2 -0
  93. package/admin/src/pages/Details/components/DetailsFilters/styles.js +14 -8
  94. package/admin/src/pages/Details/index.d.ts +4 -0
  95. package/admin/src/pages/Details/index.js +94 -133
  96. package/admin/src/pages/Discover/components/DiscoverTableRow/index.d.ts +20 -0
  97. package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +128 -139
  98. package/admin/src/pages/Discover/components/DiscoverTableRow/styles.d.ts +2 -0
  99. package/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +14 -8
  100. package/admin/src/pages/Discover/index.d.ts +4 -0
  101. package/admin/src/pages/Discover/index.js +129 -170
  102. package/admin/src/pages/Discover/utils/api.d.ts +2 -0
  103. package/admin/src/pages/Discover/utils/api.js +15 -13
  104. package/admin/src/pages/Discover/utils/filtersSchema.d.ts +11 -0
  105. package/admin/src/pages/Discover/utils/filtersSchema.js +8 -6
  106. package/admin/src/pages/Settings/components/RestartAlert/styles.d.ts +2 -0
  107. package/admin/src/pages/Settings/components/RestartAlert/styles.js +14 -8
  108. package/admin/src/pages/Settings/index.d.ts +3 -0
  109. package/admin/src/pages/Settings/index.js +225 -391
  110. package/admin/src/pages/Settings/utils/api.d.ts +7 -0
  111. package/admin/src/pages/Settings/utils/api.js +60 -55
  112. package/admin/src/pages/utils/api.d.ts +12 -0
  113. package/admin/src/pages/utils/api.js +58 -53
  114. package/admin/src/permissions.d.ts +28 -0
  115. package/admin/src/permissions.js +31 -17
  116. package/admin/src/pluginId.d.ts +2 -0
  117. package/admin/src/pluginId.js +29 -5
  118. package/admin/src/reducers.d.ts +7 -0
  119. package/admin/src/reducers.js +10 -6
  120. package/admin/src/translations/en.json +131 -131
  121. package/admin/src/translations/fr.json +132 -1
  122. package/admin/src/translations/pt-BR.json +130 -130
  123. package/admin/src/utils/axiosInstance.d.ts +3 -0
  124. package/admin/src/utils/axiosInstance.js +21 -27
  125. package/admin/src/utils/constants.d.ts +25 -0
  126. package/admin/src/utils/constants.js +23 -22
  127. package/admin/src/utils/getApiUrl.d.ts +3 -0
  128. package/admin/src/utils/getApiUrl.js +6 -5
  129. package/admin/src/utils/getMessage.d.ts +4 -0
  130. package/admin/src/utils/getMessage.js +15 -15
  131. package/admin/src/utils/getRelatedGroups.d.ts +4 -0
  132. package/admin/src/utils/getRelatedGroups.js +5 -3
  133. package/admin/src/utils/getUrl.d.ts +3 -0
  134. package/admin/src/utils/getUrl.js +6 -5
  135. package/admin/src/utils/handleAPIError.d.ts +4 -0
  136. package/admin/src/utils/handleAPIError.js +12 -11
  137. package/admin/src/utils/index.d.ts +12 -0
  138. package/admin/src/utils/index.js +29 -11
  139. package/admin/src/utils/parseRegExp.d.ts +6 -0
  140. package/admin/src/utils/parseRegExp.js +6 -5
  141. package/admin/src/utils/renderEntryTitle.d.ts +4 -0
  142. package/admin/src/utils/renderEntryTitle.js +11 -12
  143. package/admin/src/utils/renderInitials.d.ts +3 -0
  144. package/admin/src/utils/renderInitials.js +10 -5
  145. package/admin/src/utils/resolveCommentStatus.d.ts +4 -0
  146. package/admin/src/utils/resolveCommentStatus.js +17 -21
  147. package/admin/src/utils/resolveCommentStatusColor.d.ts +4 -0
  148. package/admin/src/utils/resolveCommentStatusColor.js +19 -19
  149. package/content-types/comment.d.ts +91 -0
  150. package/content-types/comment.js +87 -88
  151. package/content-types/index.d.ts +143 -0
  152. package/content-types/index.js +15 -10
  153. package/content-types/report.d.ts +48 -0
  154. package/content-types/report.js +44 -49
  155. package/package.json +24 -19
  156. package/permissions.d.ts +18 -0
  157. package/permissions.js +12 -13
  158. package/server/bootstrap.d.ts +4 -0
  159. package/server/bootstrap.js +56 -62
  160. package/server/config/index.d.ts +4 -0
  161. package/server/config/index.js +17 -15
  162. package/server/controllers/admin.d.ts +4 -0
  163. package/server/controllers/admin.js +134 -167
  164. package/server/controllers/client.d.ts +4 -0
  165. package/server/controllers/client.js +120 -112
  166. package/server/controllers/index.d.ts +6 -0
  167. package/server/controllers/index.js +12 -8
  168. package/server/controllers/utils/functions.d.ts +7 -0
  169. package/server/controllers/utils/functions.js +22 -17
  170. package/server/controllers/utils/parsers.d.ts +10 -0
  171. package/server/controllers/utils/parsers.js +47 -19
  172. package/server/destroy.d.ts +3 -0
  173. package/server/destroy.js +3 -4
  174. package/server/graphql/index.d.ts +4 -0
  175. package/server/graphql/index.js +27 -25
  176. package/server/graphql/mutations/createAbuseReport.d.ts +11 -0
  177. package/server/graphql/mutations/createAbuseReport.js +22 -24
  178. package/server/graphql/mutations/createComment.d.ts +14 -0
  179. package/server/graphql/mutations/createComment.js +22 -24
  180. package/server/graphql/mutations/index.d.ts +4 -0
  181. package/server/graphql/mutations/index.js +24 -19
  182. package/server/graphql/mutations/removeComment.d.ts +11 -0
  183. package/server/graphql/mutations/removeComment.js +22 -24
  184. package/server/graphql/mutations/updateComment.d.ts +11 -0
  185. package/server/graphql/mutations/updateComment.js +22 -24
  186. package/server/graphql/queries/findAllFlat.d.ts +19 -0
  187. package/server/graphql/queries/findAllFlat.js +36 -34
  188. package/server/graphql/queries/findAllInHierarchy.d.ts +17 -0
  189. package/server/graphql/queries/findAllInHierarchy.js +30 -30
  190. package/server/graphql/queries/index.d.ts +4 -0
  191. package/server/graphql/queries/index.js +20 -17
  192. package/server/graphql/resolvers-config.d.ts +23 -0
  193. package/server/graphql/resolvers-config.js +11 -11
  194. package/server/graphql/types/comment-author.d.ts +4 -0
  195. package/server/graphql/types/comment-author.js +10 -8
  196. package/server/graphql/types/comment-nested.d.ts +4 -0
  197. package/server/graphql/types/comment-nested.js +17 -15
  198. package/server/graphql/types/comment.d.ts +4 -0
  199. package/server/graphql/types/comment.js +16 -14
  200. package/server/graphql/types/create-comment-author.d.ts +4 -0
  201. package/server/graphql/types/create-comment-author.js +10 -8
  202. package/server/graphql/types/create-comment.d.ts +4 -0
  203. package/server/graphql/types/create-comment.js +10 -8
  204. package/server/graphql/types/create-report.d.ts +4 -0
  205. package/server/graphql/types/create-report.js +10 -8
  206. package/server/graphql/types/id.d.ts +4 -0
  207. package/server/graphql/types/id.js +24 -23
  208. package/server/graphql/types/identify-comment-author.d.ts +4 -0
  209. package/server/graphql/types/identify-comment-author.js +7 -5
  210. package/server/graphql/types/index.d.ts +4 -0
  211. package/server/graphql/types/index.js +36 -17
  212. package/server/graphql/types/remove-comment.d.ts +4 -0
  213. package/server/graphql/types/remove-comment.js +9 -7
  214. package/server/graphql/types/report-reason.d.ts +4 -0
  215. package/server/graphql/types/report-reason.js +10 -8
  216. package/server/graphql/types/report.d.ts +4 -0
  217. package/server/graphql/types/report.js +12 -10
  218. package/server/graphql/types/response-find-all.d.ts +4 -0
  219. package/server/graphql/types/response-find-all.js +8 -6
  220. package/server/graphql/types/response-meta.d.ts +4 -0
  221. package/server/graphql/types/response-meta.js +7 -5
  222. package/server/graphql/types/response-pagination.d.ts +4 -0
  223. package/server/graphql/types/response-pagination.js +12 -10
  224. package/server/graphql/types/update-comment.d.ts +4 -0
  225. package/server/graphql/types/update-comment.js +10 -8
  226. package/server/index.d.ts +26 -0
  227. package/server/index.js +24 -21
  228. package/server/register.d.ts +3 -0
  229. package/server/register.js +3 -4
  230. package/server/routes/admin.d.ts +4 -0
  231. package/server/routes/admin.js +103 -109
  232. package/server/routes/client.d.ts +4 -0
  233. package/server/routes/client.js +84 -46
  234. package/server/routes/index.d.ts +11 -0
  235. package/server/routes/index.js +18 -14
  236. package/server/services/admin.d.ts +5 -0
  237. package/server/services/admin.js +134 -161
  238. package/server/services/client.d.ts +5 -0
  239. package/server/services/client.js +164 -168
  240. package/server/services/common.d.ts +5 -0
  241. package/server/services/common.js +192 -202
  242. package/server/services/graphql.d.ts +5 -0
  243. package/server/services/graphql.js +117 -182
  244. package/server/services/index.d.ts +8 -0
  245. package/server/services/index.js +15 -12
  246. package/server/services/utils/functions.d.ts +13 -0
  247. package/server/services/utils/functions.js +105 -109
  248. package/server/utils/constants.d.ts +9 -0
  249. package/server/utils/constants.js +19 -23
  250. package/server/utils/error.d.ts +19 -0
  251. package/server/utils/error.js +23 -18
  252. package/server/utils/functions.d.ts +6 -0
  253. package/server/utils/functions.js +35 -18
  254. package/strapi-admin.d.ts +3 -0
  255. package/strapi-admin.js +8 -3
  256. package/strapi-server.d.ts +177 -0
  257. package/strapi-server.js +43 -46
  258. package/tsconfig.tsbuildinfo +1 -0
  259. package/types/contentTypes.d.ts +48 -0
  260. package/types/contentTypes.js +3 -0
  261. package/.husky/pre-commit +0 -4
  262. package/LICENSE.md +0 -7
  263. package/__mocks__/initSetup.js +0 -108
  264. package/jest.config.js +0 -7
  265. package/server/controllers/utils/__tests__/functions.test.js +0 -43
  266. package/server/controllers/utils/__tests__/parsers.test.js +0 -94
  267. package/server/services/__tests__/common.test.js +0 -399
  268. package/server/services/utils/__tests__/functions.test.js +0 -53
  269. package/server/utils/__tests__/functions.test.js +0 -17
@@ -1,168 +1,135 @@
1
- 'use strict';
2
-
3
- const { getPluginService } = require('./../utils/functions');
4
- const { parseParams, throwError } = require('./utils/functions');
5
- const _ = require('lodash');
6
-
7
- module.exports = {
8
-
9
- getService(name = 'admin') {
10
- return getPluginService(name);
11
- },
12
-
13
- async config(ctx) {
14
- try {
15
- return await this.getService().config();
16
- } catch (e) {
17
- throwError(ctx, e);
18
- }
19
- },
20
-
21
- async settingsConfig(ctx) {
22
- try {
23
- return this.getService().config(true);
24
- } catch (e) {
25
- throwError(ctx, e);
26
- }
27
- },
28
-
29
- async settingsUpdateConfig(ctx) {
30
- try {
31
- const { request: { body } } = ctx;
32
- return this.getService().updateConfig(body);
33
- } catch (e) {
34
- throwError(ctx, e);
35
- }
36
- },
37
-
38
- async settingsRestoreConfig(ctx) {
39
- try {
40
- return this.getService().restoreConfig();
41
- } catch (e) {
42
- throwError(ctx, e);
43
- }
44
- },
45
-
46
- async settingsRestart(ctx) {
47
- try {
48
- await this.getService().restart();
49
- return ctx.send({ status: 200 });
50
- } catch (e) {
51
- throwError(ctx, e);
52
- }
53
- },
54
-
55
- async findAll(ctx) {
56
- return this.getService()
57
- .findAll(ctx.query);
58
- },
59
-
60
- async findOne(ctx) {
61
- const { params = {}, query } = ctx;
62
- const { id } = parseParams(params);
63
- try {
64
- return await this.getService()
65
- .findOneAndThread(id, query);
66
- } catch (e) {
67
- throwError(ctx, e);
68
- }
69
- },
70
-
71
- async blockComment(ctx) {
72
- const { params = {} } = ctx;
73
- const { id } = parseParams(params);
74
- try {
75
- return await this.getService()
76
- .blockComment(id, true);
77
- } catch (e) {
78
- throwError(ctx, e);
79
- }
80
- },
81
-
82
- async unblockComment(ctx) {
83
- const { params = {} } = ctx;
84
- const { id } = parseParams(params);
85
- try {
86
- return await this.getService()
87
- .blockComment(id, false);
88
- } catch (e) {
89
- throwError(ctx, e);
90
- }
91
- },
92
-
93
- async blockCommentThread(ctx) {
94
- const { params = {} } = ctx;
95
- const { id } = parseParams(params);
96
- try {
97
- return await this.getService()
98
- .blockCommentThread(id, true);
99
- } catch (e) {
100
- throwError(ctx, e);
101
- }
102
- },
103
-
104
- async unblockCommentThread(ctx) {
105
- const { params = {} } = ctx;
106
- const { id } = parseParams(params);
107
- try {
108
- return await this.getService()
109
- .blockCommentThread(id, false);
110
- } catch (e) {
111
- throwError(ctx, e);
112
- }
113
- },
114
-
115
- async resolveAbuseReport(ctx) {
116
- const { params = {} } = ctx;
117
- const { id: commentId, reportId } = parseParams(params);
118
- try {
119
- return await this.getService()
120
- .resolveAbuseReport(reportId, commentId);
121
- } catch (e) {
122
- throwError(ctx, e);
123
- }
124
- },
125
-
126
- async approveComment(ctx) {
127
- const { id } = parseParams(ctx.params || {});
128
- try {
129
- return await this.getService()
130
- .approveComment(id);
131
- } catch (e) {
132
- throwError(ctx, e);
133
- }
134
- },
135
-
136
- async rejectComment(ctx) {
137
- const { id } = parseParams(ctx.params || {});
138
- try {
139
- return await this.getService()
140
- .rejectComment(id);
141
- } catch (e) {
142
- throwError(ctx, e);
143
- }
144
- },
145
-
146
- getContentsTypes() {
147
- return Object.entries(strapi.contentTypes)
148
- .filter(([, contentType]) => (
149
- contentType.associations || []).some(_ => _.plugin === 'comments' && _.collection === 'comment'),
150
- )
151
- .reduce((acc, [, contentType]) => [
152
- ...acc,
153
- { key: contentType.globalName, value: contentType.collectionName }],
154
- [],
155
- );
156
- },
157
-
158
- async contentTypeName(ctx) {
159
- const { params: { contentTypeName } } = ctx;
160
- try {
161
- const result = await this.getService()
162
- .contentTypeName(contentTypeName);
163
- return { list: result };
164
- } catch (e) {
165
- throwError(ctx, e);
166
- }
167
- },
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const functions_1 = require("./../utils/functions");
4
+ const functions_2 = require("./utils/functions");
5
+ const controllers = {
6
+ getService(name = "admin") {
7
+ return (0, functions_1.getPluginService)(name);
8
+ },
9
+ async config(ctx) {
10
+ try {
11
+ return await this.getService().config();
12
+ }
13
+ catch (e) {
14
+ throw (0, functions_2.throwError)(ctx, e);
15
+ }
16
+ },
17
+ async settingsConfig(ctx) {
18
+ try {
19
+ return this.getService().config(true);
20
+ }
21
+ catch (e) {
22
+ throw (0, functions_2.throwError)(ctx, e);
23
+ }
24
+ },
25
+ async settingsUpdateConfig(ctx) {
26
+ try {
27
+ const { request: { body }, } = ctx;
28
+ (0, functions_1.assertNotEmpty)(body);
29
+ return this.getService().updateConfig(body);
30
+ }
31
+ catch (e) {
32
+ throw (0, functions_2.throwError)(ctx, e);
33
+ }
34
+ },
35
+ async settingsRestoreConfig(ctx) {
36
+ try {
37
+ return this.getService().restoreConfig();
38
+ }
39
+ catch (e) {
40
+ throw (0, functions_2.throwError)(ctx, e);
41
+ }
42
+ },
43
+ async settingsRestart(ctx) {
44
+ try {
45
+ await this.getService().restart();
46
+ return ctx.send({ status: 200 });
47
+ }
48
+ catch (e) {
49
+ throw (0, functions_2.throwError)(ctx, e);
50
+ }
51
+ },
52
+ async findAll(ctx) {
53
+ return this.getService().findAll(ctx.query);
54
+ },
55
+ async findOne(ctx) {
56
+ const { params = {}, query } = ctx;
57
+ const { id } = (0, functions_2.parseParams)(params);
58
+ try {
59
+ return await this.getService().findOneAndThread(id, query);
60
+ }
61
+ catch (e) {
62
+ throw (0, functions_2.throwError)(ctx, e);
63
+ }
64
+ },
65
+ async blockComment(ctx) {
66
+ const { params = {} } = ctx;
67
+ const { id } = (0, functions_2.parseParams)(params);
68
+ try {
69
+ return await this.getService().blockComment(id, true);
70
+ }
71
+ catch (e) {
72
+ throw (0, functions_2.throwError)(ctx, e);
73
+ }
74
+ },
75
+ async unblockComment(ctx) {
76
+ const { params = {} } = ctx;
77
+ const { id } = (0, functions_2.parseParams)(params);
78
+ try {
79
+ return await this.getService().blockComment(id, false);
80
+ }
81
+ catch (e) {
82
+ throw (0, functions_2.throwError)(ctx, e);
83
+ }
84
+ },
85
+ async blockCommentThread(ctx) {
86
+ const { params = {} } = ctx;
87
+ const { id } = (0, functions_2.parseParams)(params);
88
+ try {
89
+ return await this.getService().blockCommentThread(id, true);
90
+ }
91
+ catch (e) {
92
+ throw (0, functions_2.throwError)(ctx, e);
93
+ }
94
+ },
95
+ async unblockCommentThread(ctx) {
96
+ const { params = {} } = ctx;
97
+ const { id } = (0, functions_2.parseParams)(params);
98
+ try {
99
+ return await this.getService().blockCommentThread(id, false);
100
+ }
101
+ catch (e) {
102
+ throw (0, functions_2.throwError)(ctx, e);
103
+ }
104
+ },
105
+ async resolveAbuseReport(ctx) {
106
+ const { params = {} } = ctx;
107
+ const { id: commentId, reportId } = (0, functions_2.parseParams)(params);
108
+ try {
109
+ return await this.getService().resolveAbuseReport(reportId, commentId);
110
+ }
111
+ catch (e) {
112
+ throw (0, functions_2.throwError)(ctx, e);
113
+ }
114
+ },
115
+ async approveComment(ctx) {
116
+ const { id } = (0, functions_2.parseParams)(ctx.params || {});
117
+ try {
118
+ return await this.getService().approveComment(id);
119
+ }
120
+ catch (e) {
121
+ throw (0, functions_2.throwError)(ctx, e);
122
+ }
123
+ },
124
+ async rejectComment(ctx) {
125
+ const { id } = (0, functions_2.parseParams)(ctx.params || {});
126
+ try {
127
+ return await this.getService().rejectComment(id);
128
+ }
129
+ catch (e) {
130
+ throw (0, functions_2.throwError)(ctx, e);
131
+ }
132
+ },
168
133
  };
134
+ exports.default = controllers;
135
+ //# sourceMappingURL=admin.js.map
@@ -0,0 +1,4 @@
1
+ import { IControllerClient } from "../../types";
2
+ declare const controllers: IControllerClient;
3
+ export default controllers;
4
+ //# sourceMappingURL=client.d.ts.map
@@ -1,114 +1,122 @@
1
- 'use strict';
2
-
3
- const { getPluginService } = require('./../utils/functions');
4
- const { parseParams, throwError } = require('./utils/functions');
5
- const { flatInput } = require('./utils/parsers');
6
-
7
- module.exports = {
8
-
9
- getService(name = 'client') {
10
- return getPluginService(name);
11
- },
12
-
13
- async findAllFlat(ctx) {
14
- const { params = {}, query, sort, pagination } = ctx;
15
- const { relation } = parseParams(params);
16
-
17
- const { sort: querySort, pagination: queryPagination, ...filterQuery } = query || {};
18
-
19
- try {
20
- return this.getService('common')
21
- .findAllFlat(flatInput(relation, filterQuery, sort || querySort, pagination || queryPagination));
22
- } catch (e) {
23
- throwError(ctx, e);
24
- }
25
- },
26
-
27
- async findAllInHierarchy(ctx) {
28
- const { params = {}, query, sort } = ctx;
29
- const { relation } = parseParams(params);
30
-
31
- const { sort: querySort, ...filterQuery } = query || {};
32
-
33
- try {
34
- return await this.getService('common')
35
- .findAllInHierarchy({
36
- ...flatInput(relation, filterQuery, sort || querySort),
37
- dropBlockedThreads: true,
38
- });
39
- } catch (e) {
40
- throwError(ctx, e);
41
- }
42
- },
43
-
44
- async post(ctx) {
45
- const { request, params = {}, state = {} } = ctx;
46
- const { relation } = parseParams(params);
47
- const { user } = state;
48
- const { body = {} } = request;
49
- try {
50
- const entity = await this.getService()
51
- .create(relation, body, user);
52
-
53
- if (entity) {
54
- return entity;
55
- }
56
- } catch (e) {
57
- throwError(ctx, e);
58
- }
59
- },
60
-
61
- async put(ctx) {
62
- const { request, state, params = {} } = ctx;
63
- const { body = {} } = request;
64
- const { user } = state;
65
- const { commentId, relation } = parseParams(params);
66
- try {
67
- return await this.getService()
68
- .update(commentId, relation, body, user);
69
- } catch (e) {
70
- throwError(ctx, e);
71
- }
72
- },
73
-
74
- async reportAbuse(ctx) {
75
- const { request, state, params = {} } = ctx;
76
- const { body = {} } = request;
77
- if (!body.content) {
78
- return ctx.badRequest(null, 'Content field is required');
79
- }
80
- const { user } = state;
81
- const { relation, commentId } = parseParams(params);
82
- try {
83
- return await this.getService()
84
- .reportAbuse(commentId, relation, body, user);
85
- } catch (e) {
86
- throwError(ctx, e);
87
- }
88
- },
89
-
90
- async removeComment(ctx) {
91
- const {
92
- params: { relationId, commentId },
93
- query: { authorId },
94
- state: { user },
95
- } = ctx;
96
- if (authorId || user?.id) {
97
- try {
98
- return await this.getService()
99
- .markAsRemoved(
100
- commentId,
101
- relationId,
102
- authorId,
103
- user
104
- );
105
- } catch (e) {
106
- if (!e.isBoom) {
107
- throwError(ctx, e);
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 functions_1 = require("./../utils/functions");
7
+ const functions_2 = require("./utils/functions");
8
+ const parsers_1 = require("./utils/parsers");
9
+ const error_1 = __importDefault(require("../utils/error"));
10
+ const controllers = {
11
+ getService(name = "client") {
12
+ return (0, functions_1.getPluginService)(name);
13
+ },
14
+ async findAllFlat(ctx) {
15
+ const { params = {}, query, sort, pagination } = ctx;
16
+ const { relation } = (0, functions_2.parseParams)(params);
17
+ const { sort: querySort, pagination: queryPagination, fields, ...filterQuery } = query || {};
18
+ try {
19
+ (0, functions_1.assertParamsPresent)(params, ["relation"]);
20
+ return this.getService("common").findAllFlat((0, parsers_1.flatInput)({
21
+ relation,
22
+ query: filterQuery,
23
+ sort: sort || querySort,
24
+ pagination: pagination || queryPagination,
25
+ fields,
26
+ }));
27
+ }
28
+ catch (e) {
29
+ throw (0, functions_2.throwError)(ctx, e);
30
+ }
31
+ },
32
+ async findAllInHierarchy(ctx) {
33
+ const { params, query, sort } = ctx;
34
+ const { relation } = (0, functions_2.parseParams)(params);
35
+ const { sort: querySort, fields, ...filterQuery } = query || {};
36
+ try {
37
+ (0, functions_1.assertParamsPresent)(params, ["relation"]);
38
+ return await this.getService("common").findAllInHierarchy({
39
+ ...(0, parsers_1.flatInput)({
40
+ relation,
41
+ query: filterQuery,
42
+ sort: sort || querySort,
43
+ fields,
44
+ }),
45
+ dropBlockedThreads: true,
46
+ });
47
+ }
48
+ catch (e) {
49
+ throw (0, functions_2.throwError)(ctx, e);
50
+ }
51
+ },
52
+ async post(ctx) {
53
+ const { request, params, state = {} } = ctx;
54
+ const { relation } = (0, functions_2.parseParams)(params);
55
+ const { user } = state;
56
+ const { body } = request;
57
+ try {
58
+ (0, functions_1.assertParamsPresent)(params, ["relation"]);
59
+ (0, functions_1.assertNotEmpty)(body);
60
+ const entity = await this.getService().create(relation, body, user);
61
+ if (entity) {
62
+ return entity;
63
+ }
64
+ throw new error_1.default(400, "Comment hasn't been created");
65
+ }
66
+ catch (e) {
67
+ throw (0, functions_2.throwError)(ctx, e);
68
+ }
69
+ },
70
+ async put(ctx) {
71
+ const { request, state, params = {} } = ctx;
72
+ const { body } = request;
73
+ const { user } = state;
74
+ const { commentId, relation } = (0, functions_2.parseParams)(params);
75
+ try {
76
+ (0, functions_1.assertParamsPresent)(params, ["commentId", "relation"]);
77
+ (0, functions_1.assertNotEmpty)(body);
78
+ return await this.getService().update(commentId, relation, body, user);
79
+ }
80
+ catch (e) {
81
+ throw (0, functions_2.throwError)(ctx, e);
82
+ }
83
+ },
84
+ async reportAbuse(ctx) {
85
+ const { request, state, params = {} } = ctx;
86
+ const { body } = request;
87
+ const { user } = state;
88
+ const { relation, commentId } = (0, functions_2.parseParams)(params);
89
+ try {
90
+ (0, functions_1.assertParamsPresent)(params, ["commentId", "relation"]);
91
+ (0, functions_1.assertNotEmpty)(body);
92
+ if (!body.content) {
93
+ throw new error_1.default(400, "Content field is required");
94
+ }
95
+ return await this.getService().reportAbuse(commentId, relation, body, user);
96
+ }
97
+ catch (e) {
98
+ throw (0, functions_2.throwError)(ctx, e);
99
+ }
100
+ },
101
+ async removeComment(ctx) {
102
+ const { params, query, state: { user }, } = ctx;
103
+ const { relation, commentId } = (0, functions_2.parseParams)(params);
104
+ const { authorId } = (0, functions_2.parseParams)(query);
105
+ try {
106
+ (0, functions_1.assertParamsPresent)(params, ["commentId", "relation"]);
107
+ (0, functions_1.assertParamsPresent)(query, ["authorId"]);
108
+ if (authorId || user?.id) {
109
+ return await this.getService().markAsRemoved(commentId, relation, authorId, user);
110
+ }
111
+ return new error_1.default(400, "Not provided authorId");
112
+ }
113
+ catch (e) {
114
+ if (!e.isBoom) {
115
+ (0, functions_2.throwError)(ctx, e);
116
+ }
117
+ throw e;
108
118
  }
109
- throw e;
110
- }
111
- }
112
- return ctx.badRequest('Not provided authorId');
113
- },
119
+ },
114
120
  };
121
+ exports.default = controllers;
122
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,6 @@
1
+ declare type PluginControllers = {
2
+ [key: string]: Function | Object;
3
+ };
4
+ declare const controllers: PluginControllers;
5
+ export default controllers;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,13 @@
1
- 'use strict';
2
-
3
- const adminController = require('./admin');
4
- const clientController = require('./client');
5
-
6
- module.exports = {
7
- admin: adminController,
8
- client: clientController,
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
4
  };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const admin_1 = __importDefault(require("./admin"));
7
+ const client_1 = __importDefault(require("./client"));
8
+ const controllers = {
9
+ admin: admin_1.default,
10
+ client: client_1.default,
11
+ };
12
+ exports.default = controllers;
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ import { Id, StringMap, StrapiRequestContext } from "strapi-typed";
2
+ import PluginError from "../../utils/error";
3
+ declare type ParseResponse = StringMap<string | number | Id>;
4
+ export declare const parseParams: <T extends ParseResponse>(params: StringMap<string | number>) => T;
5
+ export declare const throwError: <T extends {} = never>(ctx: StrapiRequestContext<T, StringMap<string | number>, StringMap<string | number>>, e: PluginError | Error | unknown) => PluginError | Error | unknown | never;
6
+ export {};
7
+ //# sourceMappingURL=functions.d.ts.map
@@ -1,19 +1,24 @@
1
- const PluginError = require('./../../utils/error');
2
-
3
- module.exports = {
4
- parseParams: params => Object.keys(params).reduce((prev, curr) => {
5
- const value = params[curr];
6
- const parsedValue = Number(value);
7
- return {
8
- ...prev,
9
- [curr]: isNaN(parsedValue) ? value : parsedValue
10
- };
11
- }, {}),
12
-
13
- throwError: (ctx, e) => {
14
- if (e instanceof PluginError){
15
- return ctx.throw(e.status, JSON.stringify(e));
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.throwError = exports.parseParams = void 0;
7
+ const error_1 = __importDefault(require("../../utils/error"));
8
+ const parseParams = (params) => Object.keys(params).reduce((prev, curr) => {
9
+ const value = params[curr];
10
+ const parsedValue = Number(value);
11
+ return {
12
+ ...prev,
13
+ [curr]: isNaN(parsedValue) ? value : parsedValue,
14
+ };
15
+ }, {});
16
+ exports.parseParams = parseParams;
17
+ const throwError = (ctx, e) => {
18
+ if (e instanceof error_1.default) {
19
+ return ctx.throw(e.status, JSON.stringify(e));
16
20
  }
17
- throw e;
18
- },
21
+ return e;
19
22
  };
23
+ exports.throwError = throwError;
24
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1,10 @@
1
+ import { OnlyStrings } from "strapi-typed";
2
+ import { FlatInput } from "../../../types";
3
+ export declare const flatInput: <T, TKeys = keyof T>(payload: FlatInput<OnlyStrings<TKeys>>) => {
4
+ query: any;
5
+ populate: any;
6
+ pagination: any;
7
+ sort: any;
8
+ fields: import("strapi-typed").StrapiRequestQueryFieldsClause<OnlyStrings<TKeys>> | undefined;
9
+ };
10
+ //# sourceMappingURL=parsers.d.ts.map