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,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 { ToBeFixed } from "../../types";
2
+ declare const controllers: ToBeFixed;
3
+ export default controllers;
4
+ //# sourceMappingURL=client.d.ts.map
@@ -1,114 +1,106 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const functions_1 = require("./../utils/functions");
4
+ const functions_2 = require("./utils/functions");
5
+ const parsers_1 = require("./utils/parsers");
6
+ const controllers = {
7
+ getService(name = "client") {
8
+ return (0, functions_1.getPluginService)(name);
9
+ },
10
+ async findAllFlat(ctx) {
11
+ const { params = {}, query, sort, pagination } = ctx;
12
+ const { relation } = (0, functions_2.parseParams)(params);
13
+ const { sort: querySort, pagination: queryPagination, ...filterQuery } = query || {};
14
+ try {
15
+ (0, functions_1.assertParamsPresent)(params, ["relation"]);
16
+ return this.getService("common").findAllFlat((0, parsers_1.flatInput)(relation, filterQuery, sort || querySort, pagination || queryPagination));
108
17
  }
109
- throw e;
110
- }
111
- }
112
- return ctx.badRequest('Not provided authorId');
113
- },
18
+ catch (e) {
19
+ (0, functions_2.throwError)(ctx, e);
20
+ }
21
+ },
22
+ async findAllInHierarchy(ctx) {
23
+ const { params = {}, query, sort } = ctx;
24
+ const { relation } = (0, functions_2.parseParams)(params);
25
+ const { sort: querySort, ...filterQuery } = query || {};
26
+ try {
27
+ (0, functions_1.assertParamsPresent)(params, ["relation"]);
28
+ return await this.getService("common").findAllInHierarchy({
29
+ ...(0, parsers_1.flatInput)(relation, filterQuery, sort || querySort),
30
+ dropBlockedThreads: true,
31
+ });
32
+ }
33
+ catch (e) {
34
+ (0, functions_2.throwError)(ctx, e);
35
+ }
36
+ },
37
+ async post(ctx) {
38
+ const { request, params = {}, state = {} } = ctx;
39
+ const { relation } = (0, functions_2.parseParams)(params);
40
+ const { user } = state;
41
+ const { body = {} } = request;
42
+ try {
43
+ (0, functions_1.assertParamsPresent)(params, ["relation"]);
44
+ (0, functions_1.assertNotEmpty)(body);
45
+ const entity = await this.getService().create(relation, body, user);
46
+ if (entity) {
47
+ return entity;
48
+ }
49
+ }
50
+ catch (e) {
51
+ (0, functions_2.throwError)(ctx, e);
52
+ }
53
+ },
54
+ async put(ctx) {
55
+ const { request, state, params = {} } = ctx;
56
+ const { body = {} } = request;
57
+ const { user } = state;
58
+ const { commentId, relation } = (0, functions_2.parseParams)(params);
59
+ try {
60
+ (0, functions_1.assertParamsPresent)(params, ["commentId", "relation"]);
61
+ (0, functions_1.assertNotEmpty)(body);
62
+ return await this.getService().update(commentId, relation, body, user);
63
+ }
64
+ catch (e) {
65
+ (0, functions_2.throwError)(ctx, e);
66
+ }
67
+ },
68
+ async reportAbuse(ctx) {
69
+ const { request, state, params = {} } = ctx;
70
+ const { body = {} } = request;
71
+ (0, functions_1.assertNotEmpty)(body);
72
+ if (!body.content) {
73
+ return ctx.badRequest(null, "Content field is required");
74
+ }
75
+ const { user } = state;
76
+ const { relation, commentId } = (0, functions_2.parseParams)(params);
77
+ try {
78
+ (0, functions_1.assertParamsPresent)(params, ["commentId", "relation"]);
79
+ return await this.getService().reportAbuse(commentId, relation, body, user);
80
+ }
81
+ catch (e) {
82
+ (0, functions_2.throwError)(ctx, e);
83
+ }
84
+ },
85
+ async removeComment(ctx) {
86
+ const { params, query, state: { user }, } = ctx;
87
+ const { relationId, commentId } = (0, functions_2.parseParams)(params);
88
+ const { authorId } = (0, functions_2.parseParams)(query);
89
+ try {
90
+ (0, functions_1.assertParamsPresent)(params, ["commentId", "relationId"]);
91
+ (0, functions_1.assertParamsPresent)(query, ["authorId"]);
92
+ if (authorId || user?.id) {
93
+ return await this.getService().markAsRemoved(commentId, relationId, authorId, user);
94
+ }
95
+ return ctx.badRequest("Not provided authorId");
96
+ }
97
+ catch (e) {
98
+ if (!e.isBoom) {
99
+ (0, functions_2.throwError)(ctx, e);
100
+ }
101
+ throw e;
102
+ }
103
+ },
114
104
  };
105
+ exports.default = controllers;
106
+ //# 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: (params: StringMap<string | number>) => ParseResponse;
5
+ export declare const throwError: <T extends {} = never>(ctx: StrapiRequestContext<T, {}>, 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,15 @@
1
+ import { Id } from "strapi-typed";
2
+ import { ToBeFixed } from "../../../types";
3
+ export declare const flatInput: (relation: Id, query: ToBeFixed, sort: ToBeFixed, pagination?: ToBeFixed) => {
4
+ query: any;
5
+ populate: {
6
+ threadOf: {
7
+ populate: {
8
+ authorUser: boolean;
9
+ };
10
+ };
11
+ };
12
+ pagination: any;
13
+ sort: any;
14
+ };
15
+ //# sourceMappingURL=parsers.d.ts.map
@@ -1,23 +1,23 @@
1
- 'use strict'
2
-
3
- module.exports = {
4
- flatInput(relation, query, sort, pagination) {
5
- const filters = query?.filters || query;
6
- const orOperator = (filters?.$or || []).filter(_ => !Object.keys(_).includes('removed'));
7
- return {
8
- query: {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.flatInput = void 0;
4
+ const flatInput = (relation, query, sort, pagination) => {
5
+ const filters = query?.filters || query;
6
+ const orOperator = (filters?.$or || []).filter((_) => !Object.keys(_).includes("removed"));
7
+ return {
8
+ query: {
9
9
  ...filters,
10
10
  $or: [...orOperator, { removed: { $null: true } }, { removed: false }],
11
11
  related: relation,
12
- },
13
- populate: {
12
+ },
13
+ populate: {
14
14
  threadOf: {
15
- populate: { authorUser: true },
15
+ populate: { authorUser: true },
16
16
  },
17
- },
18
- pagination,
19
- sort,
20
- };
21
- },
22
-
17
+ },
18
+ pagination,
19
+ sort,
20
+ };
23
21
  };
22
+ exports.flatInput = flatInput;
23
+ //# sourceMappingURL=parsers.js.map