import Column from "@entity-access/entity-access/dist/decorators/Column.js"; import { RelateTo } from "@entity-access/entity-access/dist/decorators/Relate.js"; import Table from "@entity-access/entity-access/dist/decorators/Table.js"; import { StoreJournal } from "./StoreJournal.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; import Sql from "@entity-access/entity-access/dist/sql/Sql.js"; import StorePaymentGateway from "./StorePaymentGateway.js"; import Index from "@entity-access/entity-access/dist/decorators/Index.js"; const statusTypeArray = ["paid", "failed", "timeout"] as const; export type paymentStatusType = typeof statusTypeArray[number]; const refundTypeArray = ["started", "refunded"] as const; export type refundType = typeof refundTypeArray[number]; @Table("StorePaymentAttempt") @Index({ name: "IX_StorePaymentAttempt_Pending", columns: [ { name: (x) => x.attemptID, descending: false }, { name: (x) => x.status, descending: false } ], filter: (x) => x.status === null }) export default class StorePaymentAttempt { @Column({ dataType: "BigInt", key: true, generated: "identity"}) attemptID: number; @Column({ dataType: "BigInt"}) @RelateTo(StoreJournal, { property: (x) => x.order, inverseProperty: (x) => x.paymentAttempts, foreignKeyConstraint: { name: "FC_StorePaymentAttempt_OrderID", onDelete: "cascade" } }) orderID: number; @Column({ dataType: "BigInt"}) @RelateTo(StorePaymentGateway, { property: (x) => x.gateway, inverseProperty: (x) => x.paymentAttempts, foreignKeyConstraint: { name: "FC_StorePaymentAttempt_OrderID", onDelete: "cascade" } }) gatewayID: number; @Column({ dataType: "Char", length: 400, nullable: true }) externalID: string; @Column({ dataType: "DateTime", default: () => Sql.date.now()}) dateCreated: DateTime; @Column({ dataType: "DateTime", default: () => Sql.date.now()}) dateUpdated: DateTime; @Column({ dataType: "Char", length: 20, enum: statusTypeArray, nullable: true}) status: paymentStatusType; @Column({ dataType: "Char", nullable: true}) url: string; @Column({ dataType: "Char", nullable: true }) content: string; @Column({ dataType: "Char", length: 20, nullable: true}) refund: refundType; order: StoreJournal; gateway: StorePaymentGateway; }