Skip to content

Commit

Permalink
Begin ReassignUserTasks bull task
Browse files Browse the repository at this point in the history
  • Loading branch information
7dev7urandom authored and chrisvire committed Sep 10, 2024
1 parent 700687a commit e1e6d33
Showing 1 changed file with 79 additions and 2 deletions.
81 changes: 79 additions & 2 deletions source/SIL.AppBuilder.Portal/node-server/BullWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Job, Worker } from 'bullmq';
import { BullMQ, prisma } from 'sil.appbuilder.portal.common';
import { BullMQ, DatabaseWrites, prisma } from 'sil.appbuilder.portal.common';
import { RoleId } from 'sil.appbuilder.portal.common/prisma';

export abstract class BullWorker<T, R> {
public worker: Worker;
Expand All @@ -26,13 +27,88 @@ export class ScriptoriaWorker extends BullWorker<BullMQ.ScriptoriaJob, number> {
job.updateProgress(100);
return 0;
}
case BullMQ.ScriptoriaJobType.ReassignUserTasks:
case BullMQ.ScriptoriaJobType.ReassignUserTasks: {
// TODO: Noop
// Should
// Clear preexecuteentries (product transition steps)
// Remove relevant user tasks
// Create new user tasks (send notifications)
// Recreate preexecute entries
const products = await prisma.products.findMany({
where: {
ProjectId: job.data.projectId
},
include: {
ProductTransitions: true
}
});
for (const product of products) {
// Clear PreExecuteEntries
await DatabaseWrites.productTransitions.deleteMany({
where: {
WorkflowUserId: null,
ProductId: product.Id,
DateTransition: null
}
});
// Clear existing UserTasks
await DatabaseWrites.userTasks.deleteMany({
where: {
ProductId: product.Id
}
});
// Create tasks for all users that could perform this activity
// TODO: this comes from dwkit GetAllActorsFor(Direct|Reverse)CommandTransitions
const organizationId = (
await prisma.projects.findUnique({
where: {
Id: job.data.projectId
},
include: {
Organization: true
}
})
).OrganizationId;
// All users that own the project or are org admins
const allUsersWithAction = await prisma.users.findMany({
where: {
OR: [
{
UserRoles: {
some: {
OrganizationId: organizationId,
RoleId: RoleId.OrgAdmin
}
}
},
{
Projects: {
some: {
Id: job.data.projectId
}
}
}
]
}
});
// TODO: DWKit: Need ActivityName and Status from dwkit implementation
const createdTasks = allUsersWithAction.map((user) => ({
UserId: user.Id,
ProductId: product.Id,
ActivityName: null,
Status: null
}));
await DatabaseWrites.userTasks.createMany({
data: createdTasks
});
for (const task of createdTasks) {
// Send notification for the new task
// TODO
// sendNotification(task);
}
// TODO: DWKit: CreatePreExecuteEntries
}

return (
await prisma.userTasks.findMany({
where: {
Expand All @@ -43,5 +119,6 @@ export class ScriptoriaWorker extends BullWorker<BullMQ.ScriptoriaJob, number> {
})
).length;
}
}
}
}

0 comments on commit e1e6d33

Please sign in to comment.