From 7cce84b7f82611c3a63abcfd712c73bdc9bfe737 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 24 Sep 2018 14:25:48 -0600 Subject: [PATCH] feat: added dontAgree create/delete mutations --- .../server/graph/tenant/mutators/comment.ts | 12 ++++ .../server/graph/tenant/resolvers/mutation.ts | 8 +++ .../server/graph/tenant/schema/schema.graphql | 72 +++++++++++++++++++ src/core/server/services/comments/actions.ts | 32 +++++++++ 4 files changed, 124 insertions(+) diff --git a/src/core/server/graph/tenant/mutators/comment.ts b/src/core/server/graph/tenant/mutators/comment.ts index 0867ee5e3..01c734185 100644 --- a/src/core/server/graph/tenant/mutators/comment.ts +++ b/src/core/server/graph/tenant/mutators/comment.ts @@ -1,16 +1,20 @@ import TenantContext from "talk-server/graph/tenant/context"; import { + GQLCreateCommentDontAgreeInput, GQLCreateCommentFlagInput, GQLCreateCommentInput, GQLCreateCommentReactionInput, + GQLDeleteCommentDontAgreeInput, GQLDeleteCommentFlagInput, GQLDeleteCommentReactionInput, GQLEditCommentInput, } from "talk-server/graph/tenant/schema/__generated__/types"; import { create, edit } from "talk-server/services/comments"; import { + createDontAgree, createFlag, createReaction, + deleteDontAgree, deleteFlag, deleteReaction, } from "talk-server/services/comments/actions"; @@ -48,6 +52,14 @@ export default (ctx: TenantContext) => ({ deleteReaction(ctx.mongo, ctx.tenant, ctx.user!, { item_id: input.commentID, }), + createDontAgree: (input: GQLCreateCommentDontAgreeInput) => + createDontAgree(ctx.mongo, ctx.tenant, ctx.user!, { + item_id: input.commentID, + }), + deleteDontAgree: (input: GQLDeleteCommentDontAgreeInput) => + deleteDontAgree(ctx.mongo, ctx.tenant, ctx.user!, { + item_id: input.commentID, + }), createFlag: (input: GQLCreateCommentFlagInput) => createFlag(ctx.mongo, ctx.tenant, ctx.user!, { item_id: input.commentID, diff --git a/src/core/server/graph/tenant/resolvers/mutation.ts b/src/core/server/graph/tenant/resolvers/mutation.ts index 9074ccfc8..77f0ca109 100644 --- a/src/core/server/graph/tenant/resolvers/mutation.ts +++ b/src/core/server/graph/tenant/resolvers/mutation.ts @@ -31,6 +31,14 @@ const Mutation: GQLMutationTypeResolver = { comment: await ctx.mutators.Comment.deleteReaction(input), clientMutationId: input.clientMutationId, }), + createCommentDontAgree: async (source, { input }, ctx) => ({ + comment: await ctx.mutators.Comment.createDontAgree(input), + clientMutationId: input.clientMutationId, + }), + deleteCommentDontAgree: async (source, { input }, ctx) => ({ + comment: await ctx.mutators.Comment.deleteDontAgree(input), + clientMutationId: input.clientMutationId, + }), createCommentFlag: async (source, { input }, ctx) => ({ comment: await ctx.mutators.Comment.createFlag(input), clientMutationId: input.clientMutationId, diff --git a/src/core/server/graph/tenant/schema/schema.graphql b/src/core/server/graph/tenant/schema/schema.graphql index 7ca1ec4dc..c96f32305 100644 --- a/src/core/server/graph/tenant/schema/schema.graphql +++ b/src/core/server/graph/tenant/schema/schema.graphql @@ -1530,6 +1530,62 @@ type DeleteCommentReactionPayload { clientMutationId: String! } +################## +## createCommentDontAgree +################## + +input CreateCommentDontAgreeInput { + """ + commentID is the Comment's ID that we want to create a DontAgree on. + """ + commentID: ID! + + """ + clientMutationId is required for Relay support. + """ + clientMutationId: String! +} + +type CreateCommentDontAgreePayload { + """ + comment is the Comment that the DontAgree was created on. + """ + comment: Comment + + """ + clientMutationId is required for Relay support. + """ + clientMutationId: String! +} + +################## +## deleteCommentDontAgree +################## + +input DeleteCommentDontAgreeInput { + """ + commentID is the Comment's ID that we want to delete a DontAgree on. + """ + commentID: ID! + + """ + clientMutationId is required for Relay support. + """ + clientMutationId: String! +} + +type DeleteCommentDontAgreePayload { + """ + comment is the Comment that the DontAgree was deleted on. + """ + comment: Comment + + """ + clientMutationId is required for Relay support. + """ + clientMutationId: String! +} + ################## ## createCommentFlag ################## @@ -1629,6 +1685,22 @@ type Mutation { input: CreateCommentReactionInput! ): CreateCommentReactionPayload @auth + """ + createCommentDontAgree will create a DontAgree authored by the current logged in + User on a Comment. + """ + createCommentDontAgree( + input: CreateCommentDontAgreeInput! + ): CreateCommentDontAgreePayload @auth + + """ + deleteCommentDontAgree will delete a DontAgree authored by the current logged in + User on a Comment if it exists. + """ + deleteCommentDontAgree( + input: CreateCommentDontAgreeInput! + ): CreateCommentDontAgreePayload @auth + """ createCommentFlag will create a Flag authored by the current logged in User on a given Comment. diff --git a/src/core/server/services/comments/actions.ts b/src/core/server/services/comments/actions.ts index f8313c913..e788757c9 100644 --- a/src/core/server/services/comments/actions.ts +++ b/src/core/server/services/comments/actions.ts @@ -161,6 +161,38 @@ export async function deleteReaction( }); } +export type CreateCommentDontAgree = Pick; + +export async function createDontAgree( + mongo: Db, + tenant: Tenant, + author: User, + input: CreateCommentDontAgree +) { + return addCommentAction(mongo, tenant, { + action_type: ACTION_TYPE.DONT_AGREE, + item_type: ACTION_ITEM_TYPE.COMMENTS, + item_id: input.item_id, + user_id: author.id, + }); +} + +export type DeleteCommentDontAgree = Pick; + +export async function deleteDontAgree( + mongo: Db, + tenant: Tenant, + author: User, + input: DeleteCommentDontAgree +) { + return removeCommentAction(mongo, tenant, { + action_type: ACTION_TYPE.DONT_AGREE, + item_type: ACTION_ITEM_TYPE.COMMENTS, + item_id: input.item_id, + user_id: author.id, + }); +} + export type CreateCommentFlag = Pick & { reason: GQLCOMMENT_FLAG_REPORTED_REASON; };