import Log from '#models/log' export type LogAction = 'create' | 'update' | 'delete' | 'import' | 'sync' | 'suggest' interface RecordLogInput { username: string actionName: string action: LogAction productId?: number | null meta?: Record | null } /** * Ghi nhật ký thao tác CUD của người dùng lên sản phẩm. */ export default class LogService { static async record(input: RecordLogInput): Promise { return Log.create({ username: input.username, actionName: input.actionName, action: input.action, productId: input.productId ?? null, meta: input.meta ?? null, }) } /** Ghi log hàng loạt (vd import nhiều dòng). */ static async recordMany(inputs: RecordLogInput[]): Promise { if (!inputs.length) return await Log.createMany( inputs.map((i) => ({ username: i.username, actionName: i.actionName, action: i.action, productId: i.productId ?? null, meta: i.meta ?? null, })) ) } }