Skip to content

Commit

Permalink
move around dsareport mutation/services/etc
Browse files Browse the repository at this point in the history
  • Loading branch information
kabeaty committed Oct 6, 2023
1 parent 9de2629 commit d1164b7
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 40 deletions.
2 changes: 1 addition & 1 deletion server/src/core/server/data/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Config } from "coral-server/config";
import { CommentAction } from "coral-server/models/action/comment";
import { CommentModerationAction } from "coral-server/models/action/moderation/comment";
import { Comment } from "coral-server/models/comment";
import { DSAReport } from "coral-server/models/dsaReport/comment";
import { DSAReport } from "coral-server/models/dsaReport/report";
import { createCollection } from "coral-server/models/helpers";
import { Invite } from "coral-server/models/invite";
import { MigrationRecord } from "coral-server/models/migration";
Expand Down
18 changes: 2 additions & 16 deletions server/src/core/server/graph/mutators/Comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { hasTag } from "coral-server/models/comment";
import { addTag, removeTag } from "coral-server/services/comments";
import {
createDontAgree,
createDSAReport,
// createDSAReport,
createFlag,
createReaction,
removeDontAgree,
Expand All @@ -29,7 +29,7 @@ import {
GQLCreateCommentInput,
GQLCreateCommentReactionInput,
GQLCreateCommentReplyInput,
GQLCreateDSAReportInput,
// GQLCreateDSAReportInput,
GQLEditCommentInput,
GQLFeatureCommentInput,
GQLMarkCommentsAsSeenInput,
Expand Down Expand Up @@ -208,20 +208,6 @@ export const Comments = (ctx: GraphContext) => ({
ctx.now,
ctx.req
),
createDSAReport: ({
commentID,
userID,
lawBrokenDescription,
additionalInformation,
submissionID,
}: GQLCreateDSAReportInput) =>
createDSAReport(ctx.mongo, ctx.tenant, {
commentID,
userID,
lawBrokenDescription,
additionalInformation,
submissionID,
}),
feature: async ({
commentID,
commentRevisionID,
Expand Down
21 changes: 21 additions & 0 deletions server/src/core/server/graph/mutators/DSAReports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import GraphContext from "coral-server/graph/context";
import { createDSAReport } from "coral-server/services/dsaReports/reports";

import { GQLCreateDSAReportInput } from "coral-server/graph/schema/__generated__/types";

export const DSAReports = (ctx: GraphContext) => ({
createDSAReport: ({
commentID,
userID,
lawBrokenDescription,
additionalInformation,
submissionID,
}: GQLCreateDSAReportInput) =>
createDSAReport(ctx.mongo, ctx.tenant, {
commentID,
userID,
lawBrokenDescription,
additionalInformation,
submissionID,
}),
});
2 changes: 2 additions & 0 deletions server/src/core/server/graph/mutators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import GraphContext from "coral-server/graph/context";

import { Actions } from "./Actions";
import { Comments } from "./Comments";
import { DSAReports } from "./DSAReports";
import { Redis } from "./Redis";
import { Settings } from "./Settings";
import { Sites } from "./Sites";
Expand All @@ -11,6 +12,7 @@ import { Users } from "./Users";
const root = (ctx: GraphContext) => ({
Actions: Actions(ctx),
Comments: Comments(ctx),
DSAReports: DSAReports(ctx),
Settings: Settings(ctx),
Stories: Stories(ctx),
Users: Users(ctx),
Expand Down
2 changes: 1 addition & 1 deletion server/src/core/server/graph/resolvers/Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const Mutation: Required<GQLMutationTypeResolver<void>> = {
clientMutationId: input.clientMutationId,
}),
createDSAReport: async (source, { input }, ctx) => ({
dsaReport: await ctx.mutators.Comments.createDSAReport(input),
dsaReport: await ctx.mutators.DSAReports.createDSAReport(input),
clientMutationId: input.clientMutationId,
}),
featureComment: async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { MongoContext } from "coral-server/data/context";
import { FilterQuery } from "coral-server/models/helpers";
import { TenantResource } from "coral-server/models/tenant";

import { GQLDSAReportStatus } from "coral-server/graph/schema/__generated__/types";

export interface DSAReport extends TenantResource {
readonly id: string;

Expand All @@ -21,16 +23,18 @@ export interface DSAReport extends TenantResource {
submissionID?: string;

publicID: string;

status: GQLDSAReportStatus;
}

export type CreateDSAReportInput = Omit<
DSAReport,
"id" | "tenantID" | "createdAt" | "publicID"
"id" | "tenantID" | "createdAt" | "publicID" | "status"
>;

export interface CreateDSAReportResultObject {
/**
* action contains the resultant DSAReport that was created.
* dsaReport contains the resultant DSAReport that was created.
*/
dsaReport: DSAReport;
}
Expand Down Expand Up @@ -60,6 +64,7 @@ export async function createDSAReport(
tenantID,
createdAt: now,
publicID,
status: GQLDSAReportStatus.AWAITING_REVIEW,
};

// Extract the filter parameters.
Expand Down
20 changes: 0 additions & 20 deletions server/src/core/server/services/comments/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
updateCommentActionCounts,
} from "coral-server/models/comment";
import { getLatestRevision } from "coral-server/models/comment/helpers";
import { createDSAReport as createReport } from "coral-server/models/dsaReport/comment";
import { retrieveSite } from "coral-server/models/site";
import { Tenant } from "coral-server/models/tenant";
import { User } from "coral-server/models/user";
Expand Down Expand Up @@ -473,22 +472,3 @@ export async function createFlag(

return comment;
}

export interface CreateDSAReportInput {
commentID: string;
userID: string;
lawBrokenDescription: string;
additionalInformation: string;
submissionID?: string;
}

export async function createDSAReport(
mongo: MongoContext,
tenant: Tenant,
input: CreateDSAReportInput,
now = new Date()
) {
const result = await createReport(mongo, tenant.id, input, now);
const { dsaReport } = result;
return dsaReport;
}
22 changes: 22 additions & 0 deletions server/src/core/server/services/dsaReports/reports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { MongoContext } from "coral-server/data/context";
import { createDSAReport as createReport } from "coral-server/models/dsaReport/report";
import { Tenant } from "coral-server/models/tenant";

export interface CreateDSAReportInput {
commentID: string;
userID: string;
lawBrokenDescription: string;
additionalInformation: string;
submissionID?: string;
}

export async function createDSAReport(
mongo: MongoContext,
tenant: Tenant,
input: CreateDSAReportInput,
now = new Date()
) {
const result = await createReport(mongo, tenant.id, input, now);
const { dsaReport } = result;
return dsaReport;
}

0 comments on commit d1164b7

Please sign in to comment.