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 Sql from "@entity-access/entity-access/dist/sql/Sql.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; import { JsonProperty, ReadOnlyJsonProperty } from "@entity-access/server-pages/dist/services/ModelService.js"; import AppFile from "./AppFile.js"; import type { StoreInsight } from "./StoreInsight.js"; import { StoreItemFolder } from "./StoreItemFolder.js"; import type { StoreItemPrice } from "./StoreItemPrice.js"; import type { StoreItemTag } from "./StoreItemTag.js"; import type { StoreItemTax } from "./StoreItemTax.js"; import type { StoreJournalLineItem } from "./StoreJournalLineItem.js"; import { StoreAccount } from "./StoreAccount.js"; import type { StoreMediaFile } from "./StoreMediaFile.js"; import WebSite from "./WebSite.js"; import type StoreCoupon from "./StoreCoupon.js"; import type WebHook from "./WebHook.js"; export const itemTypeArray = ["product", "e-product", "website", "shipping", "service", "tax", "fee", "commission", "variant", "size"] as const; export type itemTypeArrayType = typeof itemTypeArray[number]; export const itemUnitTypeArray = ["year", "month", "kg", "lbs"] as const; export type itemUnitType = typeof itemUnitTypeArray[number]; @Table("StoreItems") export class StoreItem { @Column({ dataType: "BigInt", key: true, generated: "identity"}) public storeItemID: number; @Column({ dataType: "BigInt" }) @RelateTo(WebSite, { property: (x) => x.store, inverseProperty: (x) => x.storeItems, foreignKeyConstraint: { onDelete: "cascade" } }) public storeID: number; @Column({ dataType: "BigInt", nullable: true }) @RelateTo(StoreItemFolder, { property: (x) => x.itemFolder, inverseProperty: (x) => x.items }) public itemFolderID: number; @Column({ dataType: "Char", length: 200 }) public name: string; @Column({ dataType: "Boolean", default: () => true}) public active: boolean; @Column({ dataType: "Char", nullable: true }) public internalNotes: string; @Column({ dataType: "Char", nullable: true }) public description: string; @Column({ dataType:"Char", length: 20, default: () => "product", enum: itemTypeArray}) public itemType: itemTypeArrayType; @Column({ dataType:"Char", length: 50, nullable: true, enum: itemTypeArray}) public itemUnitType: itemUnitType; @Column({ dataType:"Decimal", default: () => 1}) public itemUnit: number; @Column({ dataType: "BigInt", nullable: true }) @RelateTo(AppFile, { property: (x) => x.fileFolder, inverseProperty: (x) => x.storeItems }) public folderID: number; @Column({ dataType: "BigInt", nullable: true }) @RelateTo(StoreItem, { property: (x) => x.sizeFor, inverseProperty: (x) => x.sizes }) public sizeForID: number; @Column({ dataType: "BigInt", nullable: true}) @RelateTo(StoreItem, { property: (x) => x.variantFor, inverseProperty: (x) => x.variants }) public variantForID: number; @Column({ dataType: "DateTime", default: () => Sql.date.now() }) public readonly dateCreated: DateTime; @Column({ dataType: "DateTime", default: () => Sql.date.now() }) public dateUpdated: DateTime; @Column({ dataType: "BigInt", nullable: true}) @RelateTo({ property: (x) => x.vendor, inverseProperty: (x) => x.vendorItems, type: () => StoreAccount }) public vendorID: number; @Column({ dataType: "Decimal", default: () => 0}) @ReadOnlyJsonProperty public price: number; @Column({ dataType: "Decimal", default: () => 0}) @ReadOnlyJsonProperty public maxPrice: number; @Column({ dataType: "Char", length: 20, nullable: true}) public taxCodeLabel: string; @Column({ dataType: "Char", length: 20, nullable: true}) public taxCode: string; /** * Only for website type */ @Column({ dataType: "Decimal", nullable: true}) public webSiteIncludedDomainMaxPrice: number; /** * Only for website type */ @Column({ dataType: "Decimal", nullable: true }) public webSiteMaxStorage: number; public store: WebSite; public vendor: StoreAccount; public storeItemPrices: StoreItemPrice[]; public storeItemTags: StoreItemTag[]; @JsonProperty({}) publicFolderID: string; @ReadOnlyJsonProperty signed: string; sizeFor: StoreItem; variantFor: StoreItem; sizes: StoreItem[]; variants: StoreItem[]; fileFolder: AppFile; insights: StoreInsight[]; lineItems: StoreJournalLineItem[]; storeAccounts: StoreAccount[]; itemFolder: StoreItemFolder; mediaFiles: StoreMediaFile[]; applicableTaxes: StoreItemTax[]; taxItems: StoreItemTax[]; itemCoupons: StoreCoupon[]; webHooks: WebHook[]; // [GraphService.init](sp) { // const ss = ServiceProvider.resolve(sp, SignerService); // const page = ServiceProvider.resolve(sp, Page as any) as Page; // const host = page?.request?.hostName ?? ""; // const { signature, expiry } = ss.signer().sign({ storeItemID: this.storeItemID, host }, { till }); // this.signed = signature + "/" + expiry; // } }