strapi-plugin-comments 2.0.0-beta.3 → 2.0.0-beta.7

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 (73) hide show
  1. package/README.md +335 -11
  2. package/admin/src/components/DiscussionThread/index.js +9 -2
  3. package/admin/src/components/DiscussionThreadItem/index.js +27 -12
  4. package/admin/src/components/DiscussionThreadItemActions/index.js +61 -50
  5. package/admin/src/components/DiscussionThreadItemActions/styles.js +0 -4
  6. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +81 -0
  7. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +6 -0
  8. package/admin/src/components/DiscussionThreadItemMeta/index.js +16 -5
  9. package/admin/src/components/DiscussionThreadItemWarnings/index.js +16 -10
  10. package/admin/src/components/Nav/index.js +5 -1
  11. package/admin/src/components/ReportsReviewModal/index.js +5 -0
  12. package/admin/src/components/ReportsReviewTable/index.js +60 -52
  13. package/admin/src/components/icons/review.js +2 -2
  14. package/admin/src/index.js +1 -1
  15. package/admin/src/pages/Details/components/DetailsEntity/index.js +66 -0
  16. package/admin/src/pages/Details/components/DetailsFilters/index.js +37 -0
  17. package/admin/src/pages/Details/components/DetailsFilters/styles.js +8 -0
  18. package/admin/src/pages/Details/index.js +75 -42
  19. package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +69 -48
  20. package/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +8 -0
  21. package/admin/src/pages/Discover/index.js +72 -56
  22. package/admin/src/pages/{Details/utils → utils}/api.js +15 -3
  23. package/admin/src/permissions.js +10 -8
  24. package/admin/src/translations/en.json +17 -4
  25. package/admin/src/utils/constants.js +3 -6
  26. package/admin/src/utils/getMessage.js +1 -1
  27. package/admin/src/utils/getRelatedGroups.js +1 -3
  28. package/admin/src/utils/index.js +6 -2
  29. package/admin/src/utils/renderEntryTitle.js +14 -0
  30. package/admin/src/utils/renderInitials.js +5 -0
  31. package/admin/src/utils/resolveCommentStatus.js +30 -0
  32. package/admin/src/utils/resolveCommentStatusColor.js +22 -0
  33. package/package.json +8 -3
  34. package/permissions.js +19 -0
  35. package/server/bootstrap.js +38 -2
  36. package/server/config/index.js +9 -3
  37. package/server/controllers/admin.js +3 -3
  38. package/server/controllers/client.js +4 -18
  39. package/server/controllers/utils/parsers.js +17 -0
  40. package/server/graphql/index.js +26 -0
  41. package/server/graphql/mutations/createAbuseReport.js +20 -0
  42. package/server/graphql/mutations/createComment.js +20 -0
  43. package/server/graphql/mutations/index.js +21 -0
  44. package/server/graphql/mutations/removeComment.js +20 -0
  45. package/server/graphql/mutations/updateComment.js +20 -0
  46. package/server/graphql/queries/findAllFlat.js +29 -0
  47. package/server/graphql/queries/findAllInHierarchy.js +31 -0
  48. package/server/graphql/queries/index.js +19 -0
  49. package/server/graphql/resolvers-config.js +10 -0
  50. package/server/graphql/types/comment-author-user.js +9 -0
  51. package/server/graphql/types/comment-author.js +9 -0
  52. package/server/graphql/types/comment-nested.js +16 -0
  53. package/server/graphql/types/comment.js +16 -0
  54. package/server/graphql/types/create-comment-author.js +9 -0
  55. package/server/graphql/types/create-comment.js +9 -0
  56. package/server/graphql/types/create-report.js +9 -0
  57. package/server/graphql/types/id.js +24 -0
  58. package/server/graphql/types/identify-comment-author.js +6 -0
  59. package/server/graphql/types/index.js +17 -0
  60. package/server/graphql/types/remove-comment.js +8 -0
  61. package/server/graphql/types/report-reason.js +10 -0
  62. package/server/graphql/types/report.js +11 -0
  63. package/server/graphql/types/update-comment.js +9 -0
  64. package/server/register.js +3 -1
  65. package/server/services/admin.js +42 -15
  66. package/server/services/client.js +54 -38
  67. package/server/services/common.js +38 -67
  68. package/server/services/graphql.js +190 -0
  69. package/server/services/index.js +2 -0
  70. package/server/services/utils/functions.js +24 -17
  71. package/server/utils/constants.js +3 -3
  72. package/strapi-server.js +33 -0
  73. package/admin/src/components/EntityDetails/index.js +0 -53
