wikipedia-game-solver/apps/api/app/models/page.ts

43 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

import { BaseModel, column, manyToMany } from "@adonisjs/lucid/orm"
import type { ManyToMany } from "@adonisjs/lucid/types/relations"
export default class Page extends BaseModel {
protected tableName = "pages"
2024-08-16 02:50:11 +02:00
/**
* Page id is unique for each page on Wikipedia, can be used to link to the page.
* @example `https://${locale}.wikipedia.org/?curid=${pageId}`
*/
@column({ columnName: "id", serializeAs: "id", isPrimary: true })
declare id: number
2024-08-16 02:50:11 +02:00
/**
* Title of the Wikipedia page.
*/
@column({
columnName: "title",
serializeAs: "title",
})
declare title: string
@manyToMany(
() => {
return Page
},
{
pivotTable: "internal_links",
localKey: "id",
relatedKey: "id",
pivotForeignKey: "from_page_id",
pivotRelatedForeignKey: "to_page_id",
serializeAs: "internalLinks",
},
)
declare internalLinks: ManyToMany<typeof Page>
}
2024-08-16 02:50:11 +02:00
export type PageRaw = Pick<Page, "id" | "title">
export type PageWithInternalLinksRaw = PageRaw & {
internalLinks: PageRaw[]
}