strapi-plugin-comments 2.0.0-beta.6 → 2.0.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 (71) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/README.md +474 -119
  3. package/__mocks__/initSetup.js +53 -0
  4. package/admin/src/components/ActionButton/styles.js +10 -0
  5. package/admin/src/components/DiscussionThread/index.js +3 -7
  6. package/admin/src/components/DiscussionThreadItem/index.js +25 -74
  7. package/admin/src/components/DiscussionThreadItem/styles.js +4 -79
  8. package/admin/src/components/DiscussionThreadItemActions/index.js +82 -40
  9. package/admin/src/components/DiscussionThreadItemActions/styles.js +1 -12
  10. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +2 -3
  11. package/admin/src/components/DiscussionThreadItemFooter/index.js +47 -0
  12. package/admin/src/components/DiscussionThreadItemFooter/styles.js +13 -0
  13. package/admin/src/components/DiscussionThreadItemReviewAction/index.js +131 -0
  14. package/admin/src/components/IconButton/styles.js +14 -0
  15. package/admin/src/components/ReportsReviewModal/index.js +1 -1
  16. package/admin/src/components/ReportsReviewTable/index.js +12 -6
  17. package/admin/src/components/StatusBadge/index.js +17 -0
  18. package/admin/src/components/StatusBadge/styles.js +17 -0
  19. package/admin/src/pages/Details/components/DetailsEntity/index.js +40 -24
  20. package/admin/src/pages/Details/components/DetailsFilters/index.js +8 -10
  21. package/admin/src/pages/Details/index.js +9 -15
  22. package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +36 -66
  23. package/admin/src/pages/Discover/index.js +4 -1
  24. package/admin/src/translations/en.json +14 -15
  25. package/admin/src/utils/index.js +2 -0
  26. package/admin/src/utils/renderInitials.js +5 -0
  27. package/admin/src/utils/resolveCommentStatus.js +4 -4
  28. package/content-types/comment.js +0 -4
  29. package/package.json +8 -4
  30. package/public/assets/logo.png +0 -0
  31. package/public/assets/preview.png +0 -0
  32. package/server/config/index.js +5 -0
  33. package/server/controllers/client.js +11 -21
  34. package/server/controllers/utils/__tests__/functions.test.js +2 -2
  35. package/server/controllers/utils/parsers.js +19 -0
  36. package/server/graphql/index.js +26 -0
  37. package/server/graphql/mutations/createAbuseReport.js +25 -0
  38. package/server/graphql/mutations/createComment.js +25 -0
  39. package/server/graphql/mutations/index.js +21 -0
  40. package/server/graphql/mutations/removeComment.js +25 -0
  41. package/server/graphql/mutations/updateComment.js +25 -0
  42. package/server/graphql/queries/findAllFlat.js +29 -0
  43. package/server/graphql/queries/findAllInHierarchy.js +31 -0
  44. package/server/graphql/queries/index.js +19 -0
  45. package/server/graphql/resolvers-config.js +15 -0
  46. package/server/graphql/types/comment-author.js +9 -0
  47. package/server/graphql/types/comment-nested.js +16 -0
  48. package/server/graphql/types/comment.js +15 -0
  49. package/server/graphql/types/create-comment-author.js +9 -0
  50. package/server/graphql/types/create-comment.js +9 -0
  51. package/server/graphql/types/create-report.js +9 -0
  52. package/server/graphql/types/id.js +24 -0
  53. package/server/graphql/types/identify-comment-author.js +6 -0
  54. package/server/graphql/types/index.js +16 -0
  55. package/server/graphql/types/remove-comment.js +8 -0
  56. package/server/graphql/types/report-reason.js +10 -0
  57. package/server/graphql/types/report.js +11 -0
  58. package/server/graphql/types/update-comment.js +9 -0
  59. package/server/register.js +3 -1
  60. package/server/services/__tests__/common.test.js +165 -0
  61. package/server/services/admin.js +18 -15
  62. package/server/services/client.js +73 -51
  63. package/server/services/common.js +42 -14
  64. package/server/services/graphql.js +190 -0
  65. package/server/services/index.js +2 -0
  66. package/server/services/utils/__tests__/functions.test.js +9 -73
  67. package/server/services/utils/functions.js +30 -27
  68. package/server/utils/__tests__/functions.test.js +17 -0
  69. package/admin/src/components/DiscussionThreadItemMeta/index.js +0 -31
  70. package/admin/src/components/DiscussionThreadItemWarnings/index.js +0 -147
  71. package/admin/src/components/DiscussionThreadItemWarnings/styles.js +0 -7
