feat(access-request): code improvements

This commit is contained in:
carlosmonastyrski
2025-05-30 14:53:12 -03:00
parent 858ec2095e
commit 85fefb2a82
2 changed files with 6 additions and 4 deletions

View File

@@ -1,5 +1,7 @@
import { Knex } from "knex";
import { ApprovalStatus } from "@app/ee/services/secret-approval-request/secret-approval-request-types";
import { TableName } from "../schemas";
export async function up(knex: Knex): Promise<void> {
@@ -17,12 +19,12 @@ export async function up(knex: Knex): Promise<void> {
if (!hasStatusColumn) {
await knex.schema.alterTable(TableName.AccessApprovalRequest, (t) => {
t.string("status").defaultTo("pending").notNullable();
t.string("status").defaultTo(ApprovalStatus.PENDING).notNullable();
});
// Update existing rows based on business logic
// If privilegeId is not null, set status to "approved"
await knex(TableName.AccessApprovalRequest).whereNotNull("privilegeId").update({ status: "approved" });
await knex(TableName.AccessApprovalRequest).whereNotNull("privilegeId").update({ status: ApprovalStatus.APPROVED });
// If privilegeId is null and there's a rejected reviewer, set to "rejected"
const rejectedRequestIds = await knex(TableName.AccessApprovalRequestReviewer)
@@ -35,7 +37,7 @@ export async function up(knex: Knex): Promise<void> {
await knex(TableName.AccessApprovalRequest)
.whereNull("privilegeId")
.whereIn("id", rejectedRequestIds)
.update({ status: "rejected" });
.update({ status: ApprovalStatus.REJECTED });
}
}
}

View File

@@ -392,7 +392,7 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
]
});
// an approval is pending if there is no reviewer rejections, no privilege ID is set and the number of approvals is less than the number of approvals required
// an approval is pending if there is no reviewer rejections, no privilege ID is set and the status is pending
const pendingApprovals = formattedRequests.filter(
(req) =>
!req.privilegeId &&