Skip to content

Commit

Permalink
Added files for ActionItems
Browse files Browse the repository at this point in the history
Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
  • Loading branch information
NishantSinghhhhh committed Mar 1, 2025
1 parent 86ce9f5 commit 1dd5084
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/graphql/types/ActionItems/ActionItem.ts
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";

Check warning on line 2 in src/graphql/types/ActionItems/ActionItem.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/ActionItem.ts#L2

Added line #L2 was not covered by tests

export type ActionItem = typeof actionsTable.$inferSelect;

export const ActionItem = builder.objectRef<ActionItem>("ActionItem");

Check warning on line 6 in src/graphql/types/ActionItems/ActionItem.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/ActionItem.ts#L6

Added line #L6 was not covered by tests

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,
}),
}),
});

Check warning on line 67 in src/graphql/types/ActionItems/ActionItem.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/ActionItem.ts#L8-L67

Added lines #L8 - L67 were not covered by tests
44 changes: 44 additions & 0 deletions src/graphql/types/ActionItems/ActionItemCategory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { builder } from "~/src/graphql/builder";

Check warning on line 1 in src/graphql/types/ActionItems/ActionItemCategory.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/ActionItemCategory.ts#L1

Added line #L1 was not covered by tests

export type ActionItemCategory = {
id: string;
name: string;
organizationId: string;
isDisabled: boolean;
creatorId: string;
createdAt: Date;
updatedAt: Date;
};

export const ActionItemCategory =
builder.objectRef<ActionItemCategory>("ActionItemCategory");

Check warning on line 14 in src/graphql/types/ActionItems/ActionItemCategory.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/ActionItemCategory.ts#L13-L14

Added lines #L13 - L14 were not covered by tests

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",
}),
}),
});

Check warning on line 44 in src/graphql/types/ActionItems/ActionItemCategory.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/ActionItemCategory.ts#L16-L44

Added lines #L16 - L44 were not covered by tests
41 changes: 41 additions & 0 deletions src/graphql/types/ActionItems/assignee.ts
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";

Check warning on line 3 in src/graphql/types/ActionItems/assignee.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/assignee.ts#L1-L3

Added lines #L1 - L3 were not covered by tests

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),
});

Check warning on line 18 in src/graphql/types/ActionItems/assignee.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/assignee.ts#L5-L18

Added lines #L5 - L18 were not covered by tests

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"],
},
],
},
});
}

Check warning on line 35 in src/graphql/types/ActionItems/assignee.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/assignee.ts#L20-L35

Added lines #L20 - L35 were not covered by tests

return user;
},
}),
}),
});

Check warning on line 41 in src/graphql/types/ActionItems/assignee.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/assignee.ts#L37-L41

Added lines #L37 - L41 were not covered by tests
63 changes: 63 additions & 0 deletions src/graphql/types/ActionItems/createdAt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { TalawaGraphQLError } from "~/src/utilities/TalawaGraphQLError";
import { ActionItem } from "./ActionItem";

Check warning on line 2 in src/graphql/types/ActionItems/createdAt.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/createdAt.ts#L1-L2

Added lines #L1 - L2 were not covered by tests

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",
},
});
}

Check warning on line 15 in src/graphql/types/ActionItems/createdAt.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/createdAt.ts#L4-L15

Added lines #L4 - L15 were not covered by tests

const currentUserId = ctx.currentClient.user.id;

Check warning on line 17 in src/graphql/types/ActionItems/createdAt.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/createdAt.ts#L17

Added line #L17 was not covered by tests

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),
});

Check warning on line 33 in src/graphql/types/ActionItems/createdAt.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/createdAt.ts#L19-L33

Added lines #L19 - L33 were not covered by tests

if (currentUser === undefined) {
throw new TalawaGraphQLError({
extensions: {
code: "unauthenticated",
},
});
}

Check warning on line 41 in src/graphql/types/ActionItems/createdAt.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/createdAt.ts#L35-L41

Added lines #L35 - L41 were not covered by tests

const currentUserOrganizationMembership =
currentUser.organizationMembershipsWhereMember[0];

Check warning on line 44 in src/graphql/types/ActionItems/createdAt.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/createdAt.ts#L43-L44

Added lines #L43 - L44 were not covered by tests

if (
currentUser.role !== "administrator" &&
(currentUserOrganizationMembership === undefined ||
currentUserOrganizationMembership.role !== "administrator")
) {
throw new TalawaGraphQLError({
extensions: {
code: "unauthorized_action",
},
});
}

Check warning on line 56 in src/graphql/types/ActionItems/createdAt.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/createdAt.ts#L46-L56

Added lines #L46 - L56 were not covered by tests