@@ -7,16 +7,17 @@
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
+ "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",
16
16
  "page.updates.header": "Recent updates",
17
17
  "page.discover.header": "Discover threads",
18
18
  "page.discover.header.count": "entries found",
19
19
  "page.discover.table.header.id": "ID",
20
+ "page.discover.table.header.author": "Author",
20
21
  "page.discover.table.header.message": "Message",
21
22
  "page.discover.table.header.thread": "Thread of",
22
23
  "page.discover.table.header.entry": "Entry",
@@ -46,17 +47,17 @@
46
47
  "page.details.panel.discussion.warnings.reports.dialog.content": "Content",
47
48
  "page.details.panel.discussion.warnings.reports.dialog.createdAt": "Issue date",
48
49
  "page.details.panel.discussion.warnings.reports.dialog.status": "Status",
49
- "page.details.panel.discussion.warnings.reports.dialog.status.OPEN": "OPEN",
50
- "page.details.panel.discussion.warnings.reports.dialog.status.RESOLVED": "RESOLVED",
50
+ "page.details.panel.discussion.warnings.reports.dialog.status.OPEN": "Open",
51
+ "page.details.panel.discussion.warnings.reports.dialog.status.RESOLVED": "Resolved",
51
52
  "page.details.panel.discussion.warnings.reports.dialog.actions": "Actions",
52
53
  "page.details.panel.discussion.warnings.reports.dialog.actions.resolve": "Resolve",
53
54
  "page.details.panel.discussion.warnings.reports.dialog.confirmation.success": "Open report has been resolved",
54
- "page.details.panel.discussion.status.blocked": "BLOCKED",
55
+ "page.details.panel.discussion.status.blocked": "Blocked",
55
56
  "page.details.panel.entity": "Entity details",
56
57
  "page.details.panel.status": "Discussion is",
57
- "page.details.panel.status.open": "OPEN",
58
- "page.details.panel.status.blocked": "BLOCKED",
59
- "page.details.panel.status.pending": "PENDING",
58
+ "page.details.panel.status.open": "Open",
59
+ "page.details.panel.status.blocked": "Blocked",
60
+ "page.details.panel.status.pending": "Pending",
60
61
  "page.details.panel.loading": "Fetching entity...",
61
62
  "page.details.actions.comment.block": "Block comment",
62
63
  "page.details.actions.comment.block.confirmation.header": "Moderation: Block comment",
@@ -76,9 +77,7 @@
76
77
  "page.details.actions.comment.approve.confirmation.success": "Comment has been approved",
77
78
  "page.details.actions.comment.reject.confirmation.success": "Comment has been rejected",
78
79
  "page.details.filters.label": "View",
79
- "page.details.filters.removed.visibility": "Comments visibility",
80
- "page.details.filters.removed.show": "Show removed",
81
- "page.details.filters.removed.hide": "Hide removed",
80
+ "page.details.filters.removed.visibility": "Show removed comments",
82
81
  "page.coming.soon": "Wait for what is coming soon...",
83
82
  "compontents.confirmation.dialog.header": "Confirmation",
84
83
  "compontents.confirmation.dialog.description": "Do you really want to perform this action?",
@@ -4,5 +4,7 @@ export { default as getUrl } from './getUrl';
4
4
  export { default as getMessage } from './getMessage';
5
5
  export { default as handleAPIError } from './handleAPIError';
6
6
  export { default as getRelatedGroups } from './getRelatedGroups';
7
+ export { default as renderEntryTitle } from './renderEntryTitle';
8
+ export { default as renderInitials } from './renderInitials';
7
9
  export { default as resolveCommentStatus } from './resolveCommentStatus';
8
10
  export { default as resolveCommentStatusColor } from './resolveCommentStatusColor';
