43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { DateTime } from 'luxon'
|
|
import { BaseModel, column } from '@adonisjs/lucid/orm'
|
|
|
|
/** Loại thông báo hiển thị cho người dùng. */
|
|
export type NotificationType = 'warning' | 'error' | 'success' | 'news'
|
|
|
|
/**
|
|
* Thông báo hệ thống cho người dùng (giống bảng logs nhưng hướng người dùng):
|
|
* sản phẩm mới khi sync, cảnh báo import trùng, kết quả thao tác...
|
|
* Có trạng thái đã đọc / chưa đọc.
|
|
*/
|
|
export default class Notification extends BaseModel {
|
|
@column({ isPrimary: true })
|
|
declare id: number
|
|
|
|
/** warning | error | success | news */
|
|
@column()
|
|
declare type: NotificationType
|
|
|
|
@column()
|
|
declare title: string
|
|
|
|
@column()
|
|
declare message: string | null
|
|
|
|
/** false = chưa đọc (unread), true = đã đọc. */
|
|
@column()
|
|
declare isRead: boolean
|
|
|
|
/** Dữ liệu kèm theo (vd { productId, sku }) để frontend điều hướng / hành động. */
|
|
@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 })
|
|
declare createdAt: DateTime
|
|
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime
|
|
}
|