You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import { Prisma } from "@prisma/client" ;
import { prisma } from "@/lib/prisma" ;
import type { AlertDetail , AlertType } from "@/modules/alert/types" ;
export type WriteAlertOptions = {
quoteId? : string ;
cargoHash? : string ;
detail? : AlertDetail ;
} ;
/**
* 通用预警写入( task-050)
* 失败仅 log, 不阻断主流程
*/
export async function writeAlert (
alertType : AlertType ,
options? : WriteAlertOptions ,
) : Promise < void > {
try {
await prisma . alertLog . create ( {
data : {
alertType ,
quoteId : options?.quoteId ? ? null ,
cargoHash : options?.cargoHash ? ? null ,
detailJson : options?.detail
? ( options . detail as Prisma . InputJsonValue )
: undefined ,
status : "open" ,
} ,
} ) ;
} catch ( error ) {
console . error ( ` [alert] 写入 ${ alertType } 失败: ` , error ) ;
}
}