Skip to content

Commit

Permalink
Merge pull request #4214 from bcgov/chore/4212
Browse files Browse the repository at this point in the history
refactor(4212): add private cloud prefix to MOU tasks
  • Loading branch information
junminahn authored Nov 12, 2024
2 parents 03cb2c5 + 608c3d8 commit c938397
Show file tree
Hide file tree
Showing 24 changed files with 54 additions and 47 deletions.
2 changes: 1 addition & 1 deletion app/app/api/admin/task/sign-mou/resend/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const GET = apiHandler(async ({ session }) => {

const task = await prisma.task.findFirst({
where: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('List Public Cloud Product Requests - Permissions', () => {

const task1 = await prisma.task.findFirst({
where: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand All @@ -63,7 +63,7 @@ describe('List Public Cloud Product Requests - Permissions', () => {
await mockSessionByRole(GlobalRole.BillingReviewer);
const task2 = await prisma.task.findFirst({
where: {
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const POST = apiHandler(async ({ pathParams, body, session }) => {
await prisma.task.update({
where: {
id: taskId,
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
OR: [{ userIds: { has: session.user.id } }, { roles: { hasSome: session.roles } }],
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const POST = apiHandler(async ({ pathParams, body, session }) => {
prisma.task.update({
where: {
id: taskId,
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
OR: [{ userIds: { has: session.user.id } }, { roles: { hasSome: session.roles } }],
data: {
Expand All @@ -50,7 +50,7 @@ export const POST = apiHandler(async ({ pathParams, body, session }) => {
}),
prisma.task.create({
data: {
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
roles: [GlobalRole.BillingReviewer],
data: {
Expand Down
2 changes: 1 addition & 1 deletion app/app/api/public-cloud/products/_operations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default async function createOp({ session, body }: { session: Session; bo
if (newRequest.decisionData.expenseAuthorityId && !newRequest.decisionData.billing.signed) {
const taskProm = prisma.task.create({
data: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
userIds: [newRequest.decisionData.expenseAuthorityId],
data: {
Expand Down
4 changes: 2 additions & 2 deletions app/app/api/public-cloud/products/_operations/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Delete Public Cloud Product - Permissions', () => {

const task = await prisma.task.findFirst({
where: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand All @@ -64,7 +64,7 @@ describe('Delete Public Cloud Product - Permissions', () => {

const task = await prisma.task.findFirst({
where: {
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand Down
4 changes: 2 additions & 2 deletions app/app/api/public-cloud/products/_operations/read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Read Public Cloud Product - Permissions', () => {

const task = await prisma.task.findFirst({
where: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand All @@ -78,7 +78,7 @@ describe('Read Public Cloud Product - Permissions', () => {

const task = await prisma.task.findFirst({
where: {
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand Down
4 changes: 2 additions & 2 deletions app/app/api/public-cloud/products/_operations/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('Update Public Cloud Product - Permissions', () => {

const task = await prisma.task.findFirst({
where: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand All @@ -94,7 +94,7 @@ describe('Update Public Cloud Product - Permissions', () => {

const task = await prisma.task.findFirst({
where: {
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand Down
4 changes: 2 additions & 2 deletions app/app/api/public-cloud/products/download/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('Download Public Cloud Products - Permissions', () => {

const task1 = await prisma.task.findFirst({
where: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand All @@ -93,7 +93,7 @@ describe('Download Public Cloud Products - Permissions', () => {
await mockSessionByRole(GlobalRole.BillingReviewer);
const task2 = await prisma.task.findFirst({
where: {
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand Down
4 changes: 2 additions & 2 deletions app/app/api/public-cloud/products/search/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Search Public Cloud Products - Permissions', () => {

const task1 = await prisma.task.findFirst({
where: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand All @@ -75,7 +75,7 @@ describe('Search Public Cloud Products - Permissions', () => {
await mockSessionByRole(GlobalRole.BillingReviewer);
const task2 = await prisma.task.findFirst({
where: {
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Provision Public Cloud Request', () => {

const task = await prisma.task.findFirst({
where: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand All @@ -60,7 +60,7 @@ describe('Provision Public Cloud Request', () => {

const task = await prisma.task.findFirst({
where: {
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand Down
4 changes: 2 additions & 2 deletions app/app/api/public-cloud/requests/[id]/decision/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async function makeBasicProductMouReview() {

const task1 = await prisma.task.findFirst({
where: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand All @@ -79,7 +79,7 @@ async function makeBasicProductMouReview() {
await mockSessionByRole(GlobalRole.BillingReviewer);
const task2 = await prisma.task.findFirst({
where: {
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand Down
8 changes: 4 additions & 4 deletions app/app/api/public-cloud/requests/search/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Search Public Cloud Requests - Permissions', () => {

const task1 = await prisma.task.findFirst({
where: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand All @@ -75,7 +75,7 @@ describe('Search Public Cloud Requests - Permissions', () => {
await mockSessionByRole(GlobalRole.BillingReviewer);
const task2 = await prisma.task.findFirst({
where: {
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand Down Expand Up @@ -242,7 +242,7 @@ describe('Search Public Cloud Requests - Validations', () => {

const task1 = await prisma.task.findFirst({
where: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand All @@ -262,7 +262,7 @@ describe('Search Public Cloud Requests - Validations', () => {
await mockSessionByRole(GlobalRole.BillingReviewer);
const task2 = await prisma.task.findFirst({
where: {
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand Down
8 changes: 4 additions & 4 deletions app/app/api/tasks/assigned/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export const GET = apiHandler(async ({ session }) => {

for (const task of tasks) {
switch (task.type) {
case TaskType.SIGN_MOU:
case TaskType.REVIEW_MOU:
case TaskType.SIGN_PUBLIC_CLOUD_MOU:
case TaskType.REVIEW_PUBLIC_CLOUD_MOU:
const data = task.data as { licencePlate: string };
licencePlates.push(data.licencePlate);
}
Expand All @@ -56,8 +56,8 @@ export const GET = apiHandler(async ({ session }) => {

processedTasks = processedTasks.map((task) => {
switch (task.type) {
case TaskType.SIGN_MOU:
case TaskType.REVIEW_MOU:
case TaskType.SIGN_PUBLIC_CLOUD_MOU:
case TaskType.REVIEW_PUBLIC_CLOUD_MOU:
const data = task.data as { licencePlate: string };
const request = requests.find((req) => req.licencePlate === data.licencePlate);
if (request) {
Expand Down
4 changes: 2 additions & 2 deletions app/app/api/v1/public-cloud/products/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('API: List Public Cloud Products - Permissions', () => {

const task1 = await prisma.task.findFirst({
where: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand All @@ -75,7 +75,7 @@ describe('API: List Public Cloud Products - Permissions', () => {
await mockSessionByRole(GlobalRole.BillingReviewer);
const task2 = await prisma.task.findFirst({
where: {
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand Down
4 changes: 2 additions & 2 deletions app/components/layouts/SideTasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { getAssignedTasks } from '@/services/backend/tasks';
import { formatDate } from '@/utils/date';

const taskTypeLabels = {
[TaskType.SIGN_MOU]: 'Sign MOU',
[TaskType.REVIEW_MOU]: 'Review MOU',
[TaskType.SIGN_PUBLIC_CLOUD_MOU]: 'Sign Public Cloud MOU',
[TaskType.REVIEW_PUBLIC_CLOUD_MOU]: 'Review Public Cloud MOU',
};

const taskStatusColors = {
Expand Down
2 changes: 1 addition & 1 deletion app/components/modal/publicCloudMouReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const openPublicCloudMouReviewModal = createModal<ModalProps, ModalState>
if (formData.confirmed) {
const task = session?.tasks.find(
(tsk) =>
tsk.type === TaskType.REVIEW_MOU &&
tsk.type === TaskType.REVIEW_PUBLIC_CLOUD_MOU &&
tsk.status === TaskStatus.ASSIGNED &&
(tsk.data as { licencePlate: string }).licencePlate === licencePlate,
);
Expand Down
2 changes: 1 addition & 1 deletion app/components/modal/publicCloudMouSign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const openPublicCloudMouSignModal = createModal<ModalProps, ModalState>({
if (formData.confirmed) {
const task = session?.tasks.find(
(tsk) =>
tsk.type === TaskType.SIGN_MOU &&
tsk.type === TaskType.SIGN_PUBLIC_CLOUD_MOU &&
tsk.status === TaskStatus.ASSIGNED &&
(tsk.data as { licencePlate: string }).licencePlate === licencePlate,
);
Expand Down
4 changes: 2 additions & 2 deletions app/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,8 @@ enum EventType {
}

enum TaskType {
SIGN_MOU
REVIEW_MOU
SIGN_PUBLIC_CLOUD_MOU
REVIEW_PUBLIC_CLOUD_MOU
}

enum TaskStatus {
Expand Down
4 changes: 2 additions & 2 deletions app/services/api-test/public-cloud/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function runEmouWorkflows(reqData: any) {

let task = await prisma.task.findFirst({
where: {
type: TaskType.SIGN_MOU,
type: TaskType.SIGN_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand All @@ -42,7 +42,7 @@ async function runEmouWorkflows(reqData: any) {

task = await prisma.task.findFirst({
where: {
type: TaskType.REVIEW_MOU,
type: TaskType.REVIEW_PUBLIC_CLOUD_MOU,
status: TaskStatus.ASSIGNED,
data: {
equals: {
Expand Down
6 changes: 3 additions & 3 deletions app/services/db/models/public-cloud-product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function baseFilter(session: Session) {
];

const licencePlatesFromTasks = session.tasks
.filter((task) => [TaskType.SIGN_MOU, TaskType.REVIEW_MOU].includes(task.type))
.filter((task) => [TaskType.SIGN_PUBLIC_CLOUD_MOU, TaskType.REVIEW_PUBLIC_CLOUD_MOU].includes(task.type))
.map((task) => (task.data as { licencePlate: string }).licencePlate);

if (session.user.id) {
Expand Down Expand Up @@ -117,15 +117,15 @@ async function decorate<T extends PublicCloudProductSimple & Partial<Pick<Public
canSignMou =
!doc.billing.signed &&
session.tasks
.filter((task) => task.type === TaskType.SIGN_MOU && task.status === TaskStatus.ASSIGNED)
.filter((task) => task.type === TaskType.SIGN_PUBLIC_CLOUD_MOU && task.status === TaskStatus.ASSIGNED)
.map((task) => (task.data as { licencePlate: string }).licencePlate)
.includes(doc.licencePlate);

canApproveMou =
doc.billing.signed &&
!doc.billing.approved &&
session.tasks
.filter((task) => task.type === TaskType.REVIEW_MOU && task.status === TaskStatus.ASSIGNED)
.filter((task) => task.type === TaskType.REVIEW_PUBLIC_CLOUD_MOU && task.status === TaskStatus.ASSIGNED)
.map((task) => (task.data as { licencePlate: string }).licencePlate)
.includes(doc.licencePlate);
}
Expand Down
7 changes: 3 additions & 4 deletions app/services/db/models/public-cloud-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function baseFilter(session: Session) {
const licencePlates = products.map(({ licencePlate }) => licencePlate);

const licencePlatesFromTasks = session.tasks
.filter((task) => [TaskType.SIGN_MOU, TaskType.REVIEW_MOU].includes(task.type))
.filter((task) => [TaskType.SIGN_PUBLIC_CLOUD_MOU, TaskType.REVIEW_PUBLIC_CLOUD_MOU].includes(task.type))
.map((task) => (task.data as { licencePlate: string }).licencePlate);

const filter: Prisma.PublicCloudRequestWhereInput = {
Expand All @@ -40,7 +40,6 @@ async function decorate<T extends PublicCloudRequestSimple | PublicCloudRequestD
detail: boolean,
) {
let canReview = doc.decisionStatus === DecisionStatus.PENDING && session.permissions.reviewAllPublicCloudRequests;

let canSignMou = false;
let canApproveMou = false;

Expand All @@ -49,15 +48,15 @@ async function decorate<T extends PublicCloudRequestSimple | PublicCloudRequestD
canSignMou =
!doc.decisionData.billing.signed &&
session.tasks
.filter((task) => task.type === TaskType.SIGN_MOU && task.status === TaskStatus.ASSIGNED)
.filter((task) => task.type === TaskType.SIGN_PUBLIC_CLOUD_MOU && task.status === TaskStatus.ASSIGNED)
.map((task) => (task.data as { licencePlate: string }).licencePlate)
.includes(doc.licencePlate);

canApproveMou =
doc.decisionData.billing.signed &&
!doc.decisionData.billing.approved &&
session.tasks
.filter((task) => task.type === TaskType.REVIEW_MOU && task.status === TaskStatus.ASSIGNED)
.filter((task) => task.type === TaskType.REVIEW_PUBLIC_CLOUD_MOU && task.status === TaskStatus.ASSIGNED)
.map((task) => (task.data as { licencePlate: string }).licencePlate)
.includes(doc.licencePlate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const up = async (db, client) => {

const taskData = billings.map((billing) => {
return {
type: 'SIGN_MOU',
type: 'SIGN_PUBLIC_CLOUD_MOU',
status: 'ASSIGNED',
userIds: [String(billing.expenseAuthorityId)],
data: {
Expand Down
Loading

0 comments on commit c938397

Please sign in to comment.