import CheckConstraint from "@entity-access/entity-access/dist/decorators/CheckConstraint.js"; 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 { StoreJournalEntry } from "./StoreJournalEntry.js"; import { StoreItem } from "./StoreItem.js"; import WebSite from "./WebSite.js"; import { User } from "./User.js"; import type { StoreJournal } from "./StoreJournal.js"; import type { StoreJournalLineItem } from "./StoreJournalLineItem.js"; import type { StoreAccountAddress } from "./StoreAddress.js"; import type StoreAccountEmail from "./StoreAccountEmail.js"; import type StoreAccountPhone from "./StoreAccountPhone.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; import Sql from "@entity-access/entity-access/dist/sql/Sql.js"; import type StorePaymentGateway from "./StorePaymentGateway.js"; import type StoreSubscription from "./StoreSubscription.js"; @Table("StoreAccounts") @CheckConstraint({ name: "CC_Store_Account_Head_Name", filter: (x) => (x.head !== null && x.parentID === null) || x.parentID !== null }) @Index({ name: "IX_Store_Account_Head", columns: [ { name: (x) => x.storeID, descending: true }, { name: (x) => x.head, descending: false } ], filter: (x) => x.head !== null }) @Index({ name: "IX_Store_Account_Unique_Name", columns: [ { name: (x) => x.storeID, descending: true }, { name: (x) => x.parentID, descending: false }, { name: (x) => x.name, descending: false } ], unique: true }) export class StoreAccount { @Column({ dataType: "BigInt", key: true, generated: "identity"}) public accountID: number; @Column({ dataType: "Char", length: 400, nullable: true }) public path: string; @Column({ dataType: "BigInt" }) @RelateTo(WebSite, { property: (x) => x.store, inverseProperty: (x) => x.storeAccounts, foreignKeyConstraint: { name: "FC_StoreAccounts_StoreID", onDelete: "restrict" } }) public storeID: number; @Column({ dataType: "BigInt", nullable: true }) @RelateTo(User, { property: (x) => x.user, inverseProperty: (x) => x.storeAccounts, foreignKeyConstraint: { name: "FC_StoreAccounts_Customer_UserID", onDelete: "restrict" } }) public userID: number; @Column({ dataType: "BigInt", nullable: true }) @RelateTo(StoreAccount, { property: (x) => x.parent, inverseProperty: (x) => x.children, foreignKeyConstraint: { name: "FC_StoreAccounts_ParentID", onDelete: "restrict" } }) public parentID: number; // @Column({ dataType: "BigInt", nullable: true }) // @RelateTo({ // type: () => StoreItem, // property: (x) => x.item, // inverseProperty: (x) => x.storeAccounts // }) // public itemID: number; @Column({ dataType: "Char", length: 50, nullable: true }) public head: string; @Column({ dataType: "DateTime", default: () => Sql.date.now()}) public dateCreated: DateTime; /** * Could be, inventory or money */ @Column({ dataType: "Char", length: 50, default: () => "money" }) public ledgerType: string; @Column({ dataType: "Char", length: 400 }) public name: string; @Column({ dataType: "Char", nullable: true }) public description: string; @Column({ dataType: "Decimal", default: () => 0 }) balance: number; @Column({ dataType: "BigInt", nullable: true}) billingAddressID: number; @Column({ dataType: "BigInt", nullable: true}) shippingAddressID: number; store: WebSite; item: StoreItem; parent: StoreAccount; user: User; children: StoreAccount[]; entries: StoreJournalEntry[]; vendorItems: StoreItem[]; soldInvoices: StoreJournal[]; boughtInvoices: StoreJournal[]; soldItems: StoreJournalLineItem[]; addresses: StoreAccountAddress[]; emails: StoreAccountEmail[]; phones: StoreAccountPhone[]; storePaymentGateway: StorePaymentGateway; boughtSubscriptions: StoreSubscription[]; }