import Column from "@entity-access/entity-access/dist/decorators/Column.js"; import Table from "@entity-access/entity-access/dist/decorators/Table.js"; import { Email } from "./Email.js"; import Mailbox from "./Mailbox.js"; import EmailAddress from "./EmailAddress.js"; import { RelateTo } from "@entity-access/entity-access/dist/decorators/Relate.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; import Sql from "@entity-access/entity-access/dist/sql/Sql.js"; import Index from "@entity-access/entity-access/dist/decorators/Index.js"; import MailboxContact from "./MailboxContact.js"; import MultiForeignKeys from "@entity-access/entity-access/dist/decorators/ForeignKey.js"; @Table("MailboxContactEmails") @Index({ name: "IX_MailboxContactEmails_Date_Received", columns: [ { name: (x) => x.mailboxID, descending: false }, { name: (x) => x.emailAddressID, descending: false }, {name: (x) => x.dateReceived, descending: true } ] }) @Index({ name: "IX_MailboxContactEmails_Email_ID", columns: [ { name: (x) => x.emailID, descending: true }, ] }) export default class MailboxContactEmail { @Column({ key: true, dataType: "BigInt", order: 1}) @RelateTo(Mailbox, { property: (mte) => mte.mailbox, inverseProperty: (mb) => mb.threadEmails, foreignKeyConstraint: { onDelete: "restrict" } }) mailboxID: number; @Column({ key: true, dataType: "BigInt", order: 2}) @RelateTo(EmailAddress, { property: (x) => x.emailAddress, inverseProperty: (x) => x.mailboxContactEmails }) emailAddressID: number; @Column({ key: true, dataType: "BigInt", order: 3, indexOrder: "descending"}) @RelateTo(Email, { property: (mte) => mte.email, inverseProperty: (e) => e.threadContacts, foreignKeyConstraint: { onDelete: "cascade" } }) emailID: number; @Column({ default:() => Sql.date.now()}) dateReceived: DateTime; @Column({ nullable: true }) timeRead: DateTime; @Column({ dataType: "Boolean", default: () => false }) archived: boolean; /** * Caching this field here will improve the caching. * As query engine can avoid joining Email table. */ @Column({ dataType: "Char", length: 200, nullable: true}) engagement: string; email: Email; mailbox: Mailbox; emailAddress: EmailAddress; @MultiForeignKeys(MailboxContact, { foreignKeys: [ { foreignKey: (x) => x.mailboxID, key: (x) => x.mailboxID}, { foreignKey: (x) => x.emailAddressID, key: (x) => x.emailAddressID} ], inverseProperty: (x) => x.contactEmails }) mailboxContact: MailboxContact; // /** // * You can use this property to fetch email content when htmlBody property is null, // * this is done to reduce html storage in database. // */ // @ReadOnlyJsonProperty // public get htmlBodyUrl() { // if (this.signedFileLogID) { // return apiPath(`/api/emails/content/html/${this.emailID}/${this.signedFileLogID}`); // } // const { email } = this; // if (email) { // let { dateUpdated } = email; // dateUpdated = DateTime.from(dateUpdated); // if (dateUpdated) { // return apiPath(`/api/emails/content/html/${this.emailID}/0/${dateUpdated.msSinceEpoch.toString(36)}`); // } // } // return apiPath(`/api/emails/content/html/${this.emailID}`); // } // public set htmlBodyUrl(v) { // // do nothing... // } // [GraphService.appendToGraph]() { // return { // htmlBodyUrl: this.htmlBodyUrl // }; // } }