Skip to content

Commit

Permalink
feat(INTERNAL-1289): add assignee and creator to external task model
Browse files Browse the repository at this point in the history
  • Loading branch information
LamaEats committed Oct 30, 2024
1 parent 7feb1ed commit bbd50ad
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 32 deletions.
6 changes: 6 additions & 0 deletions generated/kysely/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ export type ExternalTask = {
ownerEmail: string;
ownerName: string;
ownerId: string;
creatorEmail: string | null;
creatorName: string | null;
creatorId: string | null;
assigneeEmail: string | null;
assigneeName: string | null;
assigneeId: string | null;
resolution: string | null;
resolutionId: string | null;
createdAt: Generated<Timestamp>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- AlterTable
ALTER TABLE "ExternalTask" ADD COLUMN "assigneeEmail" TEXT,
ADD COLUMN "assigneeId" TEXT,
ADD COLUMN "assigneeName" TEXT,
ADD COLUMN "creatorEmail" TEXT,
ADD COLUMN "creatorId" TEXT,
ADD COLUMN "creatorName" TEXT;

-- UpdateTable
UPDATE "ExternalTask" SET "creatorEmail" = "ownerEmail",
"creatorId" = "ownerId",
"creatorName" = "ownerName";
6 changes: 6 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ model ExternalTask {
ownerEmail String
ownerName String
ownerId String
creatorEmail String?
creatorName String?
creatorId String?
assigneeEmail String?
assigneeName String?
assigneeId String?
resolution String?
resolutionId String?
criteria GoalAchieveCriteria[] @relation("taskToCriteria")
Expand Down
27 changes: 16 additions & 11 deletions src/components/GoalCriteria/GoalCriteria.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ interface ExternalTaskCriteriaProps extends CriteriaProps {
color: string | null;
title: string;
};
ownerEmail: string;
ownerName: string;
assigneeEmail: string | null;
assigneeName: string | null;
};
}

