33 lines
869 B
TypeScript
33 lines
869 B
TypeScript
import History from '#models/history'
|
|
import type { SupplierPricePoint, EbayData } from '#models/history'
|
|
|
|
interface RecordHistoryInput {
|
|
username: string
|
|
productId: number
|
|
dataSources: SupplierPricePoint[]
|
|
dataEbay: EbayData
|
|
aiResult?: Record<string, any> | null
|
|
}
|
|
|
|
/**
|
|
* Lưu snapshot dữ liệu mỗi lần lấy về để AI gợi ý giá.
|
|
*/
|
|
export default class HistoryService {
|
|
static async record(input: RecordHistoryInput): Promise<History> {
|
|
return History.create({
|
|
username: input.username,
|
|
productId: input.productId,
|
|
dataSources: input.dataSources,
|
|
dataEbay: input.dataEbay,
|
|
aiResult: input.aiResult ?? null,
|
|
})
|
|
}
|
|
|
|
static async listForProduct(productId: number, limit = 50) {
|
|
return History.query()
|
|
.where('product_id', productId)
|
|
.orderBy('time', 'desc')
|
|
.limit(limit)
|
|
}
|
|
}
|