return parent.createdAt;
},
type: "DateTime",
}),
}),
});

Check warning on line 63 in src/graphql/types/ActionItems/createdAt.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/createdAt.ts#L58-L63

Added lines #L58 - L63 were not covered by tests
89 changes: 89 additions & 0 deletions src/graphql/types/ActionItems/creator.ts
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";

Check warning on line 3 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L1-L3

Added lines #L1 - L3 were not covered by tests

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",
},
});
}

Check warning on line 16 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L5-L16

Added lines #L5 - L16 were not covered by tests

const currentUserId = ctx.currentClient.user.id;

Check warning on line 18 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L18

Added line #L18 was not covered by tests

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),
});

Check warning on line 31 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L20-L31

Added lines #L20 - L31 were not covered by tests

if (currentUser === undefined) {
throw new TalawaGraphQLError({
extensions: {
code: "unauthenticated",
},
});
}

Check warning on line 39 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L33-L39

Added lines #L33 - L39 were not covered by tests

const currentUserOrganizationMembership =
currentUser.organizationMembershipsWhereMember[0];

Check warning on line 42 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L41-L42

Added lines #L41 - L42 were not covered by tests

if (
currentUser.role !== "administrator" &&
(currentUserOrganizationMembership === undefined ||
currentUserOrganizationMembership.role !== "administrator")
) {
throw new TalawaGraphQLError({
extensions: {
code: "unauthorized_action",
},
});
}

Check warning on line 54 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L44-L54

Added lines #L44 - L54 were not covered by tests

if (parent.creatorId === null) {
return null;
}

Check warning on line 58 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L56-L58

Added lines #L56 - L58 were not covered by tests

if (parent.creatorId === currentUserId) {
return currentUser;
}

Check warning on line 62 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L60-L62

Added lines #L60 - L62 were not covered by tests

const creatorId = parent.creatorId;

Check warning on line 64 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L64

Added line #L64 was not covered by tests

const existingUser = await ctx.drizzleClient.query.usersTable.findFirst(
{
where: (fields, operators) => operators.eq(fields.id, creatorId),
},
);

Check warning on line 70 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L66-L70

Added lines #L66 - L70 were not covered by tests

if (existingUser === undefined) {
ctx.log.error(
"Postgres select operation returned an empty array for an action item's creator id that isn't null.",
);

Check warning on line 75 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L72-L75

Added lines #L72 - L75 were not covered by tests

throw new TalawaGraphQLError({
extensions: {
code: "unexpected",
},
});
}

Check warning on line 82 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L77-L82

Added lines #L77 - L82 were not covered by tests

return existingUser;
},
type: User,
}),
}),
});

Check warning on line 89 in src/graphql/types/ActionItems/creator.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/creator.ts#L84-L89

Added lines #L84 - L89 were not covered by tests
42 changes: 42 additions & 0 deletions src/graphql/types/ActionItems/event.ts
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";

Check warning on line 3 in src/graphql/types/ActionItems/event.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/event.ts#L1-L3

Added lines #L1 - L3 were not covered by tests

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;

Check warning on line 13 in src/graphql/types/ActionItems/event.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/event.ts#L5-L13

Added lines #L5 - L13 were not covered by tests

const existingEvent =
await ctx.drizzleClient.query.eventsTable.findFirst({
where: (fields, operators) =>
operators.eq(fields.id, parent.eventId as string),
with: {
attachmentsWhereEvent: true,
},
});

Check warning on line 22 in src/graphql/types/ActionItems/event.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/event.ts#L15-L22

Added lines #L15 - L22 were not covered by tests

if (!existingEvent) {
ctx.log.error(
"Postgres select operation returned no row for action item's eventId that isn't null.",
);

Check warning on line 27 in src/graphql/types/ActionItems/event.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/event.ts#L24-L27

Added lines #L24 - L27 were not covered by tests

throw new TalawaGraphQLError({
extensions: {
code: "unexpected",
},
});
}

Check warning on line 34 in src/graphql/types/ActionItems/event.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/event.ts#L29-L34

Added lines #L29 - L34 were not covered by tests

return Object.assign(existingEvent, {
attachments: existingEvent.attachmentsWhereEvent,
});
},
}),
}),
});

Check warning on line 42 in src/graphql/types/ActionItems/event.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/event.ts#L36-L42

Added lines #L36 - L42 were not covered by tests
5 changes: 5 additions & 0 deletions src/graphql/types/ActionItems/index.ts
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";

Check warning on line 5 in src/graphql/types/ActionItems/index.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/ActionItems/index.ts#L1-L5

Added lines #L1 - L5 were not covered by tests
Loading

0 comments on commit 1dd5084

Please sign in to comment.