Skip to content

Commit

Permalink
Move allUsersByRole to UserRoles.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
FyreByrd committed Oct 10, 2024
1 parent 562b0e3 commit d0f055c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 44 deletions.
41 changes: 41 additions & 0 deletions source/SIL.AppBuilder.Portal/common/databaseProxy/UserRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,44 @@ export async function setUserRolesForOrganization(
})
]);
}

export async function allUsersByRole(projectId: number) {
const project = await prisma.projects.findUnique({
where: {
Id: projectId
},
select: {
Organization: {
select: {
UserRoles: {
where: {
RoleId: RoleId.OrgAdmin
},
select: {
UserId: true
}
}
}
},
OwnerId: true,
Authors: {
select: {
UserId: true
}
}
}
});

const map = new Map<RoleId, number[]>();

map.set(
RoleId.OrgAdmin,
project.Organization.UserRoles.map((u) => u.UserId)
);
map.set(RoleId.AppBuilder, [project.OwnerId]);
map.set(
RoleId.Author,
project.Authors.map((a) => a.UserId)
);
return map;
}
42 changes: 0 additions & 42 deletions source/SIL.AppBuilder.Portal/common/databaseProxy/utility.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import prisma from '../prisma.js';
import { RoleId } from '../public/prisma.js';

export type RequirePrimitive<T> = {
[K in keyof T]: Extract<T[K], string | number | boolean | Date>;
Expand Down Expand Up @@ -37,44 +36,3 @@ export async function getOrCreateUser(profile: {
}
});
}

export async function allUsersByRole(projectId: number) {
const project = await prisma.projects.findUnique({
where: {
Id: projectId
},
select: {
Organization: {
select: {
UserRoles: {
where: {
RoleId: RoleId.OrgAdmin
},
select: {
UserId: true
}
}
}
},
OwnerId: true,
Authors: {
select: {
UserId: true
}
}
}
});

const map = new Map<RoleId, number[]>();

map.set(
RoleId.OrgAdmin,
project.Organization.UserRoles.map((u) => u.UserId)
);
map.set(RoleId.AppBuilder, [project.OwnerId]);
map.set(
RoleId.Author,
project.Authors.map((a) => a.UserId)
);
return map;
}
2 changes: 1 addition & 1 deletion source/SIL.AppBuilder.Portal/common/workflow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import prisma from '../prisma.js';
import { RoleId, ProductTransitionType } from '../public/prisma.js';
import { scriptoria } from '../bullmq.js';
import { BullMQ } from '../index.js';
import { allUsersByRole } from '../databaseProxy/utility.js';
import { allUsersByRole } from '../databaseProxy/UserRoles.js';
import { Prisma } from '@prisma/client';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class Modify extends ScriptoriaJobExecutor<BullMQ.ScriptoriaJobType.UserT
job.updateProgress(90);
} else {
job.updateProgress(25);
const allUsers = await DatabaseWrites.utility.allUsersByRole(projectId);
const allUsers = await DatabaseWrites.userRoles.allUsersByRole(projectId);
job.updateProgress(30);
if (job.data.operation.type !== BullMQ.UserTasks.OpType.Create) {
// Clear existing UserTasks
Expand Down

0 comments on commit d0f055c

Please sign in to comment.