fix(global-approvals): return grant statuses as expired when expiredAt is reached

This commit is contained in:
x032205
2025-12-17 17:12:01 -05:00
parent 19916bc113
commit aae86640fb

View File

@@ -820,7 +820,18 @@ export const approvalPolicyServiceFactory = ({
);
const grants = await approvalRequestGrantsDAL.find({ projectId, type: policyType });
return { grants };
const updatedGrants = grants.map((grant) => {
if (
grant.status === ApprovalRequestGrantStatus.Active &&
grant.expiresAt &&
new Date(grant.expiresAt) < new Date()
) {
return { ...grant, status: ApprovalRequestGrantStatus.Expired };
}
return grant;
});
return { grants: updatedGrants };
};
const getGrantById = async (grantId: string, actor: OrgServiceActor) => {
@@ -843,7 +854,15 @@ export const approvalPolicyServiceFactory = ({
ProjectPermissionSub.ApprovalRequestGrants
);
return { grant };
let status = grant.status;
if (
grant.status === ApprovalRequestGrantStatus.Active &&
grant.expiresAt &&
new Date(grant.expiresAt) < new Date()
) {
status = ApprovalRequestGrantStatus.Expired;
}
return { grant: { ...grant, status } };
};
const revokeGrant = async (