blob: dd45a56a0b437c2a55a5ea8cbda16bf3ce1e76f0 (
plain)
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
|
"use server";
import { BasicContractView } from "@/db/schema";
import { getTriggeredRedFlagQuestions } from "@/lib/compliance/red-flag-notifier";
/**
* 여러 계약서에 대한 Red Flag 발생 여부를 한 번에 확인
*/
export async function checkRedFlagsForContracts(
contracts: BasicContractView[]
): Promise<Record<number, boolean>> {
const result: Record<number, boolean> = {};
// 준법서약 템플릿인 계약서만 필터링
const complianceContracts = contracts.filter(contract =>
contract.templateName?.includes('준법')
);
if (complianceContracts.length === 0) {
return result;
}
// 각 계약서에 대해 Red Flag 발생 여부 확인
const redFlagChecks = await Promise.all(
complianceContracts.map(async (contract) => {
try {
const triggeredFlags = await getTriggeredRedFlagQuestions(contract.id);
return {
contractId: contract.id,
hasRedFlag: triggeredFlags.length > 0
};
} catch (error) {
console.error(`Error checking red flags for contract ${contract.id}:`, error);
return {
contractId: contract.id,
hasRedFlag: false
};
}
})
);
// 결과를 Record 형태로 변환
redFlagChecks.forEach(check => {
result[check.contractId] = check.hasRedFlag;
});
return result;
}
|