1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
"use server";
import { BasicContractView } from "@/db/schema";
import { getComplianceResponseByBasicContractId } from "@/lib/compliance/services";
type RedFlagResolutionState = {
resolved: boolean;
resolvedAt: Date | null;
pendingApprovalId: string | null;
};
/**
* 여러 계약서에 대한 RED FLAG 해제 상태를 한 번에 확인
*/
export async function checkRedFlagResolutionForContracts(
contracts: BasicContractView[]
): Promise<Record<number, RedFlagResolutionState>> {
const result: Record<number, RedFlagResolutionState> = {};
// 준법서약 템플릿인 계약서만 필터링
const complianceContracts = contracts.filter((contract) =>
contract.templateName?.includes("준법")
);
if (complianceContracts.length === 0) {
return result;
}
const checks = await Promise.all(
complianceContracts.map(async (contract) => {
try {
const response = await getComplianceResponseByBasicContractId(contract.id);
return {
contractId: contract.id,
resolved: Boolean(response?.redFlagResolvedAt),
resolvedAt: response?.redFlagResolvedAt || null,
pendingApprovalId: response?.redFlagResolutionApprovalId ?? null,
};
} catch (error) {
console.error(`Error fetching compliance response for contract ${contract.id}:`, error);
return {
contractId: contract.id,
resolved: false,
resolvedAt: null,
pendingApprovalId: null,
};
}
})
);
checks.forEach((check) => {
result[check.contractId] = {
resolved: check.resolved,
resolvedAt: check.resolvedAt,
pendingApprovalId: check.pendingApprovalId,
};
});
return result;
}
|