- New nullable purchase_url column on components - Store/update validators accept an optional purchaseUrl (must be a valid absolute URL with a protocol when provided) - components/create.vue: NewPartSearch import now also fills purchaseUrl from the scraped part's source URL (pc-builder.io product page); the field remains manually editable for second-hand parts entered by hand - components/edit.vue: purchaseUrl is editable after creation - components/show.vue: displays the purchase site as a clickable link when present - 4 new functional tests: create with/without a purchase URL, invalid URL rejected (asserts the Inertia inputErrorsBag flash, not a raw 422 - content negotiation only returns JSON for XHR/API-style requests), and updating an existing component's purchase URL
42 lines
951 B
TypeScript
42 lines
951 B
TypeScript
import { DateTime } from 'luxon'
|
|
import { BaseModel, belongsTo, column } from '@adonisjs/lucid/orm'
|
|
import ComponentType from '#models/component_type'
|
|
import type { BelongsTo } from '@adonisjs/lucid/types/relations'
|
|
|
|
export default class Component extends BaseModel {
|
|
@column({ isPrimary: true })
|
|
declare id: number
|
|
|
|
@column()
|
|
declare name: string
|
|
|
|
@column()
|
|
declare price: number
|
|
|
|
@column({ serializeAs: null })
|
|
declare typeId: number
|
|
|
|
@belongsTo(() => ComponentType, {
|
|
foreignKey: 'typeId',
|
|
})
|
|
declare type: BelongsTo<typeof ComponentType>
|
|
|
|
@column()
|
|
declare computerId: number | null
|
|
|
|
@column()
|
|
declare purchaseUrl: string | null
|
|
|
|
@column({ serializeAs: null })
|
|
declare userId: number
|
|
|
|
@column.date()
|
|
declare purchaseDate: DateTime
|
|
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime
|
|
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
}
|