strapi-plugin-comments 2.0.11 → 2.1.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.
- package/README.md +165 -119
- package/admin/src/components/ActionButton/styles.ts +11 -0
- package/admin/src/components/Avatar/index.tsx +31 -0
- package/admin/src/components/ConfirmationDialog/index.tsx +88 -0
- package/admin/src/components/DiscussionStatus/index.tsx +36 -0
- package/admin/src/components/DiscussionThread/index.tsx +97 -0
- package/admin/src/components/DiscussionThreadItem/index.tsx +71 -0
- package/admin/src/components/DiscussionThreadItem/{styles.js → styles.ts} +8 -6
- package/admin/src/components/DiscussionThreadItemActions/index.tsx +365 -0
- package/admin/src/components/DiscussionThreadItemActions/styles.ts +9 -0
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.tsx +99 -0
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.ts +8 -0
- package/admin/src/components/DiscussionThreadItemFooter/index.tsx +62 -0
- package/admin/src/components/DiscussionThreadItemFooter/styles.ts +15 -0
- package/admin/src/components/DiscussionThreadItemReviewAction/index.tsx +180 -0
- package/admin/src/components/FormSwitch/index.tsx +35 -0
- package/admin/src/components/FormSwitch/styles.ts +10 -0
- package/admin/src/components/IconButton/styles.ts +19 -0
- package/admin/src/components/Initializer/{index.js → index.tsx} +8 -6
- package/admin/src/components/LoadingIndicatorOverlay/index.tsx +19 -0
- package/admin/src/components/LoadingIndicatorOverlay/styles.ts +21 -0
- package/admin/src/components/Nav/index.tsx +61 -0
- package/admin/src/components/PluginIcon/{index.js → index.tsx} +4 -2
- package/admin/src/components/ReportsReviewModal/index.tsx +71 -0
- package/admin/src/components/ReportsReviewTable/index.tsx +233 -0
- package/admin/src/components/StatusBadge/index.tsx +21 -0
- package/admin/src/components/StatusBadge/styles.ts +19 -0
- package/admin/src/components/TableFilters/{index.js → index.tsx} +14 -9
- package/admin/src/components/TablePagination/{index.js → index.tsx} +8 -6
- package/admin/src/components/icons/comments.tsx +15 -0
- package/admin/src/components/icons/index.ts +6 -0
- package/admin/src/components/icons/{lock.js → lock.tsx} +17 -12
- package/admin/src/components/icons/review.tsx +25 -0
- package/admin/src/components/icons/unlock.tsx +25 -0
- package/admin/src/hooks/useConfig.ts +58 -0
- package/admin/src/{index.js → index.ts} +26 -22
- package/admin/src/pages/App/index.tsx +67 -0
- package/admin/src/pages/App/reducer/actions.ts +10 -0
- package/admin/src/pages/App/reducer/constants.ts +4 -0
- package/admin/src/pages/App/reducer/{index.js → index.ts} +8 -6
- package/admin/src/pages/App/reducer/init.ts +9 -0
- package/admin/src/pages/App/reducer/selectors.ts +32 -0
- package/admin/src/pages/App/utils/{api.js → api.ts} +3 -1
- package/admin/src/pages/ComingSoonPage/index.tsx +31 -0
- package/admin/src/pages/Details/components/DetailsEntity/index.tsx +106 -0
- package/admin/src/pages/Details/components/DetailsFilters/index.tsx +43 -0
- package/admin/src/pages/Details/components/DetailsFilters/styles.ts +9 -0
- package/admin/src/pages/Details/index.tsx +169 -0
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.tsx +252 -0
- package/admin/src/pages/Discover/components/DiscoverTableRow/styles.ts +9 -0
- package/admin/src/pages/Discover/index.tsx +230 -0
- package/admin/src/pages/Discover/utils/api.ts +22 -0
- package/admin/src/pages/Discover/utils/filtersSchema.ts +9 -0
- package/admin/src/pages/Settings/components/RestartAlert/styles.ts +10 -0
- package/admin/src/pages/Settings/index.tsx +602 -0
- package/admin/src/pages/Settings/utils/{api.js → api.ts} +16 -5
- package/admin/src/pages/utils/api.ts +70 -0
- package/admin/src/permissions.ts +30 -0
- package/admin/src/pluginId.ts +3 -0
- package/admin/src/reducers.ts +8 -0
- package/admin/src/translations/en.json +131 -131
- package/admin/src/translations/pt-BR.json +130 -130
- package/admin/src/utils/{axiosInstance.js → axiosInstance.ts} +12 -9
- package/admin/src/utils/constants.ts +25 -0
- package/admin/src/utils/getApiUrl.ts +5 -0
- package/admin/src/utils/getMessage.ts +29 -0
- package/admin/src/utils/getRelatedGroups.ts +6 -0
- package/admin/src/utils/getUrl.ts +5 -0
- package/admin/src/utils/handleAPIError.ts +21 -0
- package/admin/src/utils/index.ts +11 -0
- package/admin/src/utils/parseRegExp.ts +9 -0
- package/admin/src/utils/renderEntryTitle.ts +16 -0
- package/admin/src/utils/renderInitials.ts +10 -0
- package/admin/src/utils/resolveCommentStatus.ts +37 -0
- package/admin/src/utils/resolveCommentStatusColor.ts +22 -0
- package/build/README.md +41 -5
- package/build/admin/src/components/ActionButton/styles.d.ts +1 -1
- package/build/admin/src/components/ActionButton/styles.js +5 -7
- package/build/admin/src/components/Avatar/index.d.ts +12 -0
- package/build/admin/src/components/Avatar/index.js +26 -0
- package/build/admin/src/components/ConfirmationDialog/index.js +23 -90
- package/build/admin/src/components/DiscussionStatus/index.js +13 -27
- package/build/admin/src/components/DiscussionThread/index.js +29 -83
- package/build/admin/src/components/DiscussionThreadItem/index.js +20 -59
- package/build/admin/src/components/DiscussionThreadItem/styles.d.ts +1 -1
- package/build/admin/src/components/DiscussionThreadItem/styles.js +8 -17
- package/build/admin/src/components/DiscussionThreadItemActions/index.js +163 -383
- package/build/admin/src/components/DiscussionThreadItemActions/styles.d.ts +1 -1
- package/build/admin/src/components/DiscussionThreadItemActions/styles.js +5 -9
- package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +52 -85
- package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.d.ts +1 -1
- package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +5 -8
- package/build/admin/src/components/DiscussionThreadItemFooter/index.js +27 -61
- package/build/admin/src/components/DiscussionThreadItemFooter/styles.d.ts +1 -1
- package/build/admin/src/components/DiscussionThreadItemFooter/styles.js +7 -14
- package/build/admin/src/components/DiscussionThreadItemReviewAction/index.js +91 -207
- package/build/admin/src/components/FormSwitch/index.d.ts +5 -9
- package/build/admin/src/components/FormSwitch/index.js +8 -32
- package/build/admin/src/components/FormSwitch/styles.d.ts +1 -1
- package/build/admin/src/components/FormSwitch/styles.js +5 -7
- package/build/admin/src/components/IconButton/styles.d.ts +1 -1
- package/build/admin/src/components/IconButton/styles.js +7 -13
- package/build/admin/src/components/Initializer/index.d.ts +4 -2
- package/build/admin/src/components/Initializer/index.js +7 -7
- package/build/admin/src/components/LoadingIndicatorOverlay/index.d.ts +1 -1
- package/build/admin/src/components/LoadingIndicatorOverlay/index.js +6 -12
- package/build/admin/src/components/LoadingIndicatorOverlay/styles.d.ts +1 -1
- package/build/admin/src/components/LoadingIndicatorOverlay/styles.js +7 -14
- package/build/admin/src/components/Nav/index.js +16 -62
- package/build/admin/src/components/PluginIcon/index.d.ts +1 -1
- package/build/admin/src/components/PluginIcon/index.js +5 -8
- package/build/admin/src/components/ReportsReviewModal/index.js +23 -62
- package/build/admin/src/components/ReportsReviewTable/index.js +112 -293
- package/build/admin/src/components/StatusBadge/index.d.ts +5 -9
- package/build/admin/src/components/StatusBadge/index.js +6 -16
- package/build/admin/src/components/StatusBadge/styles.d.ts +1 -1
- package/build/admin/src/components/StatusBadge/styles.js +5 -7
- package/build/admin/src/components/TableFilters/index.js +38 -91
- package/build/admin/src/components/TablePagination/index.d.ts +13 -11
- package/build/admin/src/components/TablePagination/index.js +19 -31
- package/build/admin/src/components/icons/comments.d.ts +4 -7
- package/build/admin/src/components/icons/comments.js +7 -18
- package/build/admin/src/components/icons/index.d.ts +1 -1
- package/build/admin/src/components/icons/index.js +5 -11
- package/build/admin/src/components/icons/lock.d.ts +5 -9
- package/build/admin/src/components/icons/lock.js +7 -24
- package/build/admin/src/components/icons/review.d.ts +5 -9
- package/build/admin/src/components/icons/review.js +7 -26
- package/build/admin/src/components/icons/unlock.d.ts +5 -9
- package/build/admin/src/components/icons/unlock.js +7 -24
- package/build/admin/src/hooks/useConfig.js +34 -42
- package/build/admin/src/index.js +84 -121
- package/build/admin/src/pages/App/index.js +23 -66
- package/build/admin/src/pages/App/reducer/actions.d.ts +4 -4
- package/build/admin/src/pages/App/reducer/actions.js +3 -3
- package/build/admin/src/pages/App/reducer/constants.d.ts +1 -1
- package/build/admin/src/pages/App/reducer/constants.js +1 -1
- package/build/admin/src/pages/App/reducer/index.d.ts +5 -10
- package/build/admin/src/pages/App/reducer/index.js +16 -19
- package/build/admin/src/pages/App/reducer/init.d.ts +1 -1
- package/build/admin/src/pages/App/reducer/init.js +4 -4
- package/build/admin/src/pages/App/reducer/selectors.d.ts +1 -1
- package/build/admin/src/pages/App/reducer/selectors.js +6 -8
- package/build/admin/src/pages/App/utils/api.js +8 -9
- package/build/admin/src/pages/ComingSoonPage/index.js +27 -62
- package/build/admin/src/pages/Details/components/DetailsEntity/index.js +39 -115
- package/build/admin/src/pages/Details/components/DetailsFilters/index.js +13 -33
- package/build/admin/src/pages/Details/components/DetailsFilters/styles.d.ts +1 -1
- package/build/admin/src/pages/Details/components/DetailsFilters/styles.js +5 -7
- package/build/admin/src/pages/Details/index.js +64 -183
- package/build/admin/src/pages/Discover/components/DiscoverTableRow/index.js +139 -314
- package/build/admin/src/pages/Discover/components/DiscoverTableRow/styles.d.ts +1 -1
- package/build/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +5 -7
- package/build/admin/src/pages/Discover/index.js +98 -298
- package/build/admin/src/pages/Discover/utils/api.js +8 -15
- package/build/admin/src/pages/Discover/utils/filtersSchema.d.ts +8 -8
- package/build/admin/src/pages/Discover/utils/filtersSchema.js +6 -6
- package/build/admin/src/pages/Settings/components/RestartAlert/styles.d.ts +1 -1
- package/build/admin/src/pages/Settings/components/RestartAlert/styles.js +5 -7
- package/build/admin/src/pages/Settings/index.js +192 -678
- package/build/admin/src/pages/Settings/utils/api.js +44 -59
- package/build/admin/src/pages/utils/api.js +26 -51
- package/build/admin/src/permissions.d.ts +25 -25
- package/build/admin/src/permissions.js +28 -60
- package/build/admin/src/pluginId.d.ts +1 -1
- package/build/admin/src/pluginId.js +20 -41
- package/build/admin/src/reducers.d.ts +4 -9
- package/build/admin/src/reducers.js +5 -7
- package/build/admin/src/translations/fr.json +132 -1
- package/build/admin/src/utils/axiosInstance.js +15 -23
- package/build/admin/src/utils/constants.d.ts +17 -17
- package/build/admin/src/utils/constants.js +16 -20
- package/build/admin/src/utils/getApiUrl.d.ts +1 -1
- package/build/admin/src/utils/getApiUrl.js +1 -1
- package/build/admin/src/utils/getMessage.js +13 -17
- package/build/admin/src/utils/getRelatedGroups.js +2 -3
- package/build/admin/src/utils/getUrl.d.ts +1 -1
- package/build/admin/src/utils/getUrl.js +1 -1
- package/build/admin/src/utils/handleAPIError.js +12 -15
- package/build/admin/src/utils/index.js +16 -84
- package/build/admin/src/utils/parseRegExp.d.ts +3 -3
- package/build/admin/src/utils/parseRegExp.js +6 -6
- package/build/admin/src/utils/renderEntryTitle.js +7 -10
- package/build/admin/src/utils/renderInitials.d.ts +1 -1
- package/build/admin/src/utils/renderInitials.js +2 -3
- package/build/admin/src/utils/resolveCommentStatus.js +19 -25
- package/build/admin/src/utils/resolveCommentStatusColor.js +15 -15
- package/build/content-types/comment.d.ts +87 -87
- package/build/content-types/comment.js +87 -87
- package/build/content-types/index.d.ts +136 -136
- package/build/content-types/index.js +10 -12
- package/build/content-types/report.d.ts +41 -41
- package/build/content-types/report.js +41 -41
- package/build/package.json +5 -5
- package/build/permissions.d.ts +14 -14
- package/build/permissions.js +14 -14
- package/build/server/bootstrap.js +52 -58
- package/build/server/config/index.js +13 -13
- package/build/server/controllers/admin.js +128 -117
- package/build/server/controllers/client.js +15 -4
- package/build/server/controllers/index.js +6 -8
- package/build/server/controllers/utils/functions.d.ts +1 -1
- package/build/server/controllers/utils/parsers.d.ts +5 -10
- package/build/server/controllers/utils/parsers.js +46 -20
- package/build/server/destroy.d.ts +1 -1
- package/build/server/destroy.js +3 -2
- package/build/server/graphql/index.js +19 -29
- package/build/server/graphql/mutations/createAbuseReport.js +19 -23
- package/build/server/graphql/mutations/createComment.d.ts +1 -1
- package/build/server/graphql/mutations/createComment.js +19 -22
- package/build/server/graphql/mutations/index.js +19 -21
- package/build/server/graphql/mutations/removeComment.d.ts +1 -1
- package/build/server/graphql/mutations/removeComment.js +19 -23
- package/build/server/graphql/mutations/updateComment.d.ts +1 -1
- package/build/server/graphql/mutations/updateComment.js +19 -23
- package/build/server/graphql/queries/findAllFlat.d.ts +1 -1
- package/build/server/graphql/queries/findAllFlat.js +30 -40
- package/build/server/graphql/queries/findAllInHierarchy.d.ts +1 -2
- package/build/server/graphql/queries/findAllInHierarchy.js +25 -32
- package/build/server/graphql/queries/index.js +17 -19
- package/build/server/graphql/resolvers-config.js +10 -10
- package/build/server/graphql/types/comment-author.js +7 -8
- package/build/server/graphql/types/comment-nested.js +14 -15
- package/build/server/graphql/types/comment.js +13 -14
- package/build/server/graphql/types/create-comment-author.js +7 -8
- package/build/server/graphql/types/create-comment.js +7 -8
- package/build/server/graphql/types/create-report.js +7 -8
- package/build/server/graphql/types/id.js +13 -14
- package/build/server/graphql/types/identify-comment-author.js +4 -5
- package/build/server/graphql/types/index.js +21 -27
- package/build/server/graphql/types/remove-comment.js +6 -7
- package/build/server/graphql/types/report-reason.js +9 -9
- package/build/server/graphql/types/report.js +9 -10
- package/build/server/graphql/types/response-find-all.js +5 -6
- package/build/server/graphql/types/response-meta.js +4 -5
- package/build/server/graphql/types/response-pagination.js +9 -10
- package/build/server/graphql/types/update-comment.js +7 -8
- package/build/server/register.d.ts +1 -1
- package/build/server/register.js +3 -2
- package/build/server/routes/admin.d.ts +1 -1
- package/build/server/routes/admin.js +99 -99
- package/build/server/routes/client.d.ts +1 -1
- package/build/server/routes/client.js +79 -43
- package/build/server/routes/index.d.ts +4 -4
- package/build/server/routes/index.js +12 -14
- package/build/server/services/admin.js +257 -284
- package/build/server/services/client.js +54 -42
- package/build/server/services/common.js +33 -11
- package/build/server/services/graphql.js +113 -124
- package/build/server/services/utils/functions.d.ts +1 -1
- package/build/server/services/utils/functions.js +76 -109
- package/build/server/utils/constants.js +13 -14
- package/build/server/utils/error.d.ts +12 -16
- package/build/server/utils/error.js +23 -23
- package/build/server/utils/functions.d.ts +4 -12
- package/build/server/utils/functions.js +20 -34
- package/build/strapi-admin.js +4 -6
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/contentTypes.d.ts +7 -5
- package/content-types/comment.ts +93 -0
- package/content-types/index.ts +11 -0
- package/content-types/report.ts +50 -0
- package/jest.config.ts +22 -0
- package/package.json +45 -11
- package/permissions.ts +17 -0
- package/server/{bootstrap.js → bootstrap.ts} +12 -11
- package/server/config/index.ts +19 -0
- package/server/controllers/admin.ts +194 -0
- package/server/controllers/client.ts +220 -0
- package/server/controllers/index.ts +13 -0
- package/server/controllers/utils/functions.ts +27 -0
- package/server/controllers/utils/parsers.ts +59 -0
- package/server/destroy.ts +3 -0
- package/server/graphql/index.ts +27 -0
- package/server/graphql/mutations/createAbuseReport.ts +38 -0
- package/server/graphql/mutations/createComment.ts +41 -0
- package/server/graphql/mutations/index.ts +26 -0
- package/server/graphql/mutations/removeComment.ts +41 -0
- package/server/graphql/mutations/updateComment.ts +40 -0
- package/server/graphql/queries/findAllFlat.ts +58 -0
- package/server/graphql/queries/findAllInHierarchy.ts +47 -0
- package/server/graphql/queries/index.ts +22 -0
- package/server/graphql/resolvers-config.ts +13 -0
- package/server/graphql/types/comment-author.ts +12 -0
- package/server/graphql/types/comment-nested.ts +19 -0
- package/server/graphql/types/comment.ts +18 -0
- package/server/graphql/types/create-comment-author.ts +12 -0
- package/server/graphql/types/create-comment.ts +12 -0
- package/server/graphql/types/create-report.ts +12 -0
- package/server/graphql/types/id.ts +28 -0
- package/server/graphql/types/identify-comment-author.ts +9 -0
- package/server/graphql/types/index.ts +38 -0
- package/server/graphql/types/remove-comment.ts +11 -0
- package/server/graphql/types/report-reason.ts +12 -0
- package/server/graphql/types/report.ts +14 -0
- package/server/graphql/types/response-find-all.ts +10 -0
- package/server/graphql/types/response-meta.ts +9 -0
- package/server/graphql/types/response-pagination.ts +14 -0
- package/server/graphql/types/update-comment.ts +12 -0
- package/server/index.ts +20 -0
- package/server/register.ts +3 -0
- package/server/routes/admin.ts +118 -0
- package/server/routes/client.ts +95 -0
- package/server/routes/index.ts +25 -0
- package/server/services/admin.ts +406 -0
- package/server/services/client.ts +394 -0
- package/server/services/common.ts +503 -0
- package/server/services/{graphql.js → graphql.ts} +72 -43
- package/server/services/index.ts +13 -0
- package/server/services/utils/functions.ts +150 -0
- package/server/utils/constants.ts +23 -0
- package/server/utils/error.ts +44 -0
- package/server/utils/functions.ts +55 -0
- package/strapi-admin.ts +5 -0
- package/strapi-server.ts +77 -0
- package/tsconfig.json +38 -0
- package/types/common.d.ts +1 -0
- package/types/config.d.ts +35 -0
- package/types/constants.d.ts +3 -0
- package/types/contentTypes.ts +56 -0
- package/types/controllers.d.ts +125 -0
- package/types/graphql.d.ts +24 -0
- package/types/index.d.ts +7 -0
- package/types/services.d.ts +166 -0
- package/__mocks__/initSetup.js +0 -108
- package/admin/src/components/ActionButton/styles.js +0 -10
- package/admin/src/components/ConfirmationDialog/index.js +0 -56
- package/admin/src/components/DiscussionStatus/index.js +0 -33
- package/admin/src/components/DiscussionThread/index.js +0 -62
- package/admin/src/components/DiscussionThreadItem/index.js +0 -57
- package/admin/src/components/DiscussionThreadItemActions/index.js +0 -231
- package/admin/src/components/DiscussionThreadItemActions/styles.js +0 -7
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +0 -80
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +0 -6
- package/admin/src/components/DiscussionThreadItemFooter/index.js +0 -47
- package/admin/src/components/DiscussionThreadItemFooter/styles.js +0 -13
- package/admin/src/components/DiscussionThreadItemReviewAction/index.js +0 -131
- package/admin/src/components/FormSwitch/index.js +0 -18
- package/admin/src/components/FormSwitch/styles.js +0 -8
- package/admin/src/components/IconButton/styles.js +0 -14
- package/admin/src/components/LoadingIndicatorOverlay/index.js +0 -15
- package/admin/src/components/LoadingIndicatorOverlay/styles.js +0 -20
- package/admin/src/components/Nav/index.js +0 -49
- package/admin/src/components/ReportsReviewModal/index.js +0 -48
- package/admin/src/components/ReportsReviewTable/index.js +0 -160
- package/admin/src/components/StatusBadge/index.js +0 -17
- package/admin/src/components/StatusBadge/styles.js +0 -17
- package/admin/src/components/icons/comments.js +0 -9
- package/admin/src/components/icons/index.js +0 -6
- package/admin/src/components/icons/review.js +0 -18
- package/admin/src/components/icons/unlock.js +0 -20
- package/admin/src/hooks/useConfig.js +0 -49
- package/admin/src/pages/App/index.js +0 -71
- package/admin/src/pages/App/reducer/actions.js +0 -8
- package/admin/src/pages/App/reducer/constants.js +0 -4
- package/admin/src/pages/App/reducer/init.js +0 -7
- package/admin/src/pages/App/reducer/selectors.js +0 -35
- package/admin/src/pages/ComingSoonPage/index.js +0 -25
- package/admin/src/pages/Details/components/DetailsEntity/index.js +0 -84
- package/admin/src/pages/Details/components/DetailsFilters/index.js +0 -35
- package/admin/src/pages/Details/components/DetailsFilters/styles.js +0 -8
- package/admin/src/pages/Details/index.js +0 -136
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +0 -180
- package/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +0 -8
- package/admin/src/pages/Discover/index.js +0 -173
- package/admin/src/pages/Discover/utils/api.js +0 -14
- package/admin/src/pages/Discover/utils/filtersSchema.js +0 -9
- package/admin/src/pages/Settings/components/RestartAlert/styles.js +0 -8
- package/admin/src/pages/Settings/index.js +0 -392
- package/admin/src/pages/utils/api.js +0 -53
- package/admin/src/permissions.js +0 -19
- package/admin/src/pluginId.js +0 -5
- package/admin/src/reducers.js +0 -8
- package/admin/src/utils/constants.js +0 -25
- package/admin/src/utils/getApiUrl.js +0 -5
- package/admin/src/utils/getMessage.js +0 -21
- package/admin/src/utils/getRelatedGroups.js +0 -3
- package/admin/src/utils/getUrl.js +0 -5
- package/admin/src/utils/handleAPIError.js +0 -16
- package/admin/src/utils/index.js +0 -11
- package/admin/src/utils/parseRegExp.js +0 -10
- package/admin/src/utils/renderEntryTitle.js +0 -14
- package/admin/src/utils/renderInitials.js +0 -5
- package/admin/src/utils/resolveCommentStatus.js +0 -30
- package/admin/src/utils/resolveCommentStatusColor.js +0 -22
- package/content-types/comment.js +0 -93
- package/content-types/index.js +0 -11
- package/content-types/report.js +0 -54
- package/jest.config.js +0 -7
- package/permissions.js +0 -19
- package/server/config/index.js +0 -17
- package/server/controllers/admin.js +0 -168
- package/server/controllers/client.js +0 -114
- package/server/controllers/index.js +0 -9
- package/server/controllers/utils/__tests__/functions.test.js +0 -43
- package/server/controllers/utils/__tests__/parsers.test.js +0 -94
- package/server/controllers/utils/functions.js +0 -19
- package/server/controllers/utils/parsers.js +0 -23
- package/server/destroy.js +0 -5
- package/server/graphql/index.js +0 -25
- package/server/graphql/mutations/createAbuseReport.js +0 -25
- package/server/graphql/mutations/createComment.js +0 -25
- package/server/graphql/mutations/index.js +0 -21
- package/server/graphql/mutations/removeComment.js +0 -25
- package/server/graphql/mutations/updateComment.js +0 -25
- package/server/graphql/queries/findAllFlat.js +0 -35
- package/server/graphql/queries/findAllInHierarchy.js +0 -31
- package/server/graphql/queries/index.js +0 -19
- package/server/graphql/resolvers-config.js +0 -13
- package/server/graphql/types/comment-author.js +0 -9
- package/server/graphql/types/comment-nested.js +0 -16
- package/server/graphql/types/comment.js +0 -15
- package/server/graphql/types/create-comment-author.js +0 -9
- package/server/graphql/types/create-comment.js +0 -9
- package/server/graphql/types/create-report.js +0 -9
- package/server/graphql/types/id.js +0 -24
- package/server/graphql/types/identify-comment-author.js +0 -6
- package/server/graphql/types/index.js +0 -19
- package/server/graphql/types/remove-comment.js +0 -8
- package/server/graphql/types/report-reason.js +0 -10
- package/server/graphql/types/report.js +0 -11
- package/server/graphql/types/response-find-all.js +0 -7
- package/server/graphql/types/response-meta.js +0 -6
- package/server/graphql/types/response-pagination.js +0 -11
- package/server/graphql/types/update-comment.js +0 -9
- package/server/index.js +0 -22
- package/server/register.js +0 -5
- package/server/routes/admin.js +0 -124
- package/server/routes/client.js +0 -52
- package/server/routes/index.js +0 -15
- package/server/services/__tests__/common.test.js +0 -399
- package/server/services/admin.js +0 -296
- package/server/services/client.js +0 -263
- package/server/services/common.js +0 -295
- package/server/services/index.js +0 -13
- package/server/services/utils/__tests__/functions.test.js +0 -53
- package/server/services/utils/functions.js +0 -112
- package/server/utils/__tests__/functions.test.js +0 -17
- package/server/utils/constants.js +0 -26
- package/server/utils/error.js +0 -24
- package/server/utils/functions.js +0 -19
- package/strapi-admin.js +0 -3
- package/strapi-server.js +0 -49
package/jest.config.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Config } from "@jest/types";
|
|
2
|
+
import { defaults as tsjPreset } from "ts-jest/presets";
|
|
3
|
+
|
|
4
|
+
const config: Config.InitialOptions = {
|
|
5
|
+
name: "Unit test",
|
|
6
|
+
testMatch: ["**/__tests__/?(*.)+(spec|test).ts"],
|
|
7
|
+
transform: {
|
|
8
|
+
...tsjPreset.transform,
|
|
9
|
+
},
|
|
10
|
+
preset: "ts-jest",
|
|
11
|
+
coverageDirectory: "./coverage/",
|
|
12
|
+
collectCoverage: true,
|
|
13
|
+
globals: {
|
|
14
|
+
"ts-jest": {
|
|
15
|
+
diagnostics: {
|
|
16
|
+
warnOnly: true,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default config;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strapi-plugin-comments",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Strapi - Comments plugin",
|
|
5
5
|
"strapi": {
|
|
6
6
|
"name": "comments",
|
|
@@ -10,30 +10,60 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"prepare": "husky install",
|
|
13
|
-
"publish:latest": "npm publish --tag latest",
|
|
14
|
-
"
|
|
13
|
+
"publish:latest": "cd build && npm publish --tag latest",
|
|
14
|
+
"prepublish:latest": "npm run clean && npm run build && node build/setup-package.js",
|
|
15
|
+
"build": "tsc && yarn copy-translations",
|
|
16
|
+
"build:dev": "yarn run build && cp ./package.json ./build",
|
|
17
|
+
"copy-translations": "copyfiles admin/src/translations/*.json build/",
|
|
18
|
+
"clean": "rm -rf build",
|
|
19
|
+
"develop": "nodemon --exec \"yarn build:dev\"",
|
|
20
|
+
"test:unit": "jest --verbose --coverage",
|
|
21
|
+
"lint": "prettier --check .",
|
|
22
|
+
"format": "prettier --write ."
|
|
15
23
|
},
|
|
16
24
|
"repository": {
|
|
17
25
|
"type": "git",
|
|
18
26
|
"url": "https://github.com/VirtusLab-Open-Source/strapi-plugin-comments"
|
|
19
27
|
},
|
|
20
28
|
"dependencies": {
|
|
21
|
-
"@strapi/utils": "^4.1.
|
|
22
|
-
"@strapi/plugin-graphql": "^4.1.
|
|
29
|
+
"@strapi/utils": "^4.1.8",
|
|
30
|
+
"@strapi/plugin-graphql": "^4.1.8",
|
|
23
31
|
"bad-words": "^3.0.4"
|
|
24
32
|
},
|
|
25
33
|
"devDependencies": {
|
|
34
|
+
"@types/bad-words": "^3.0.1",
|
|
35
|
+
"@types/jest": "^27.4.1",
|
|
26
36
|
"codecov": "^3.7.2",
|
|
27
|
-
"
|
|
28
|
-
"jest-cli": "^26.0.1",
|
|
29
|
-
"jest-styled-components": "^7.0.2",
|
|
30
|
-
"koa": "2.13.3",
|
|
37
|
+
"copyfiles": "^2.4.1",
|
|
31
38
|
"husky": "7.0.4",
|
|
32
|
-
"
|
|
39
|
+
"jest": "^27.5.1",
|
|
40
|
+
"jest-cli": "^27.5.1",
|
|
41
|
+
"jest-styled-components": "^7.0.8",
|
|
42
|
+
"koa": "2.13.3",
|
|
43
|
+
"nodemon": "^2.0.15",
|
|
44
|
+
"prettier": "^2.6.0",
|
|
45
|
+
"rimraf": "^3.0.2",
|
|
46
|
+
"ts-jest": "^27.1.3",
|
|
47
|
+
"ts-node": "^10.7.0",
|
|
48
|
+
"strapi-typed": "^1.0.9",
|
|
49
|
+
"typescript": "^4.6.3"
|
|
33
50
|
},
|
|
34
51
|
"peerDependencies": {
|
|
35
52
|
"@strapi/strapi": "4.x"
|
|
36
53
|
},
|
|
54
|
+
"nodemonConfig": {
|
|
55
|
+
"ignore": [
|
|
56
|
+
"./build/**/*",
|
|
57
|
+
"./__mocks__/*",
|
|
58
|
+
"./**/__tests__/*"
|
|
59
|
+
],
|
|
60
|
+
"ext": "js,json,ts"
|
|
61
|
+
},
|
|
62
|
+
"husky": {
|
|
63
|
+
"hooks": {
|
|
64
|
+
"pre-commit": "yarn format && yarn test:unit"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
37
67
|
"author": {
|
|
38
68
|
"name": "VirtusLab",
|
|
39
69
|
"email": "strapi@virtuslab.com",
|
|
@@ -55,6 +85,10 @@
|
|
|
55
85
|
"node": ">=14.x.x <=17.x.x",
|
|
56
86
|
"npm": ">=7.x.x"
|
|
57
87
|
},
|
|
58
|
-
"keywords": [
|
|
88
|
+
"keywords": [
|
|
89
|
+
"strapi",
|
|
90
|
+
"plugin",
|
|
91
|
+
"comments"
|
|
92
|
+
],
|
|
59
93
|
"license": "MIT"
|
|
60
94
|
}
|
package/permissions.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ToBeFixed } from "./types/common";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
render: (uid: ToBeFixed) => `plugin::comments.${uid}`,
|
|
5
|
+
comments: {
|
|
6
|
+
read: "read",
|
|
7
|
+
moderate: "moderate",
|
|
8
|
+
},
|
|
9
|
+
reports: {
|
|
10
|
+
read: "reports.read",
|
|
11
|
+
action: "reports.action",
|
|
12
|
+
},
|
|
13
|
+
settings: {
|
|
14
|
+
read: "settings.read",
|
|
15
|
+
change: "settings.change",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
module.exports = async ({ strapi }) => {
|
|
1
|
+
import { isEmpty } from "lodash";
|
|
2
|
+
import { StrapiContext } from "strapi-typed";
|
|
3
|
+
import { CommentsPluginConfig, IServiceCommon } from "../types";
|
|
4
|
+
import permissions from "./../permissions";
|
|
5
|
+
import { getPluginService } from "./utils/functions";
|
|
8
6
|
|
|
7
|
+
export = async ({ strapi }: StrapiContext) => {
|
|
9
8
|
// Provide GQL support
|
|
10
|
-
if (strapi.plugin(
|
|
11
|
-
const config = await getPluginService(
|
|
9
|
+
if (strapi.plugin("graphql")) {
|
|
10
|
+
const config: CommentsPluginConfig = await getPluginService<IServiceCommon>(
|
|
11
|
+
"common"
|
|
12
|
+
).getConfig();
|
|
12
13
|
const { enabledCollections } = config;
|
|
13
14
|
if (!isEmpty(enabledCollections)) {
|
|
14
|
-
await require(
|
|
15
|
+
await require("./graphql")({ strapi, config });
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
// Check if the plugin users-permissions is installed because the navigation needs it
|
|
19
20
|
if (Object.keys(strapi.plugins).indexOf("users-permissions") === -1) {
|
|
20
21
|
throw new Error(
|
|
21
|
-
"In order to make the comments plugin work the users-permissions plugin is required"
|
|
22
|
+
"In order to make the comments plugin work the users-permissions plugin is required"
|
|
22
23
|
);
|
|
23
24
|
}
|
|
24
25
|
// Add permissions
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { StrapiConfig } from "../../types";
|
|
2
|
+
|
|
3
|
+
const config: StrapiConfig = {
|
|
4
|
+
default: {
|
|
5
|
+
enabledCollections: [],
|
|
6
|
+
moderatorRoles: [],
|
|
7
|
+
approvalFlow: [],
|
|
8
|
+
entryLabel: {
|
|
9
|
+
"*": ["Title", "title", "Name", "name", "Subject", "subject"],
|
|
10
|
+
},
|
|
11
|
+
reportReasons: {
|
|
12
|
+
BAD_LANGUAGE: "BAD_LANGUAGE",
|
|
13
|
+
DISCRIMINATION: "DISCRIMINATION",
|
|
14
|
+
OTHER: "OTHER",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default config;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { StrapiRequestContext } from "strapi-typed";
|
|
2
|
+
import {
|
|
3
|
+
AdminFindAllProps,
|
|
4
|
+
AdminFindOneAndThreadProps,
|
|
5
|
+
AdminPaginatedResponse,
|
|
6
|
+
AdminSinglePageResponse,
|
|
7
|
+
Comment,
|
|
8
|
+
CommentReport,
|
|
9
|
+
IControllerAdmin,
|
|
10
|
+
IServiceAdmin,
|
|
11
|
+
SettingsCommentsPluginConfig,
|
|
12
|
+
ThrowablePromisedResponse,
|
|
13
|
+
ToBeFixed,
|
|
14
|
+
ViewCommentsPluginConfig,
|
|
15
|
+
} from "../../types";
|
|
16
|
+
|
|
17
|
+
import { assertNotEmpty, getPluginService } from "./../utils/functions";
|
|
18
|
+
import { parseParams, throwError } from "./utils/functions";
|
|
19
|
+
|
|
20
|
+
const controllers: IControllerAdmin = {
|
|
21
|
+
getService<T>(name = "admin") {
|
|
22
|
+
return getPluginService<T>(name);
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
async config(
|
|
26
|
+
ctx: StrapiRequestContext<never>
|
|
27
|
+
): ThrowablePromisedResponse<ViewCommentsPluginConfig> {
|
|
28
|
+
try {
|
|
29
|
+
return await this.getService<IServiceAdmin>().config<ViewCommentsPluginConfig>();
|
|
30
|
+
} catch (e) {
|
|
31
|
+
throw throwError(ctx, e);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
async settingsConfig(
|
|
36
|
+
ctx: StrapiRequestContext<never>
|
|
37
|
+
): ThrowablePromisedResponse<SettingsCommentsPluginConfig> {
|
|
38
|
+
try {
|
|
39
|
+
return this.getService<IServiceAdmin>().config<SettingsCommentsPluginConfig>(
|
|
40
|
+
true
|
|
41
|
+
);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
throw throwError(ctx, e);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
async settingsUpdateConfig(
|
|
48
|
+
ctx: StrapiRequestContext<SettingsCommentsPluginConfig>
|
|
49
|
+
): ThrowablePromisedResponse<SettingsCommentsPluginConfig> {
|
|
50
|
+
try {
|
|
51
|
+
const {
|
|
52
|
+
request: { body },
|
|
53
|
+
} = ctx;
|
|
54
|
+
|
|
55
|
+
assertNotEmpty<SettingsCommentsPluginConfig>(body);
|
|
56
|
+
|
|
57
|
+
return this.getService<IServiceAdmin>().updateConfig(body);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
throw throwError(ctx, e);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
async settingsRestoreConfig(
|
|
64
|
+
ctx: StrapiRequestContext<never>
|
|
65
|
+
): ThrowablePromisedResponse<SettingsCommentsPluginConfig> {
|
|
66
|
+
try {
|
|
67
|
+
return this.getService<IServiceAdmin>().restoreConfig();
|
|
68
|
+
} catch (e) {
|
|
69
|
+
throw throwError(ctx, e);
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
async settingsRestart(
|
|
74
|
+
ctx: StrapiRequestContext<never>
|
|
75
|
+
): ThrowablePromisedResponse<any> {
|
|
76
|
+
try {
|
|
77
|
+
await this.getService<IServiceAdmin>().restart();
|
|
78
|
+
return ctx.send({ status: 200 });
|
|
79
|
+
} catch (e) {
|
|
80
|
+
throw throwError(ctx, e);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
async findAll(
|
|
85
|
+
ctx: StrapiRequestContext<never, AdminFindAllProps>
|
|
86
|
+
): Promise<AdminPaginatedResponse<Comment>> {
|
|
87
|
+
return this.getService<IServiceAdmin>().findAll(ctx.query);
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
async findOne(
|
|
91
|
+
ctx: StrapiRequestContext<never, AdminFindOneAndThreadProps>
|
|
92
|
+
): ThrowablePromisedResponse<AdminSinglePageResponse> {
|
|
93
|
+
const { params = {}, query } = ctx;
|
|
94
|
+
const { id }: ToBeFixed = parseParams(params);
|
|
95
|
+
try {
|
|
96
|
+
return await this.getService<IServiceAdmin>().findOneAndThread(id, query);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
throw throwError(ctx, e);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
async blockComment(
|
|
103
|
+
ctx: StrapiRequestContext<never>
|
|
104
|
+
): ThrowablePromisedResponse<Comment> {
|
|
105
|
+
const { params = {} } = ctx;
|
|
106
|
+
const { id } = parseParams(params);
|
|
107
|
+
try {
|
|
108
|
+
return await this.getService<IServiceAdmin>().blockComment(id, true);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
throw throwError(ctx, e);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
async unblockComment(
|
|
115
|
+
ctx: StrapiRequestContext<never>
|
|
116
|
+
): ThrowablePromisedResponse<Comment> {
|
|
117
|
+
const { params = {} } = ctx;
|
|
118
|
+
const { id } = parseParams(params);
|
|
119
|
+
try {
|
|
120
|
+
return await this.getService<IServiceAdmin>().blockComment(id, false);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
throw throwError(ctx, e);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
async blockCommentThread(
|
|
127
|
+
ctx: StrapiRequestContext<never>
|
|
128
|
+
): ThrowablePromisedResponse<Comment> {
|
|
129
|
+
const { params = {} } = ctx;
|
|
130
|
+
const { id } = parseParams(params);
|
|
131
|
+
try {
|
|
132
|
+
return await this.getService<IServiceAdmin>().blockCommentThread(
|
|
133
|
+
id,
|
|
134
|
+
true
|
|
135
|
+
);
|
|
136
|
+
} catch (e) {
|
|
137
|
+
throw throwError(ctx, e);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
async unblockCommentThread(
|
|
142
|
+
ctx: StrapiRequestContext<never>
|
|
143
|
+
): ThrowablePromisedResponse<Comment> {
|
|
144
|
+
const { params = {} } = ctx;
|
|
145
|
+
const { id } = parseParams(params);
|
|
146
|
+
try {
|
|
147
|
+
return await this.getService<IServiceAdmin>().blockCommentThread(
|
|
148
|
+
id,
|
|
149
|
+
false
|
|
150
|
+
);
|
|
151
|
+
} catch (e) {
|
|
152
|
+
throw throwError(ctx, e);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
async resolveAbuseReport(
|
|
157
|
+
ctx: StrapiRequestContext<never>
|
|
158
|
+
): ThrowablePromisedResponse<CommentReport> {
|
|
159
|
+
const { params = {} } = ctx;
|
|
160
|
+
const { id: commentId, reportId } = parseParams(params);
|
|
161
|
+
try {
|
|
162
|
+
return await this.getService<IServiceAdmin>().resolveAbuseReport(
|
|
163
|
+
reportId,
|
|
164
|
+
commentId
|
|
165
|
+
);
|
|
166
|
+
} catch (e) {
|
|
167
|
+
throw throwError(ctx, e);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
async approveComment(
|
|
172
|
+
ctx: StrapiRequestContext<never>
|
|
173
|
+
): ThrowablePromisedResponse<Comment> {
|
|
174
|
+
const { id } = parseParams(ctx.params || {});
|
|
175
|
+
try {
|
|
176
|
+
return await this.getService<IServiceAdmin>().approveComment(id);
|
|
177
|
+
} catch (e) {
|
|
178
|
+
throw throwError(ctx, e);
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
async rejectComment(
|
|
183
|
+
ctx: StrapiRequestContext<never>
|
|
184
|
+
): ThrowablePromisedResponse<Comment> {
|
|
185
|
+
const { id } = parseParams(ctx.params || {});
|
|
186
|
+
try {
|
|
187
|
+
return await this.getService<IServiceAdmin>().rejectComment(id);
|
|
188
|
+
} catch (e) {
|
|
189
|
+
throw throwError(ctx, e);
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export default controllers;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Comment,
|
|
3
|
+
CommentReport,
|
|
4
|
+
CreateCommentPayload,
|
|
5
|
+
CreateCommentReportPayload,
|
|
6
|
+
IControllerClient,
|
|
7
|
+
Id,
|
|
8
|
+
IServiceClient,
|
|
9
|
+
IServiceCommon,
|
|
10
|
+
ThrowablePromisedResponse,
|
|
11
|
+
ToBeFixed,
|
|
12
|
+
UpdateCommentPayload,
|
|
13
|
+
} from "../../types";
|
|
14
|
+
import { StrapiRequestContext, StrapiPaginatedResponse } from "strapi-typed";
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
assertNotEmpty,
|
|
18
|
+
assertParamsPresent,
|
|
19
|
+
getPluginService,
|
|
20
|
+
} from "./../utils/functions";
|
|
21
|
+
import { parseParams, throwError } from "./utils/functions";
|
|
22
|
+
import { flatInput } from "./utils/parsers";
|
|
23
|
+
import PluginError from "../utils/error";
|
|
24
|
+
|
|
25
|
+
const controllers: IControllerClient = {
|
|
26
|
+
getService(name = "client") {
|
|
27
|
+
return getPluginService(name);
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
async findAllFlat(
|
|
31
|
+
this: IControllerClient,
|
|
32
|
+
ctx: StrapiRequestContext<never, ToBeFixed>
|
|
33
|
+
): ThrowablePromisedResponse<StrapiPaginatedResponse<Comment>> {
|
|
34
|
+
const { params = {}, query, sort, pagination } = ctx;
|
|
35
|
+
const { relation } = parseParams<{ relation: string }>(params);
|
|
36
|
+
|
|
37
|
+
const {
|
|
38
|
+
sort: querySort,
|
|
39
|
+
pagination: queryPagination,
|
|
40
|
+
fields,
|
|
41
|
+
...filterQuery
|
|
42
|
+
} = query || {};
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
assertParamsPresent<{ relation: string }>(params, ["relation"]);
|
|
46
|
+
|
|
47
|
+
return this.getService<IServiceCommon>("common").findAllFlat(
|
|
48
|
+
flatInput({
|
|
49
|
+
relation,
|
|
50
|
+
query: filterQuery,
|
|
51
|
+
sort: sort || querySort,
|
|
52
|
+
pagination: pagination || queryPagination,
|
|
53
|
+
fields,
|
|
54
|
+
})
|
|
55
|
+
);
|
|
56
|
+
} catch (e: ToBeFixed) {
|
|
57
|
+
throw throwError(ctx, e);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
async findAllInHierarchy(
|
|
62
|
+
this: IControllerClient,
|
|
63
|
+
ctx: StrapiRequestContext<never, ToBeFixed>
|
|
64
|
+
): ThrowablePromisedResponse<Array<Comment>> {
|
|
65
|
+
const { params, query, sort } = ctx;
|
|
66
|
+
const { relation } = parseParams<{ relation: string }>(params);
|
|
67
|
+
|
|
68
|
+
const { sort: querySort, fields, ...filterQuery } = query || {};
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
assertParamsPresent<{ relation: string }>(params, ["relation"]);
|
|
72
|
+
|
|
73
|
+
return await this.getService<IServiceCommon>("common").findAllInHierarchy(
|
|
74
|
+
{
|
|
75
|
+
...flatInput<Comment>({
|
|
76
|
+
relation,
|
|
77
|
+
query: filterQuery,
|
|
78
|
+
sort: sort || querySort,
|
|
79
|
+
fields,
|
|
80
|
+
}),
|
|
81
|
+
dropBlockedThreads: true,
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
} catch (e: ToBeFixed) {
|
|
85
|
+
throw throwError(ctx, e);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
async post(
|
|
90
|
+
this: IControllerClient,
|
|
91
|
+
ctx: StrapiRequestContext<CreateCommentPayload>
|
|
92
|
+
): ThrowablePromisedResponse<Comment> {
|
|
93
|
+
const { request, params, state = {} } = ctx;
|
|
94
|
+
const { relation } = parseParams<{
|
|
95
|
+
relation: string;
|
|
96
|
+
}>(params);
|
|
97
|
+
const { user } = state;
|
|
98
|
+
const { body } = request;
|
|
99
|
+
try {
|
|
100
|
+
assertParamsPresent<{ relation: string }>(params, ["relation"]);
|
|
101
|
+
assertNotEmpty<CreateCommentPayload>(body);
|
|
102
|
+
|
|
103
|
+
const entity = await this.getService<IServiceClient>().create(
|
|
104
|
+
relation,
|
|
105
|
+
body,
|
|
106
|
+
user
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
if (entity) {
|
|
110
|
+
return entity;
|
|
111
|
+
}
|
|
112
|
+
throw new PluginError(400, "Comment hasn't been created");
|
|
113
|
+
} catch (e: ToBeFixed) {
|
|
114
|
+
throw throwError(ctx, e);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
async put(
|
|
119
|
+
this: IControllerClient,
|
|
120
|
+
ctx: StrapiRequestContext<UpdateCommentPayload>
|
|
121
|
+
): ThrowablePromisedResponse<Comment> {
|
|
122
|
+
const { request, state, params = {} } = ctx;
|
|
123
|
+
const { body } = request;
|
|
124
|
+
const { user } = state;
|
|
125
|
+
const { commentId, relation } = parseParams<{
|
|
126
|
+
relation: string;
|
|
127
|
+
commentId: Id;
|
|
128
|
+
}>(params);
|
|
129
|
+
try {
|
|
130
|
+
assertParamsPresent<{
|
|
131
|
+
relation: string;
|
|
132
|
+
commentId: Id;
|
|
133
|
+
}>(params, ["commentId", "relation"]);
|
|
134
|
+
assertNotEmpty<UpdateCommentPayload>(body);
|
|
135
|
+
|
|
136
|
+
return await this.getService<IServiceClient>().update(
|
|
137
|
+
commentId,
|
|
138
|
+
relation,
|
|
139
|
+
body,
|
|
140
|
+
user
|
|
141
|
+
);
|
|
142
|
+
} catch (e: ToBeFixed) {
|
|
143
|
+
throw throwError(ctx, e);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
async reportAbuse(
|
|
148
|
+
this: IControllerClient,
|
|
149
|
+
ctx: StrapiRequestContext<CreateCommentReportPayload>
|
|
150
|
+
): ThrowablePromisedResponse<CommentReport> {
|
|
151
|
+
const { request, state, params = {} } = ctx;
|
|
152
|
+
const { body } = request;
|
|
153
|
+
const { user } = state;
|
|
154
|
+
const { relation, commentId } = parseParams<{
|
|
155
|
+
relation: string;
|
|
156
|
+
commentId: Id;
|
|
157
|
+
}>(params);
|
|
158
|
+
|
|
159
|
+
try {
|
|
160
|
+
assertParamsPresent(params, ["commentId", "relation"]);
|
|
161
|
+
assertNotEmpty<CreateCommentReportPayload>(body);
|
|
162
|
+
|
|
163
|
+
if (!body.content) {
|
|
164
|
+
throw new PluginError(400, "Content field is required");
|
|
165
|
+
}
|
|
166
|
+
return await this.getService<IServiceClient>().reportAbuse(
|
|
167
|
+
commentId,
|
|
168
|
+
relation,
|
|
169
|
+
body,
|
|
170
|
+
user
|
|
171
|
+
);
|
|
172
|
+
} catch (e) {
|
|
173
|
+
throw throwError(ctx, e);
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
async removeComment(
|
|
178
|
+
this: IControllerClient,
|
|
179
|
+
ctx: StrapiRequestContext<never>
|
|
180
|
+
): ThrowablePromisedResponse<Comment> {
|
|
181
|
+
const {
|
|
182
|
+
params,
|
|
183
|
+
query,
|
|
184
|
+
state: { user },
|
|
185
|
+
} = ctx;
|
|
186
|
+
|
|
187
|
+
const { relation, commentId } = parseParams<{
|
|
188
|
+
relation: string;
|
|
189
|
+
commentId: Id;
|
|
190
|
+
}>(params);
|
|
191
|
+
const { authorId } = parseParams(query);
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
assertParamsPresent<{
|
|
195
|
+
relation: string;
|
|
196
|
+
commentId: Id;
|
|
197
|
+
}>(params, ["commentId", "relation"]);
|
|
198
|
+
assertParamsPresent<{
|
|
199
|
+
authorId: Id;
|
|
200
|
+
}>(query, ["authorId"]);
|
|
201
|
+
|
|
202
|
+
if (authorId || user?.id) {
|
|
203
|
+
return await this.getService<IServiceClient>().markAsRemoved(
|
|
204
|
+
commentId,
|
|
205
|
+
relation,
|
|
206
|
+
authorId,
|
|
207
|
+
user
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
return new PluginError(400, "Not provided authorId");
|
|
211
|
+
} catch (e: ToBeFixed) {
|
|
212
|
+
if (!e.isBoom) {
|
|
213
|
+
throwError(ctx, e);
|
|
214
|
+
}
|
|
215
|
+
throw e;
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export default controllers;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import adminController from "./admin";
|
|
2
|
+
import clientController from "./client";
|
|
3
|
+
|
|
4
|
+
type PluginControllers = {
|
|
5
|
+
[key: string]: Function | Object;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const controllers: PluginControllers = {
|
|
9
|
+
admin: adminController,
|
|
10
|
+
client: clientController,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default controllers;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Id, StringMap, StrapiRequestContext } from "strapi-typed";
|
|
2
|
+
|
|
3
|
+
import PluginError from "../../utils/error";
|
|
4
|
+
|
|
5
|
+
type ParseResponse = StringMap<string | number | Id>;
|
|
6
|
+
|
|
7
|
+
export const parseParams = <T extends ParseResponse>(
|
|
8
|
+
params: StringMap<string | number>
|
|
9
|
+
) =>
|
|
10
|
+
Object.keys(params).reduce((prev, curr): T => {
|
|
11
|
+
const value = params[curr];
|
|
12
|
+
const parsedValue = Number(value);
|
|
13
|
+
return {
|
|
14
|
+
...prev,
|
|
15
|
+
[curr]: isNaN(parsedValue) ? value : parsedValue,
|
|
16
|
+
};
|
|
17
|
+
}, {} as T);
|
|
18
|
+
|
|
19
|
+
export const throwError = <T extends {} = never>(
|
|
20
|
+
ctx: StrapiRequestContext<T>,
|
|
21
|
+
e: PluginError | Error | unknown
|
|
22
|
+
): PluginError | Error | unknown | never => {
|
|
23
|
+
if (e instanceof PluginError) {
|
|
24
|
+
return ctx.throw(e.status, JSON.stringify(e));
|
|
25
|
+
}
|
|
26
|
+
return e;
|
|
27
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { OnlyStrings } from "strapi-typed";
|
|
2
|
+
import { FlatInput, ToBeFixed } from "../../../types";
|
|
3
|
+
|
|
4
|
+
export const flatInput = <T, TKeys = keyof T>(
|
|
5
|
+
payload: FlatInput<OnlyStrings<TKeys>>
|
|
6
|
+
) => {
|
|
7
|
+
const { relation, query, sort, pagination, fields } = payload;
|
|
8
|
+
|
|
9
|
+
const { populate = {}, ...restQuery } = query;
|
|
10
|
+
const filters = restQuery?.filters || restQuery;
|
|
11
|
+
const orOperator = (filters?.$or || []).filter(
|
|
12
|
+
(_: ToBeFixed) => !Object.keys(_).includes("removed")
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
let basePopulate = {
|
|
16
|
+
...populate,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
let threadOfPopulate = {
|
|
20
|
+
threadOf: {
|
|
21
|
+
populate: {
|
|
22
|
+
authorUser: true,
|
|
23
|
+
...populate,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Cover case when someone wants to populate author instead of authorUser
|
|
29
|
+
if (populate.author) {
|
|
30
|
+
const { author, ...restPopulate } = populate;
|
|
31
|
+
basePopulate = {
|
|
32
|
+
...restPopulate,
|
|
33
|
+
authorUser: author,
|
|
34
|
+
};
|
|
35
|
+
threadOfPopulate = {
|
|
36
|
+
threadOf: {
|
|
37
|
+
populate: {
|
|
38
|
+
authorUser: author,
|
|
39
|
+
...restPopulate,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
query: {
|
|
47
|
+
...filters,
|
|
48
|
+
$or: [...orOperator, { removed: { $null: true } }, { removed: false }],
|
|
49
|
+
related: relation,
|
|
50
|
+
},
|
|
51
|
+
populate: {
|
|
52
|
+
...basePopulate,
|
|
53
|
+
...threadOfPopulate,
|
|
54
|
+
},
|
|
55
|
+
pagination,
|
|
56
|
+
sort,
|
|
57
|
+
fields,
|
|
58
|
+
};
|
|
59
|
+
};
|