-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
- Loading branch information
1 parent
86ce9f5
commit 1dd5084
Showing
8 changed files
with
443 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import type { actionsTable } from "~/src/drizzle/tables/actions"; | ||
import { builder } from "~/src/graphql/builder"; | ||
|
||
export type ActionItem = typeof actionsTable.$inferSelect; | ||
|
||
export const ActionItem = builder.objectRef<ActionItem>("ActionItem"); | ||
|
||
ActionItem.implement({ | ||
description: | ||
"Represents an action item assigned to users, linked to events, categories, and organizations.", | ||
fields: (t) => ({ | ||
id: t.exposeID("id", { | ||
description: "Unique identifier for the action item.", | ||
}), | ||
isCompleted: t.exposeBoolean("isCompleted", { | ||
description: "Indicates whether the action item is completed.", | ||
}), | ||
assignedAt: t.expose("assignedAt", { | ||
description: "Timestamp when the action item was assigned.", | ||
type: "DateTime", | ||
}), | ||
completionAt: t.expose("completionAt", { | ||
description: "Timestamp when the action item was completed.", | ||
type: "DateTime", | ||
}), | ||
createdAt: t.expose("createdAt", { | ||
description: "Timestamp when the action item was created.", | ||
type: "DateTime", | ||
}), | ||
updatedAt: t.expose("updatedAt", { | ||
description: "Timestamp when the action item was last updated.", | ||
type: "DateTime", | ||
nullable: true, | ||
}), | ||
preCompletionNotes: t.exposeString("preCompletionNotes", { | ||
description: "Notes added before completing the action item.", | ||
nullable: true, | ||
}), | ||
postCompletionNotes: t.exposeString("postCompletionNotes", { | ||
description: "Notes added after completing the action item.", | ||
nullable: true, | ||
}), | ||
organizationId: t.exposeID("organizationId", { | ||
description: "The ID of the organization the action item belongs to.", | ||
}), | ||
categoryId: t.exposeID("categoryId", { | ||
description: "The ID of the category this action item belongs to.", | ||
nullable: true, | ||
}), | ||
eventId: t.exposeID("eventId", { | ||
description: "The ID of the associated event, if applicable.", | ||
nullable: true, | ||
}), | ||
assigneeId: t.exposeID("assigneeId", { | ||
description: "The ID of the user assigned to this action item.", | ||
nullable: true, | ||
}), | ||
creatorId: t.exposeID("creatorId", { | ||
description: "The ID of the user who created this action item.", | ||
nullable: true, | ||
}), | ||
updaterId: t.exposeID("updaterId", { | ||
description: "The ID of the user who last updated this action item.", | ||
nullable: true, | ||
}), | ||
}), | ||
}); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { builder } from "~/src/graphql/builder"; | ||
|
||
export type ActionItemCategory = { | ||
id: string; | ||
name: string; | ||
organizationId: string; | ||
isDisabled: boolean; | ||
creatorId: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
}; | ||
|
||
export const ActionItemCategory = | ||
builder.objectRef<ActionItemCategory>("ActionItemCategory"); | ||
|
||
ActionItemCategory.implement({ | ||
description: | ||
"Represents a category for action items, including metadata such as creation and update timestamps.", | ||
fields: (t) => ({ | ||
id: t.exposeID("id", { | ||
description: "Unique identifier for the action item category.", | ||
}), | ||
name: t.exposeString("name", { | ||
description: "The name of the action item category.", | ||
}), | ||
organizationId: t.exposeID("organizationId", { | ||
description: "Identifier for the organization this category belongs to.", | ||
}), | ||
isDisabled: t.exposeBoolean("isDisabled", { | ||
description: "Indicates whether the action item category is disabled.", | ||
}), | ||
creatorId: t.exposeID("creatorId", { | ||
description: "Identifier for the user who created this category.", | ||
}), | ||
createdAt: t.expose("createdAt", { | ||
description: "Timestamp when the category was created.", | ||
type: "DateTime", | ||
}), | ||
updatedAt: t.expose("updatedAt", { | ||
description: "Timestamp when the category was last updated.", | ||
type: "DateTime", | ||
}), | ||
}), | ||
}); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { User } from "~/src/graphql/types/User/User"; | ||
import { TalawaGraphQLError } from "~/src/utilities/TalawaGraphQLError"; | ||
import { ActionItem } from "./ActionItem"; | ||
|
||
ActionItem.implement({ | ||
fields: (t) => ({ | ||
assignee: t.field({ | ||
type: User, | ||
nullable: true, | ||
description: "The user assigned to this action item.", | ||
resolve: async (parent, _args, ctx) => { | ||
if (!parent.assigneeId) { | ||
return null; | ||
} | ||
const user = await ctx.drizzleClient.query.usersTable.findFirst({ | ||
where: (fields, operators) => | ||
operators.eq(fields.id, parent.assigneeId as string), | ||
}); | ||
|
||
if (!user) { | ||
ctx.log.error( | ||
`Assignee with ID ${parent.assigneeId} not found for ActionItem.`, | ||
); | ||
throw new TalawaGraphQLError({ | ||
message: "Assignee not found", | ||
extensions: { | ||
code: "arguments_associated_resources_not_found", | ||
issues: [ | ||
{ | ||
argumentPath: ["assigneeId"], | ||
}, | ||
], | ||
}, | ||
}); | ||
} | ||
|
||
return user; | ||
}, | ||
}), | ||
}), | ||
}); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { TalawaGraphQLError } from "~/src/utilities/TalawaGraphQLError"; | ||
import { ActionItem } from "./ActionItem"; | ||
|
||
ActionItem.implement({ | ||
fields: (t) => ({ | ||
createdAt: t.field({ | ||
description: "Date time at the time the action item was created.", | ||
resolve: async (parent, _args, ctx) => { | ||
if (!ctx.currentClient.isAuthenticated) { | ||
throw new TalawaGraphQLError({ | ||
extensions: { | ||
code: "unauthenticated", | ||
}, | ||
}); | ||
} | ||
|
||
const currentUserId = ctx.currentClient.user.id; | ||
|
||
const currentUser = await ctx.drizzleClient.query.usersTable.findFirst({ | ||
columns: { | ||
role: true, | ||
}, | ||
with: { | ||
organizationMembershipsWhereMember: { | ||
columns: { | ||
role: true, | ||
}, | ||
where: (fields, operators) => | ||
operators.eq(fields.organizationId, parent.organizationId), | ||
}, | ||
}, | ||
where: (fields, operators) => operators.eq(fields.id, currentUserId), | ||
}); | ||
|
||
if (currentUser === undefined) { | ||
throw new TalawaGraphQLError({ | ||
extensions: { | ||
code: "unauthenticated", | ||
}, | ||
}); | ||
} | ||
|
||
const currentUserOrganizationMembership = | ||
currentUser.organizationMembershipsWhereMember[0]; | ||
|
||
if ( | ||
currentUser.role !== "administrator" && | ||
(currentUserOrganizationMembership === undefined || | ||
currentUserOrganizationMembership.role !== "administrator") | ||
) { | ||
throw new TalawaGraphQLError({ | ||
extensions: { | ||
code: "unauthorized_action", | ||
}, | ||
}); | ||
} | ||
|
||
return parent.createdAt; | ||
}, | ||
type: "DateTime", | ||
}), | ||
}), | ||
}); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { User } from "~/src/graphql/types/User/User"; | ||
import { TalawaGraphQLError } from "~/src/utilities/TalawaGraphQLError"; | ||
import { ActionItem } from "./ActionItem"; | ||
|
||
ActionItem.implement({ | ||
fields: (t) => ({ | ||
creator: t.field({ | ||
description: "User who created the action item.", | ||
resolve: async (parent, _args, ctx) => { | ||
if (!ctx.currentClient.isAuthenticated) { | ||
throw new TalawaGraphQLError({ | ||
extensions: { | ||
code: "unauthenticated", | ||
}, | ||
}); | ||
} | ||
|
||
const currentUserId = ctx.currentClient.user.id; | ||
|
||
const currentUser = await ctx.drizzleClient.query.usersTable.findFirst({ | ||
with: { | ||
organizationMembershipsWhereMember: { | ||
columns: { | ||
role: true, | ||
}, | ||
where: (fields, operators) => | ||
operators.eq(fields.organizationId, parent.organizationId), | ||
}, | ||
}, | ||
where: (fields, operators) => operators.eq(fields.id, currentUserId), | ||
}); | ||
|
||
if (currentUser === undefined) { | ||
throw new TalawaGraphQLError({ | ||
extensions: { | ||
code: "unauthenticated", | ||
}, | ||
}); | ||
} | ||
|
||
const currentUserOrganizationMembership = | ||
currentUser.organizationMembershipsWhereMember[0]; | ||
|
||
if ( | ||
currentUser.role !== "administrator" && | ||
(currentUserOrganizationMembership === undefined || | ||
currentUserOrganizationMembership.role !== "administrator") | ||
) { | ||
throw new TalawaGraphQLError({ | ||
extensions: { | ||
code: "unauthorized_action", | ||
}, | ||
}); | ||
} | ||
|
||
if (parent.creatorId === null) { | ||
return null; | ||
} | ||
|
||
if (parent.creatorId === currentUserId) { | ||
return currentUser; | ||
} | ||
|
||
const creatorId = parent.creatorId; | ||
|
||
const existingUser = await ctx.drizzleClient.query.usersTable.findFirst( | ||
{ | ||
where: (fields, operators) => operators.eq(fields.id, creatorId), | ||
}, | ||
); | ||
|
||
if (existingUser === undefined) { | ||
ctx.log.error( | ||
"Postgres select operation returned an empty array for an action item's creator id that isn't null.", | ||
); | ||
|
||
throw new TalawaGraphQLError({ | ||
extensions: { | ||
code: "unexpected", | ||
}, | ||
}); | ||
} | ||
|
||
return existingUser; | ||
}, | ||
type: User, | ||
}), | ||
}), | ||
}); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Event } from "~/src/graphql/types/Event/Event"; | ||
import { TalawaGraphQLError } from "~/src/utilities/TalawaGraphQLError"; | ||
import { ActionItem } from "./ActionItem"; | ||
|
||
ActionItem.implement({ | ||
fields: (t) => ({ | ||
event: t.field({ | ||
description: | ||
"Fetch the event associated with this action item, including attachments if available.", | ||
type: Event, | ||
nullable: true, | ||
resolve: async (parent, _args, ctx) => { | ||
if (!parent.eventId) return null; | ||
|
||
const existingEvent = | ||
await ctx.drizzleClient.query.eventsTable.findFirst({ | ||
where: (fields, operators) => | ||
operators.eq(fields.id, parent.eventId as string), | ||
with: { | ||
attachmentsWhereEvent: true, | ||
}, | ||
}); | ||
|
||
if (!existingEvent) { | ||
ctx.log.error( | ||
"Postgres select operation returned no row for action item's eventId that isn't null.", | ||
); | ||
|
||
throw new TalawaGraphQLError({ | ||
extensions: { | ||
code: "unexpected", | ||
}, | ||
}); | ||
} | ||
|
||
return Object.assign(existingEvent, { | ||
attachments: existingEvent.attachmentsWhereEvent, | ||
}); | ||
}, | ||
}), | ||
}), | ||
}); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from "./ActionItem"; | ||
export * from "./ActionItemCategory"; | ||
export * from "./createdAt"; | ||
export * from "./updatedAt"; | ||
export * from "./creator"; | ||
Oops, something went wrong.