import Column from "@entity-access/entity-access/dist/decorators/Column.js"; import Index from "@entity-access/entity-access/dist/decorators/Index.js"; import { RelateTo } from "@entity-access/entity-access/dist/decorators/Relate.js"; import Table from "@entity-access/entity-access/dist/decorators/Table.js"; import Sql from "@entity-access/entity-access/dist/sql/Sql.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; import EmailAddress from "./EmailAddress.js"; import MultiForeignKeys from "@entity-access/entity-access/dist/decorators/ForeignKey.js"; import MailboxContact from "./MailboxContact.js"; const activities = [ "sent", "rejected", "delivery-failed"] as const; export type deliveryActivities = typeof activities[number]; @Table("DeliveryStatus") @Index({ name: "IX_DeliveryStatus_EmailAddress_DateCreated", columns:[ { name: (x) => x.dateCreated, descending: false } ] }) @Index({ name: "IX_DeliveryStatus_Activity", columns:[ { name: (x) => x.emailAddressID, descending: false }, { name: (x) => x.mailboxID, descending: false }, { name: (x) => x.activity, descending: false} ] }) export default class DeliveryStatus { @Column({ dataType: "BigInt", key: true, generated: "identity"}) activityID: number; @Column({ dataType: "BigInt", nullable: true}) emailID: number; @Column({ dataType: "BigInt", nullable: true}) mailboxID: number; @Column({ dataType: "BigInt"}) @RelateTo(EmailAddress, { property: (x) => x.emailAddress, inverseProperty: (x) => x.deliveryStatuses }) emailAddressID: number; @Column({ dataType: "BigInt", nullable: true}) logID: number; @Column({ dataType: "Char", length: 50, enum: activities }) activity: deliveryActivities; @Column({ dataType: "DateTime", default: () => Sql.date.now()}) dateCreated: DateTime; emailAddress: EmailAddress; @MultiForeignKeys(MailboxContact, { foreignKeys: [ { foreignKey: (x) => x.mailboxID, key: (x) => x.mailboxID}, { foreignKey: (x) => x.emailAddressID, key: (x) => x.emailAddressID} ], inverseProperty: (x) => x.deliveryStatuses }) mailboxContact: MailboxContact; }