@@ -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;
@@ -4,10 +4,6 @@ import { COMMENT_STATUS } from './constants';
4
4
  const resolveCommentStatus = ({ removed, blocked, blockedThread, approvalStatus, reviewFlowEnabled }) => {
5
5
  const gotApprovalFlow = !isNil(approvalStatus);
6
6
 
7
- if (reviewFlowEnabled) {
8
- return COMMENT_STATUS.TO_REVIEW;
9
- }
10
-
11
7
  if (removed) {
12
8
  return COMMENT_STATUS.REMOVED;
13
9
  }
@@ -15,6 +11,10 @@ const resolveCommentStatus = ({ removed, blocked, blockedThread, approvalStatus,
15
11
  if (blocked || blockedThread) {
16
12
  return COMMENT_STATUS.BLOCKED;
17
13
  }
14
+
15
+ if (reviewFlowEnabled) {
16
+ return COMMENT_STATUS.TO_REVIEW;
17
+ }
18
18
 
19
19
  if (gotApprovalFlow) {
20
20
  const status = approvalStatus.toUpperCase();
@@ -48,10 +48,6 @@ module.exports = {
48
48
  target: 'plugin::users-permissions.user',
49
49
  configurable: false,
50
50
  },
51
- authorType: {
52
- type: 'string',
53
- configurable: false
54
- },
55
51
  authorId: {
56
52
  type: 'string',
57
53
  configurable: false
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "strapi-plugin-comments",
3
- "version": "2.0.0-beta.6",
3
+ "version": "2.0.0",
4
4
  "description": "Strapi - Comments plugin",
5
5
  "strapi": {
6
6
  "name": "comments",
7
- "description": "Comments & audience engagement",
7
+ "displayName": "Comments",
8
+ "description": "Powerful Strapi based comments moderation tool for you and your users",
8
9
  "kind": "plugin"
9
10
  },
10
11
  "scripts": {
12
+ "publish": "npm publish --tag latest",
11
13
  "test:unit": "jest --verbose --coverage"
12
14
  },
13
15
  "repository": {
@@ -15,14 +17,16 @@
15
17
  "url": "https://github.com/VirtusLab-Open-Source/strapi-plugin-comments"
16
18
  },
17
19
  "dependencies": {
18
- "@strapi/utils": "^4.0.5",
20
+ "@strapi/utils": "^4.0.7",
21
+ "@strapi/plugin-graphql": "^4.0.7",
19
22
  "bad-words": "^3.0.4"
20
23
  },
21
24
  "devDependencies": {
22
25
  "codecov": "^3.7.2",
23
26
  "jest": "^26.0.1",
24
27
  "jest-cli": "^26.0.1",
25
- "jest-styled-components": "^7.0.2"
28
+ "jest-styled-components": "^7.0.2",
29
+ "koa": "2.13.3"
26
30
  },
27
31
  "peerDependencies": {
28
32
  "@strapi/strapi": "4.x"
Binary file
Binary file
@@ -7,5 +7,10 @@ module.exports = {
7
7
  entryLabel: {
8
8
  '*': ['Title', 'title', 'Name', 'name', 'Subject', 'subject']
9
9
  },
10
+ reportReasons: {
11
+ 'BAD_LANGUAGE': 'BAD_LANGUAGE',
12
+ 'DISCRIMINATION': 'DISCRIMINATION',
13
+ 'OTHER': 'OTHER',
14
+ },
10
15
  }
11
16
  };
@@ -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,16 +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
- $or: [{ removed: { $null: true } }, { removed: false }],
22
- related: relation,
23
- },
24
- populate: {
25
- threadOf: true,
26
- },
27
- });
18
+ .findAllFlat(flatInput(relation, query));
28
19
  } catch (e) {
29
20
  throwError(ctx, e);
30
21
  }
@@ -36,13 +27,7 @@ module.exports = {
36
27
  try {
37
28
  return await this.getService('common')
38
29
  .findAllInHierarchy({
39
- query: {
40
- ...query,
41
- related: relation,
42
- },
43
- populate: {
44
- threadOf: true,
45
- },
30
+ ...flatInput(relation, query),
46
31
  dropBlockedThreads: true,
47
32
  });
48
33
  } catch (e) {
@@ -97,14 +82,19 @@ module.exports = {
97
82
  },
98
83
 
99
84
  async removeComment(ctx) {
100
- const { params: { relationId, commentId }, query: { authorId } } = ctx;
101
- if (authorId) {
85
+ const {
86
+ params: { relationId, commentId },
87
+ query: { authorId },
88
+ state: { user },
89
+ } = ctx;
90
+ if (authorId || user?.id) {
102
91
  try {
103
92
  return await this.getService()
104
93
  .markAsRemoved(
105
- relationId,
106
94
  commentId,
95
+ relationId,
107
96
  authorId,
97
+ user
108
98
  );
109
99
  } catch (e) {
110
100
  if (!e.isBoom) {
@@ -1,6 +1,6 @@
1
- const PluginError = require('../../../services/utils/error');
1
+ const PluginError = require('../../../utils/error');
2
2
  const ctx = require('koa/lib/context');
3
- const { parseParams, throwError } = require('../functions');
3
+ const { throwError } = require('../functions');
4
4
 
5
5
  jest.mock
6
6
 
@@ -0,0 +1,19 @@
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: {
13
+ populate: { authorUser: true },
14
+ },
15
+ },
16
+ };
17
+ },
18
+
19
+ };
@@ -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,25 @@
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, ctx) {
14
+ const { input } = args;
15
+ const { state: { user } = {} } = ctx;
16
+ const { commentId, relation, ...body } = input;
17
+ try {
18
+ return await getPluginService('client')
19
+ .reportAbuse(commentId, relation, body, user);
20
+ } catch(e) {
21
+ throw new Error(e);
22
+ }
23
+ },
24
+ };
25
+ }
@@ -0,0 +1,25 @@
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, ctx) {
14
+ const { input } = args;
15
+ const { state: { user } = {} } = ctx;
16
+ const { relation, ...body } = input;
17
+ try {
18
+ return await getPluginService('client')
19
+ .create(relation, body, user);
20
+ } catch(e) {
21
+ throw new Error(e);
22
+ }
23
+ },
24
+ };
25
+ }
@@ -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,25 @@
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, ctx) {
14
+ const { input } = args;
15
+ const { state: { user } = {} } = ctx;
16
+ const { id, relation, author } = input;
17
+ try {
18
+ return await getPluginService('client')
19
+ .markAsRemoved(id, relation, author?.id, user);
20
+ } catch(e) {
21
+ throw new Error(e);
22
+ }
23
+ },
24
+ };
25
+ }
@@ -0,0 +1,25 @@
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, ctx) {
14
+ const { input } = args;
15
+ const { state: { user } = {} } = ctx;
16
+ const { id, relation, ...body } = input;
17
+ try {
18
+ return await getPluginService('client')
19
+ .update(id, relation, body, user);
20
+ } catch(e) {
21
+ throw new Error(e);
22
+ }
23
+ },
24
+ };
25
+ }
@@ -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
+ };
@@ -0,0 +1,15 @@
1
+ 'use strict'
2
+
3
+ const { getPluginService } = require("../utils/functions");
4
+
5
+ module.exports = () => {
6
+ const auth = getPluginService('common').getConfig('gql.auth', false);
7
+ return {
8
+ 'Query.findAllFlat': { auth },
9
+ 'Query.findAllInHierarchy': { auth },
10
+ 'Mutation.createComment': { auth },
11
+ 'Mutation.updateComment': { auth },
12
+ 'Mutation.removeComment': { auth },
13
+ 'Mutation.createAbuseReport': { auth },
14
+ };
15
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = ({ nexus }) => nexus.objectType({
2
+ name: "CommentAuthor",
3
+ definition(t) {
4
+ t.id("id")
5
+ t.nonNull.string("name")
6
+ t.string("email")
7
+ t.string("avatar")
8
+ }
9
+ })
@@ -0,0 +1,16 @@
1
+ module.exports = ({ nexus }) => nexus.objectType({
2
+ name: "CommentNested",
3
+ definition(t) {
4
+ t.id("id")
5
+ t.nonNull.string("content")
6
+ t.boolean("blocked")
7
+ t.boolean("blockedThread")
8
+ t.string("approvalStatus")
9
+ t.boolean("removed")
10
+ t.field("threadOf", { type: 'CommentSingle' })
11
+ t.list.field("children", { type: 'CommentNested' })
12
+ t.field("author", { type: 'CommentAuthor' })
13
+ t.string("createdAt")
14
+ t.string("updatedAt")
15
+ }
16
+ })
@@ -0,0 +1,15 @@
1
+ module.exports = ({ nexus }) => nexus.objectType({
2
+ name: "CommentSingle",
3
+ definition(t) {
4
+ t.id("id")
5
+ t.nonNull.string("content")
6
+ t.boolean("blocked")
7
+ t.boolean("blockedThread")
8
+ t.boolean("removed")
9
+ t.string("approvalStatus")
10
+ t.field("threadOf", { type: 'CommentSingle' })
11
+ t.field("author", { type: 'CommentAuthor' })
12
+ t.string("createdAt")
13
+ t.string("updatedAt")
14
+ }
15
+ })
@@ -0,0 +1,9 @@
1
+ module.exports = ({ nexus }) => nexus.inputObjectType({
2
+ name: "CreateCommentAuthor",
3
+ definition(t) {
4
+ t.nonNull.id("id")
5
+ t.nonNull.string("name")
6
+ t.string("email")
7
+ t.string("avatar")
8
+ }
9
+ })
@@ -0,0 +1,9 @@
1
+ module.exports = ({ nexus }) => nexus.inputObjectType({
2
+ name: "CreateComment",
3
+ definition(t) {
4
+ t.nonNull.string("content")
5
+ t.nonNull.string("relation")
6
+ t.id("threadOf")
7
+ t.field("author", { type: 'CreateCommentAuthor' })
8
+ }
9
+ })
@@ -0,0 +1,9 @@
1
+ module.exports = ({ nexus }) => nexus.inputObjectType({
2
+ name: "CreateReport",
3
+ definition(t) {
4
+ t.id("commentId")
5
+ t.nonNull.string("relation")
6
+ t.nonNull.string("content")
7
+ t.field("reason", { type: 'ReportReason' })
8
+ }
9
+ })
@@ -0,0 +1,24 @@
1
+ const { isNumber, parseInt } = require('lodash');
2
+ const { Kind } = require('graphql');
3
+
4
+ module.exports = ({ nexus }) => nexus.scalarType({
5
+ name: "Id",
6
+ asNexusMethod: 'id',
7
+ description: 'Id as string or int',
8
+ parseValue(value) {
9
+ const parsedValue = parseInt(value);
10
+ if (isNumber(parsedValue)) {
11
+ return parsedValue;
12
+ }
13
+ return value;
14
+ },
15
+ serialize(value) {
16
+ return value;
17
+ },
18
+ parseLiteral(ast) {
19
+ if ([Kind.INT, Kind.STRING].includes(ast.kind)) {
20
+ return ast.value;
21
+ }
22
+ return null
23
+ },
24
+ })
@@ -0,0 +1,6 @@
1
+ module.exports = ({ nexus }) => nexus.inputObjectType({
2
+ name: "IdentifyCommentAuthor",
3
+ definition(t) {
4
+ t.nonNull.id("id")
5
+ }
6
+ })
@@ -0,0 +1,16 @@
1
+ const typesFactories = [
2
+ require('./id'),
3
+ require('./comment'),
4
+ require('./comment-nested'),
5
+ require('./comment-author'),
6
+ require('./create-comment'),
7
+ require('./create-comment-author'),
8
+ require('./update-comment'),
9
+ require('./remove-comment'),
10
+ require('./identify-comment-author'),
11
+ require('./report'),
12
+ require('./report-reason'),
13
+ require('./create-report'),
14
+ ];
15
+
16
+ module.exports = context => typesFactories.map(factory => factory(context));
@@ -0,0 +1,8 @@
1
+ module.exports = ({ nexus }) => nexus.inputObjectType({
2
+ name: "RemoveComment",
3
+ definition(t) {
4
+ t.id("id")
5
+ t.nonNull.string("relation")
6
+ t.field("author", { type: 'IdentifyCommentAuthor' })
7
+ }
8
+ })
@@ -0,0 +1,10 @@
1
+ const { getPluginService } = require("../../utils/functions");
2
+
3
+
4
+ module.exports = ({ nexus }) => nexus.enumType({
5
+ name: "ReportReason",
6
+ description: 'Reason of abuse report',
7
+ members: {
8
+ ...getPluginService('common').getConfig('reportReasons', {})
9
+ },
10
+ })