@@ -1,9 +1,13 @@
1
- import { getApiURL, axiosInstance, handleAPIError } from '../../../utils';
1
+ import { stringify } from 'qs';
2
+ import { isEmpty } from 'lodash';
3
+
4
+ import { getApiURL, axiosInstance, handleAPIError } from '../../utils';
2
5
 
3
6
  // eslint-disable-next-line import/prefer-default-export
4
- export const fetchDetailsData = async (id, toggleNotification) => {
7
+ export const fetchDetailsData = async (id, queryParams, toggleNotification) => {
5
8
  try {
6
- const { data } = await axiosInstance.get(getApiURL(`moderate/single/${id}`));
9
+ const stringifiedProps = !isEmpty(queryParams) ? `?${stringify(queryParams, { encode: false })}` : '';
10
+ const { data } = await axiosInstance.get(getApiURL(`moderate/single/${id}${stringifiedProps}`));
7
11
 
8
12
  return data;
9
13
  } catch (err) {
@@ -28,6 +32,14 @@ export const unblockItem = id => {
28
32
  return axiosInstance.patch(getApiURL(`moderate/single/${id}/unblock`));
29
33
  };
30
34
 
35
+ export const approveItem = id => {
36
+ return axiosInstance.patch(getApiURL(`moderate/single/${id}/approve`));
37
+ };
38
+
39
+ export const rejectItem = id => {
40
+ return axiosInstance.patch(getApiURL(`moderate/single/${id}/reject`));
41
+ };
42
+
31
43
  export const blockItemThread = id => {
32
44
  return axiosInstance.patch(getApiURL(`moderate/thread/${id}/block`));
33
45
  };
@@ -1,14 +1,16 @@
1
+ const permissions = require('./../../permissions');
2
+
1
3
  const pluginPermissions = {
2
4
  access: [
3
- { action: 'plugin::comments.read', subject: null },
4
- { action: 'plugin::comments.reports.read', subject: null },
5
- { action: 'plugin::comments.discovery.read', subject: null },
6
- { action: 'plugin::comments.settings.read', subject: null },
5
+ { action: permissions.render(permissions.comments.read), subject: null },
6
+ { action: permissions.render(permissions.reports.read), subject: null },
7
+ // { action: 'plugin::comments.discover.read', subject: null },
8
+ { action: permissions.render(permissions.settings.read), subject: null },
7
9
  ],
8
- discover: [{ action: 'plugin::comments.read', subject: null }],
9
- moderate: [{ action: 'plugin::comments.moderate', subject: null }],
10
- reports: [{ action: 'plugin::comments.reports.read', subject: null }],
11
- reportsReview: [{ action: 'plugin::comments.reports.action', subject: null }],
10
+ // discover: [{ action: 'plugin::comments.discover.read', subject: null }],
11
+ moderate: [{ action: permissions.render(permissions.comments.moderate), subject: null }],
12
+ reports: [{ action: permissions.render(permissions.reports.read), subject: null }],
13
+ reportsReview: [{ action: permissions.render(permissions.reports.action), subject: null }],
12
14
  };
13
15
 
14
16
  export default pluginPermissions;
@@ -7,18 +7,24 @@
7
7
  "nav.item.discover": "Discover",
8
8
  "nav.item.reports": "Reports",
9
9
  "nav.item.settings": "Settings",
10
+ "page.common.item.status.OPEN": "OPEN",
11
+ "page.common.item.status.BLOCKED": "BLOCKED",
12
+ "page.common.item.status.APPROVED": "APPROVED",
13
+ "page.common.item.status.TO_REVIEW": "TO REVIEW ({count, number})",
14
+ "page.common.item.status.REJECTED": "REJECTED",
15
+ "page.common.item.status.REMOVED": "REMOVED BY AUTHOR",
10
16
  "page.updates.header": "Recent updates",
11
17
  "page.discover.header": "Discover threads",
12
18
  "page.discover.header.count": "entries found",
19
+ "page.discover.table.header.id": "ID",
20
+ "page.discover.table.header.author": "Author",
13
21
  "page.discover.table.header.message": "Message",
14
22
  "page.discover.table.header.thread": "Thread of",
15
23
  "page.discover.table.header.entry": "Entry",
16
24
  "page.discover.table.header.lastUpdate": "Last update",
17
25
  "page.discover.table.header.status": "Status",
18
- "page.discover.table.header.status.OPEN": "OPEN",
19
- "page.discover.table.header.status.BLOCKED": "BLOCKED",
20
- "page.discover.table.header.status.TO_REVIEW": "TO REVIEW ({count, number})",
21
- "page.discover.table.header.actions": "Status",
26
+ "page.discover.table.header.actions": "Actions",
27
+ "page.discover.table.cell.thread": "Comment #{id}",
22
28
  "page.discover.table.action.display": "Display",
23
29
  "page.discover.table.action.reports": "Reports",
24
30
  "page.discover.table.empty": "You don't have any comments yet.",
@@ -52,6 +58,7 @@
52
58
  "page.details.panel.status.open": "OPEN",
53
59
  "page.details.panel.status.blocked": "BLOCKED",
54
60
  "page.details.panel.status.pending": "PENDING",
61
+ "page.details.panel.loading": "Fetching entity...",
55
62
  "page.details.actions.comment.block": "Block comment",
56
63
  "page.details.actions.comment.block.confirmation.header": "Moderation: Block comment",
57
64
  "page.details.actions.comment.block.confirmation.description": "Do you really want to block this comment?",
@@ -67,6 +74,12 @@
67
74
  "page.details.actions.thread.block.confirmation.success": "Thread has been blocked",
68
75
  "page.details.actions.thread.unblock": "Unblock thread",
69
76
  "page.details.actions.thread.unblock.confirmation.success": "Thread has been unblocked",
77
+ "page.details.actions.comment.approve.confirmation.success": "Comment has been approved",
78
+ "page.details.actions.comment.reject.confirmation.success": "Comment has been rejected",
79
+ "page.details.filters.label": "View",
80
+ "page.details.filters.removed.visibility": "Comments visibility",
81
+ "page.details.filters.removed.show": "Show removed",
82
+ "page.details.filters.removed.hide": "Hide removed",
70
83
  "page.coming.soon": "Wait for what is coming soon...",
71
84
  "compontents.confirmation.dialog.header": "Confirmation",
72
85
  "compontents.confirmation.dialog.description": "Do you really want to perform this action?",
@@ -16,13 +16,10 @@ export const REPORT_REASON = {
16
16
  };
17
17
 
18
18
  export const COMMENT_STATUS = {
19
+ 'UNKNOWN': 'UNKNOWN',
19
20
  'BLOCKED': 'BLOCKED',
20
21
  'OPEN': 'OPEN',
22
+ 'REMOVED': 'REMOVED',
21
23
  'TO_REVIEW': 'TO_REVIEW',
22
- };
23
-
24
- export const REGEX = {
25
- uid: new RegExp(/^(?<type>[a-z]+)\:{2}(?<api>[a-z]+)\.{1}(?<contentType>[a-z]+)$/gmi),
26
- relatedUid: new RegExp(/^(?<uid>[a-z]+\:{2}[a-z]+\.[a-z]+)\:{1}(?<id>[0-9]+)$/gmi),
27
- email: new RegExp(/\S+@\S+\.\S+/),
24
+ ...APPROVAL_STATUS,
28
25
  };
@@ -4,7 +4,7 @@ import { isString } from 'lodash';
4
4
 
5
5
  import pluginId from '../pluginId';
6
6
 
7
- const getMessage = (input, defaultMessage, inPluginScope = true) => {
7
+ const getMessage = (input, defaultMessage = '', inPluginScope = true) => {
8
8
  const { formatMessage } = useIntl();
9
9
  let formattedId = ''
10
10
  if (isString(input)) {
@@ -1,5 +1,3 @@
1
- import { REGEX } from "./constants";
2
-
3
- const getRelatedGroups = related => related.split(REGEX.relatedUid).filter(s => s && s.length > 0);
1
+ const getRelatedGroups = (related, config) => related.split(config.regex.relatedUid).filter(s => s && s.length > 0);
4
2
 
5
3
  export default getRelatedGroups;
@@ -1,6 +1,10 @@
1
1
  export { default as axiosInstance } from './axiosInstance';
2
- export { default as getApiURL } from './getApiURL';
2
+ export { default as getApiURL } from './getApiUrl';
3
3
  export { default as getUrl } from './getUrl';
4
4
  export { default as getMessage } from './getMessage';
5
5
  export { default as handleAPIError } from './handleAPIError';
6
- export { default as getRelatedGroups } from './getRelatedGroups';
6
+ export { default as getRelatedGroups } from './getRelatedGroups';
7
+ export { default as renderEntryTitle } from './renderEntryTitle';
8
+ export { default as renderInitials } from './renderInitials';
9
+ export { default as resolveCommentStatus } from './resolveCommentStatus';
10
+ export { default as resolveCommentStatusColor } from './resolveCommentStatusColor';
@@ -0,0 +1,14 @@
1
+ import { first } from 'lodash';
2
+
3
+ const renderEntryTitle = (entry, config = {}) => {
4
+ const { entryLabel } = config;
5
+ const rule = entry.uid in entryLabel ? entryLabel[entry.uid] : entryLabel['*'];
6
+ return first(
7
+ Object.keys(entry)
8
+ .filter(_ => (rule === _) || rule.includes(_))
9
+ .map(_ => entry[_])
10
+ .filter(_ => _)
11
+ );
12
+ };
13
+
14
+ export default renderEntryTitle;
@@ -0,0 +1,5 @@
1
+ import { first } from 'lodash';
2
+
3
+ const renderInitials = (value = '') => value.split(' ').map(_ => first(_)).join('').toUpperCase();
4
+
5
+ export default renderInitials;
@@ -0,0 +1,30 @@
1
+ import { isNil } from 'lodash';
2
+ import { COMMENT_STATUS } from './constants';
3
+
4
+ const resolveCommentStatus = ({ removed, blocked, blockedThread, approvalStatus, reviewFlowEnabled }) => {
5
+ const gotApprovalFlow = !isNil(approvalStatus);
6
+
7
+ if (reviewFlowEnabled) {
8
+ return COMMENT_STATUS.TO_REVIEW;
9
+ }
10
+
11
+ if (removed) {
12
+ return COMMENT_STATUS.REMOVED;
13
+ }
14
+
15
+ if (blocked || blockedThread) {
16
+ return COMMENT_STATUS.BLOCKED;
17
+ }
18
+
19
+ if (gotApprovalFlow) {
20
+ const status = approvalStatus.toUpperCase();
21
+ if (Object.keys(COMMENT_STATUS).includes(status)) {
22
+ return status;
23
+ }
24
+ return COMMENT_STATUS.UNKNOWN;
25
+ }
26
+
27
+ return COMMENT_STATUS.OPEN;
28
+ }
29
+
30
+ export default resolveCommentStatus;
@@ -0,0 +1,22 @@
1
+ import { isNil } from 'lodash';
2
+ import { COMMENT_STATUS } from './constants';
3
+
4
+ const resolveCommentStatusColor = (status) => {
5
+ if (Object.keys(COMMENT_STATUS).includes(status)) {
6
+ switch (status) {
7
+ case COMMENT_STATUS.REMOVED:
8
+ return 'secondary';
9
+ case COMMENT_STATUS.TO_REVIEW:
10
+ case COMMENT_STATUS.REJECTED:
11
+ return 'warning';
12
+ case COMMENT_STATUS.BLOCKED:
13
+ return 'danger';
14
+ case COMMENT_STATUS.OPEN:
15
+ case COMMENT_STATUS.APPROVED:
16
+ return 'success';
17
+ };
18
+ }
19
+ return 'secondary';
20
+ }
21
+
22
+ export default resolveCommentStatusColor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-comments",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-beta.7",
4
4
  "description": "Strapi - Comments plugin",
5
5
  "strapi": {
6
6
  "name": "comments",
@@ -15,6 +15,8 @@
15
15
  "url": "https://github.com/VirtusLab-Open-Source/strapi-plugin-comments"
16
16
  },
17
17
  "dependencies": {
18
+ "@strapi/utils": "^4.0.5",
19
+ "@strapi/plugin-graphql": "^4.0.5",
18
20
  "bad-words": "^3.0.4"
19
21
  },
20
22
  "devDependencies": {
@@ -23,6 +25,9 @@
23
25
  "jest-cli": "^26.0.1",
24
26
  "jest-styled-components": "^7.0.2"
25
27
  },
28
+ "peerDependencies": {
29
+ "@strapi/strapi": "4.x"
30
+ },
26
31
  "author": {
27
32
  "name": "VirtusLab // Mateusz Ziarko",
28
33
  "email": "mziarko@virtuslab.com",
@@ -41,8 +46,8 @@
41
46
  }
42
47
  ],
43
48
  "engines": {
44
- "node": ">=12.x. <=16.x.x",
45
- "npm": ">=6.0.0"
49
+ "node": ">=14.x.x <=17.x.x",
50
+ "npm": ">=7.x.x"
46
51
  },
47
52
  "keywords": ["strapi", "plugin", "comments"],
48
53
  "license": "MIT"
package/permissions.js ADDED
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ render: function(uid) {
5
+ return `plugin::comments.${uid}`;
6
+ },
7
+ comments: {
8
+ read: 'read',
9
+ moderate: 'moderate',
10
+ },
11
+ reports: {
12
+ read: 'reports.read',
13
+ action: 'reports.action',
14
+ },
15
+ settings: {
16
+ read: 'settings.read',
17
+ change: 'settings.change',
18
+ },
19
+ };
@@ -1,5 +1,41 @@
1
1
  'use strict';
2
2
 
3
- module.exports = ({ strapi }) => {
4
- // bootstrap phase
3
+ const permissions = require('./../permissions');
4
+
5
+ module.exports = async ({ strapi }) => {
6
+ // Check if the plugin users-permissions is installed because the navigation needs it
7
+ if (Object.keys(strapi.plugins).indexOf("users-permissions") === -1) {
8
+ throw new Error(
9
+ "In order to make the comments plugin work the users-permissions plugin is required",
10
+ );
11
+ }
12
+ // Add permissions
13
+ const actions = [
14
+ {
15
+ section: "plugins",
16
+ displayName: "Comments: Read",
17
+ uid: permissions.comments.read,
18
+ pluginName: "comments",
19
+ },
20
+ {
21
+ section: "plugins",
22
+ displayName: "Comments: Moderate",
23
+ uid: permissions.comments.moderate,
24
+ pluginName: "comments",
25
+ },
26
+ {
27
+ section: "plugins",
28
+ displayName: "Reports: Read",
29
+ uid: permissions.reports.read,
30
+ pluginName: "comments",
31
+ },
32
+ {
33
+ section: "plugins",
34
+ displayName: "Reports: Moderate",
35
+ uid: permissions.reports.action,
36
+ pluginName: "comments",
37
+ },
38
+ ];
39
+
40
+ await strapi.admin.services.permission.actionProvider.registerMany(actions);
5
41
  };
@@ -2,9 +2,15 @@
2
2
 
3
3
  module.exports = {
4
4
  default: {
5
+ moderatorRoles: [],
6
+ approvalFlow: [],
5
7
  entryLabel: {
6
8
  '*': ['Title', 'title', 'Name', 'name', 'Subject', 'subject']
7
- }
8
- },
9
- validator() {},
9
+ },
10
+ reportReasons: {
11
+ 'BAD_LANGUAGE': 'BAD_LANGUAGE',
12
+ 'DISCRIMINATION': 'DISCRIMINATION',
13
+ 'OTHER': 'OTHER',
14
+ },
15
+ }
10
16
  };
@@ -16,11 +16,11 @@ module.exports = {
16
16
  },
17
17
 
18
18
  async findOne(ctx) {
19
- const { params = {} } = ctx;
19
+ const { params = {}, query } = ctx;
20
20
  const { id } = parseParams(params);
21
21
  try {
22
22
  return await this.getService()
23
- .findOneAndThread(id);
23
+ .findOneAndThread(id, query);
24
24
  } catch (e) {
25
25
  throwError(ctx, e);
26
26
  }
@@ -101,7 +101,7 @@ module.exports = {
101
101
  }
102
102
  },
103
103
 
104
- async config() {
104
+ async config(ctx) {
105
105
  try {
106
106
  return await this.getService().config();
107
107
  } catch (e) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { getPluginService } = require('./../utils/functions');
4
4
  const { parseParams, throwError } = require('./utils/functions');
5
- const _ = require('lodash');
5
+ const { flatInput } = require('./utils/parsers');
6
6
 
7
7
  module.exports = {
8
8
 
@@ -15,15 +15,7 @@ module.exports = {
15
15
  const { relation } = parseParams(params);
16
16
  try {
17
17
  return this.getService('common')
18
- .findAllFlat({
19
- query: {
20
- ...query,
21
- related: relation,
22
- },
23
- populate: {
24
- threadOf: true,
25
- },
26
- });
18
+ .findAllFlat(flatInput(relation, query));
27
19
  } catch (e) {
28
20
  throwError(ctx, e);
29
21
  }
@@ -35,13 +27,7 @@ module.exports = {
35
27
  try {
36
28
  return await this.getService('common')
37
29
  .findAllInHierarchy({
38
- query: {
39
- ...query,
40
- related: relation,
41
- },
42
- populate: {
43
- threadOf: true,
44
- },
30
+ ...flatInput(relation, query),
45
31
  dropBlockedThreads: true,
46
32
  });
47
33
  } catch (e) {
@@ -101,8 +87,8 @@ module.exports = {
101
87
  try {
102
88
  return await this.getService()
103
89
  .markAsRemoved(
104
- relationId,
105
90
  commentId,
91
+ relationId,
106
92
  authorId,
107
93
  );
108
94
  } catch (e) {
@@ -0,0 +1,17 @@
1
+ 'use strict'
2
+
3
+ module.exports = {
4
+ flatInput(relation, query) {
5
+ return {
6
+ query: {
7
+ ...query,
8
+ $or: [{ removed: { $null: true } }, { removed: false }],
9
+ related: relation,
10
+ },
11
+ populate: {
12
+ threadOf: true,
13
+ },
14
+ };
15
+ },
16
+
17
+ };
@@ -0,0 +1,26 @@
1
+ 'use strict'
2
+
3
+ const getTypes = require('./types');
4
+ const getQueries = require('./queries');
5
+ const getMutations = require('./mutations');
6
+ const getResolversConfig = require('./resolvers-config');
7
+ const { getModelUid } = require('../services/utils/functions');
8
+
9
+ module.exports = () => {
10
+ const extensionService = strapi.plugin('graphql').service('extension');
11
+
12
+ extensionService.shadowCRUD(getModelUid('comment')).disable();
13
+ extensionService.shadowCRUD(getModelUid('comment-report')).disable();
14
+
15
+ extensionService.use(({ nexus }) => {
16
+ const types = getTypes({ strapi, nexus });
17
+ const queries = getQueries({ strapi, nexus });
18
+ const mutations = getMutations({ strapi, nexus });
19
+ const resolversConfig = getResolversConfig({ strapi });
20
+
21
+ return {
22
+ types: [types, queries, mutations],
23
+ resolversConfig,
24
+ }
25
+ });
26
+ }
@@ -0,0 +1,20 @@
1
+ 'use strict'
2
+
3
+ const { getPluginService } = require('../../utils/functions');
4
+
5
+ module.exports = ({ nexus }) => {
6
+ const { nonNull } = nexus;
7
+
8
+ return {
9
+ type: nonNull('Report'),
10
+ args: {
11
+ input: nonNull('CreateReport'),
12
+ },
13
+ async resolve(obj, args) {
14
+ const { input } = args;
15
+ const { commentId, relation, ...body } = input;
16
+ return await getPluginService('client')
17
+ .reportAbuse(commentId, relation, body);
18
+ },
19
+ };
20
+ }
@@ -0,0 +1,20 @@
1
+ 'use strict'
2
+
3
+ const { getPluginService } = require('../../utils/functions');
4
+
5
+ module.exports = ({ nexus }) => {
6
+ const { nonNull } = nexus;
7
+
8
+ return {
9
+ type: nonNull('CommentSingle'),
10
+ args: {
11
+ input: nonNull('CreateComment'),
12
+ },
13
+ async resolve(obj, args) {
14
+ const { input } = args;
15
+ const { relation, ...body } = input;
16
+ return await getPluginService('client')
17
+ .create(relation, body);
18
+ },
19
+ };
20
+ }
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+
3
+ module.exports = (context) => {
4
+ const mutations = {
5
+ createComment: require('./createComment'),
6
+ updateComment: require('./updateComment'),
7
+ removeComment: require('./removeComment'),
8
+ createAbuseReport: require('./createAbuseReport'),
9
+ };
10
+
11
+ return context.nexus.extendType({
12
+ type: 'Mutation',
13
+ definition(t) {
14
+ for (const [name, configFactory] of Object.entries(mutations)) {
15
+ const config = configFactory(context);
16
+
17
+ t.field(name, config);
18
+ }
19
+ },
20
+ });
21
+ };
@@ -0,0 +1,20 @@
1
+ 'use strict'
2
+
3
+ const { getPluginService } = require('../../utils/functions');
4
+
5
+ module.exports = ({ nexus }) => {
6
+ const { nonNull } = nexus;
7
+
8
+ return {
9
+ type: nonNull('CommentSingle'),
10
+ args: {
11
+ input: nonNull('RemoveComment'),
12
+ },
13
+ async resolve(obj, args) {
14
+ const { input } = args;
15
+ const { id, relation, author } = input;
16
+ return await getPluginService('client')
17
+ .markAsRemoved(id, relation, author?.id);
18
+ },
19
+ };
20
+ }
@@ -0,0 +1,20 @@
1
+ 'use strict'
2
+
3
+ const { getPluginService } = require('../../utils/functions');
4
+
5
+ module.exports = ({ nexus }) => {
6
+ const { nonNull } = nexus;
7
+
8
+ return {
9
+ type: nonNull('CommentSingle'),
10
+ args: {
11
+ input: nonNull('UpdateComment'),
12
+ },
13
+ async resolve(obj, args) {
14
+ const { input } = args;
15
+ const { id, relation, ...body } = input;
16
+ return await getPluginService('client')
17
+ .update(id, relation, body);
18
+ },
19
+ };
20
+ }
@@ -0,0 +1,29 @@
1
+ 'use strict'
2
+
3
+ const contentType = require('../../../content-types/comment');
4
+ const { flatInput } = require('../../controllers/utils/parsers');
5
+ const { getPluginService } = require('../../utils/functions');
6
+
7
+ module.exports = ({ strapi, nexus }) => {
8
+ const { nonNull, list, stringArg } = nexus;
9
+ const { service: getService } = strapi.plugin('graphql');
10
+ const { args } = getService('internals');
11
+
12
+ return {
13
+ type: nonNull(list('CommentSingle')),
14
+ args: {
15
+ relation: nonNull(stringArg()),
16
+ filters: getPluginService('gql').buildContentTypeFilters(contentType),
17
+ pagination: args.PaginationArg,
18
+ sort: args.SortArg,
19
+ },
20
+ async resolve(obj, args) {
21
+ const { relation, filters } = args;
22
+ return await getPluginService('common')
23
+ .findAllFlat(flatInput(
24
+ relation,
25
+ getPluginService('gql').graphQLFiltersToStrapiQuery(filters, contentType)
26
+ ), undefined);
27
+ },
28
+ };
29
+ }
@@ -0,0 +1,31 @@
1
+ 'use strict'
2
+
3
+ const contentType = require('../../../content-types/comment');
4
+ const { flatInput } = require('../../controllers/utils/parsers');
5
+ const { getPluginService } = require('../../utils/functions');
6
+
7
+ module.exports = ({ strapi, nexus }) => {
8
+ const { nonNull, list, stringArg } = nexus;
9
+ const { service: getService } = strapi.plugin('graphql');
10
+ const { args } = getService('internals');
11
+
12
+ return {
13
+ type: nonNull(list('CommentNested')),
14
+ args: {
15
+ relation: nonNull(stringArg()),
16
+ // filters: filtersArg,
17
+ sort: args.SortArg,
18
+ },
19
+ async resolve(obj, args) {
20
+ const { relation, filters } = args;
21
+ return await getPluginService('common')
22
+ .findAllInHierarchy({
23
+ ...flatInput(
24
+ relation,
25
+ getPluginService('gql').graphQLFiltersToStrapiQuery(filters, contentType)
26
+ ),
27
+ dropBlockedThreads: true,
28
+ });
29
+ },
30
+ };
31
+ }
@@ -0,0 +1,19 @@
1
+ 'use strict'
2
+
3
+ module.exports = (context) => {
4
+ const queries = {
5
+ findAllFlat: require('./findAllFlat'),
6
+ findAllInHierarchy: require('./findAllInHierarchy'),
7
+ };
8
+
9
+ return context.nexus.extendType({
10
+ type: 'Query',
11
+ definition(t) {
12
+ for (const [name, configFactory] of Object.entries(queries)) {
13
+ const config = configFactory(context);
14
+
15
+ t.field(name, config);
16
+ }
17
+ },
18
+ });
19
+ };