Expand Down Expand Up @@ -126,9 +126,9 @@ export function mapCriteria<
id: string;
project: string;
projectId: string;
ownerEmail: string;
externalKey: string;
ownerName: string;
assigneeName: string | null;
assigneeEmail: string | null;
},
>(criteria: T, connectedGoal: G | null, task: Et | null): UnionCriteria {
if (connectedGoal) {
Expand Down Expand Up @@ -216,13 +216,18 @@ const SimpleCriteria: React.FC<Omit<CriteriaProps, 'id'> & OnCheckCriteriaCallba
);

const ExternalTaskCriteria = ({ title, externalTask, weight, isDone }: Omit<ExternalTaskCriteriaProps, 'id'>) => {
const ownerData = safeUserData({
user: {
email: externalTask.ownerEmail,
name: externalTask.ownerName,
},
ghost: null,
});
const { assigneeEmail, assigneeName } = externalTask;
let ownerData: ReturnType<typeof safeUserData> | null = null;

if (assigneeEmail && assigneeName) {
ownerData = safeUserData({
user: {
email: assigneeEmail,
name: assigneeName,
},
ghost: null,
});
}

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/integration/jira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface JiraIssue {
summary: string;
description: string;
creator: JiraUser;
assignee: JiraUser;
assignee: JiraUser | null;
reporter: JiraUser;
status: JiraIssueStatus;
project: JiraProject;
Expand Down
16 changes: 15 additions & 1 deletion src/utils/worker/externalTasksJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const dayDuration = 24 * 60 * 60 * 1000;

const createSQLValues = (sources: JiraIssue[]) =>
Prisma.join(
sources.map(({ key, id, status, summary, issuetype, reporter, project, resolution }) =>
sources.map(({ key, id, status, summary, issuetype, reporter, project, resolution, creator, assignee }) =>
Prisma.join(
[
id,
Expand All @@ -33,6 +33,12 @@ const createSQLValues = (sources: JiraIssue[]) =>
reporter.emailAddress,
reporter.key,
reporter.displayName || reporter.name || null,
creator.emailAddress,
creator.key,
creator.displayName || creator.name || null,
assignee?.emailAddress,
assignee?.key,
assignee?.displayName || assignee?.name || null,
resolution?.name || null,
resolution?.id || null,
],
Expand Down Expand Up @@ -100,6 +106,8 @@ const updateExternalTasks = (tasks: JiraIssue[]) => {
"project", "projectKey",
"type", "typeIcon", "typeId",
"ownerEmail", "ownerKey", "ownerName",
"creatorEmail", "creatorKey", "creatorName",
"assigneeEmail", "assigneeKey", "assigneeName",
"resolution", "resolutionId"
)`;

Expand All @@ -123,6 +131,12 @@ const updateExternalTasks = (tasks: JiraIssue[]) => {
"ownerName" = task."ownerName",
"ownerEmail" = task."ownerEmail",
"ownerId" = task."ownerKey",
"creatorName" = task."creatorName",
"creatorEmail" = task."creatorEmail",
"creatorId" = task."creatorKey",
"assigneeName" = task."assigneeName",
"assigneeEmail" = task."assigneeEmail",
"assigneeId" = task."assigneeKey",
"resolution" = task."resolution",
"resolutionId" = task."resolutionId"
FROM ${valuesToUpdate}
Expand Down
8 changes: 8 additions & 0 deletions trpc/queries/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const getOrCreateExternalTask = async ({ id }: { id: string }) => {
issuetype,
status: state,
project,
creator,
assignee,
reporter,
resolution,
} = externalIssue;
Expand All @@ -59,6 +61,12 @@ export const getOrCreateExternalTask = async ({ id }: { id: string }) => {
ownerName: reporter.displayName,
ownerEmail: reporter.emailAddress,
ownerId: reporter.key,
creatorName: creator.displayName,
creatorEmail: creator.emailAddress,
creatorId: creator.key,
assigneeName: assignee?.displayName ?? null,
assigneeEmail: assignee?.emailAddress ?? null,
assigneeId: assignee?.key ?? null,
resolution: resolution?.name ?? null,
resolutionId: resolution?.id ?? null,
}).executeTakeFirstOrThrow();
Expand Down
8 changes: 8 additions & 0 deletions trpc/router/goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,8 @@ export const goal = router({
status: state,
project,
reporter,
creator,
assignee,
resolution,
} = updatedTask;

Expand All @@ -1510,6 +1512,12 @@ export const goal = router({
ownerName: reporter.displayName,
ownerEmail: reporter.emailAddress,
ownerId: reporter.key,
creatorName: creator.displayName,
creatorEmail: creator.emailAddress,
creatorId: creator.key,
assigneeName: assignee?.displayName ?? null,
assigneeEmail: assignee?.emailAddress ?? null,
assigneeId: assignee?.key ?? null,
resolution: resolution?.name ?? null,
resolutionId: resolution?.id ?? null,
}).executeTakeFirstOrThrow();
Expand Down
45 changes: 26 additions & 19 deletions trpc/router/jira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,33 @@ import { ExtractTypeFromGenerated } from '../utils';
const jiraIssueToExternalTask = (
issue: JiraIssue,
): Omit<ExtractTypeFromGenerated<ExternalTask>, 'createdAt' | 'id' | 'updatedAt'> => {
const { key, id, summary, status, project, creator, reporter, assignee, resolution, issuetype } = issue;
return {
externalKey: issue.key,
externalId: issue.id,
title: issue.summary,
state: issue.status.name,
stateCategoryId: issue.status.statusCategory.id,
stateCategoryName: issue.status?.statusCategory.name,
stateId: issue.status.statusCategory?.id ? String(issue.status.statusCategory?.id) : issue.status.id,
stateColor: issue.status.statusCategory?.colorName ?? null,
stateIconUrl: issue.status.iconUrl,
project: issue.project.key,
projectId: issue.project.id,
type: issue.issuetype.name,
typeIconUrl: issue.issuetype.iconUrl,
typeId: issue.issuetype.id,
ownerEmail: issue.reporter.emailAddress,
ownerId: issue.reporter.key,
ownerName: issue.reporter.displayName || issue.reporter.name,
resolution: issue.resolution?.name ?? null,
resolutionId: issue.resolution?.id ?? null,
externalKey: key,
externalId: id,
title: summary,
state: status.name,
stateCategoryId: status.statusCategory.id,
stateCategoryName: status?.statusCategory.name,
stateId: status.statusCategory?.id ? String(status.statusCategory?.id) : status.id,
stateColor: status.statusCategory?.colorName ?? null,
stateIconUrl: status.iconUrl,
project: project.key,
projectId: project.id,
type: issuetype.name,
typeIconUrl: issuetype.iconUrl,
typeId: issuetype.id,
ownerEmail: reporter.emailAddress,
ownerId: reporter.key,
ownerName: reporter.displayName || reporter.name,
creatorEmail: creator.emailAddress,
creatorId: creator.key,
creatorName: creator.displayName || creator.name,
assigneeEmail: assignee?.emailAddress ?? null,
assigneeId: assignee?.key ?? null,
assigneeName: assignee?.displayName ?? assignee?.name ?? null,
resolution: resolution?.name ?? null,
resolutionId: resolution?.id ?? null,
};
};

Expand Down

0 comments on commit bbd50ad

Please sign in to comment.