Skip to content

Commit

Permalink
add resolvers for DSA deports associated to a notification
Browse files Browse the repository at this point in the history
also adds loaders for DSA reports
  • Loading branch information
nick-funk committed Oct 30, 2023
1 parent f182afb commit 89608a2
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 2 deletions.
22 changes: 22 additions & 0 deletions server/src/core/server/graph/loaders/DSAReports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import DataLoader from "dataloader";

import { find } from "coral-server/models/dsaReport/report";

import GraphContext from "../context";
import { createManyBatchLoadFn } from "./util";

export interface FindDSAReportInput {
id: string;
}

export default (ctx: GraphContext) => ({
find: new DataLoader(
createManyBatchLoadFn((input: FindDSAReportInput) =>
find(ctx.mongo, ctx.tenant, input)
),
{
cacheKeyFn: (input: FindDSAReportInput) => `${input.id}`,
cache: !ctx.disableCaching,
}
),
});
2 changes: 2 additions & 0 deletions server/src/core/server/graph/loaders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Auth from "./Auth";
import CommentActions from "./CommentActions";
import CommentModerationActions from "./CommentModerationActions";
import Comments from "./Comments";
import DSAReports from "./DSAReports";
import Notifications from "./Notifications";
import SeenComments from "./SeenComments";
import Sites from "./Sites";
Expand All @@ -20,4 +21,5 @@ export default (ctx: Context) => ({
Sites: Sites(ctx),
SeenComments: SeenComments(ctx),
Notifications: Notifications(ctx),
DSAReports: DSAReports(ctx),
});
7 changes: 7 additions & 0 deletions server/src/core/server/graph/resolvers/Notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,11 @@ export const NotificationResolver: Required<

return comment;
},
dsaReport: async ({ reportID }, input, ctx) => {
if (!reportID) {
return null;
}

return await ctx.loaders.DSAReports.find.load({ id: reportID });
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { DSAReport } from "coral-server/models/dsaReport/report";

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

export const NotificationDSAReportDetailsResolver: Required<
GQLNotificationDSAReportDetailsTypeResolver<DSAReport>
> = {
id: ({ id }) => id,
publicID: ({ publicID }) => publicID,
comment: async ({ commentID }, input, ctx) => {
if (!commentID) {
return null;
}

return await ctx.loaders.Comments.comment.load(commentID);
},
user: async ({ userID }, input, ctx) => {
if (!userID) {
return null;
}

return await ctx.loaders.Users.user.load(userID);
},
lawBrokenDescription: ({ lawBrokenDescription }) => lawBrokenDescription,
additionalInformation: ({ additionalInformation }) => additionalInformation,
submissionID: ({ submissionID }) => submissionID,
};
2 changes: 2 additions & 0 deletions server/src/core/server/graph/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { ModMessageStatusHistory } from "./ModMessageStatusHistory";
import { Mutation } from "./Mutation";
import { NewCommentersConfiguration } from "./NewCommentersConfiguration";
import { NotificationResolver as Notification } from "./Notification";
import { NotificationDSAReportDetailsResolver as NotificationDSAReportDetails } from "./NotificationDSAReportDetails";
import { OIDCAuthIntegration } from "./OIDCAuthIntegration";
import { PremodStatus } from "./PremodStatus";
import { PremodStatusHistory } from "./PremodStatusHistory";
Expand Down Expand Up @@ -167,6 +168,7 @@ const Resolvers: GQLResolver = {
LocalAuthIntegration,
AuthenticationTargetFilter,
Notification,
NotificationDSAReportDetails,
};

export default Resolvers;
26 changes: 25 additions & 1 deletion server/src/core/server/graph/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4514,6 +4514,13 @@ type Notification {
comment is the optional comment that is linked to this notification.
"""
comment: Comment

"""
dsaReports are details of the DSA Reports related to the notification.
This is usually in reference to the comment that is also related to
the notification.
"""
dsaReport: NotificationDSAReportDetails
}

type NotificationEdge {
Expand Down Expand Up @@ -4545,6 +4552,22 @@ type NotificationsConnection {
pageInfo: PageInfo!
}

type NotificationDSAReportDetails {
id: ID!

publicID: String!

comment: Comment

user: User

lawBrokenDescription: String @auth(roles: [ADMIN, MODERATOR])

additionalInformation: String @auth(roles: [ADMIN, MODERATOR])

submissionID: ID @auth(roles: [ADMIN, MODERATOR])
}

################################################################################
## Query
################################################################################
Expand Down Expand Up @@ -4718,7 +4741,8 @@ type Query {
notifications(
ownerID: ID!
first: Int = 10 @constraint(max: 50)
after: Cursor): NotificationsConnection!
after: Cursor
): NotificationsConnection!
}

################################################################################
Expand Down
24 changes: 23 additions & 1 deletion server/src/core/server/models/dsaReport/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { v4 as uuid } from "uuid";

import { Sub } from "coral-common/common/lib/types";
import { MongoContext } from "coral-server/data/context";
import { FindDSAReportInput } from "coral-server/graph/loaders/DSAReports";
import { FilterQuery } from "coral-server/models/helpers";
import { TenantResource } from "coral-server/models/tenant";
import { Tenant, TenantResource } from "coral-server/models/tenant";

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

Expand Down Expand Up @@ -98,3 +99,24 @@ export async function createDSAReport(
dsaReport: report,
};
}

export async function find(
mongo: MongoContext,
tenant: Tenant,
input: FindDSAReportInput
) {
return findDSAReport(mongo, tenant.id, input.id);
}

export async function findDSAReport(
mongo: MongoContext,
tenantID: string,
id: string
): Promise<DSAReport | null> {
const result = await mongo.dsaReports().findOne({
tenantID,
id,
});

return result ?? null;
}

0 comments on commit 89608a2

Please sign in to comment.