Listing_SuggestPrice/backend/app/models/log.ts

40 lines
1.1 KiB
TypeScript

import { DateTime } from 'luxon'
import { BaseModel, column, belongsTo } from '@adonisjs/lucid/orm'
import type { BelongsTo } from '@adonisjs/lucid/types/relations'
import Product from '#models/product'
/**
* Nhật ký thao tác CUD của người dùng lên sản phẩm.
*/
export default class Log extends BaseModel {
@column({ isPrimary: true })
declare id: number
@column()
declare username: string
/** Tên hành động dễ đọc, vd: "Tạo sản phẩm", "Cập nhật giá". */
@column()
declare actionName: string
/** Mã hành động: create | update | delete | import | sync | suggest. */
@column()
declare action: string
@column()
declare productId: number | null
/** Dữ liệu trước/sau (diff) — tùy chọn, hữu ích để truy vết. */
@column({
prepare: (v) => (v === null || v === undefined ? null : JSON.stringify(v)),
consume: (v) => (typeof v === 'string' ? JSON.parse(v) : v),
})
declare meta: Record<string, any> | null
@column.dateTime({ autoCreate: true, columnName: 'time' })
declare time: DateTime
@belongsTo(() => Product)
declare product: BelongsTo<typeof Product>
}