import { InferAttributes, InferCreationAttributes } from "sequelize"; import { AllowNull, BelongsTo, Column, DataType, ForeignKey, IsIn, Table, } from "sequelize-typescript"; import { type ImportTaskInput, ImportTaskOutput } from "@shared/schema"; import { ImportableIntegrationService, ImportTaskState } from "@shared/types"; import Import from "./Import"; import IdModel from "./base/IdModel"; import Fix from "./decorators/Fix"; // Not all fields are automatically inferred by Sequelize. // see https://sequelize.org/docs/v7/models/model-typing/#manual-attribute-typing type NonInferredAttributes = { input: ImportTaskInput; }; export type ImportTaskAttributes = InferAttributes> & NonInferredAttributes; export type ImportTaskCreationAttributes< T extends ImportableIntegrationService, > = Partial>> & Partial>; @Table({ tableName: "import_tasks", modelName: "import_task" }) @Fix class ImportTask extends IdModel< ImportTaskAttributes, ImportTaskCreationAttributes > { @IsIn([Object.values(ImportTaskState)]) @Column(DataType.STRING) state: ImportTaskState; @Column(DataType.JSONB) input: ImportTaskInput; @AllowNull @Column(DataType.JSONB) output: ImportTaskOutput | null; @Column error: string | null; // associations @BelongsTo(() => Import, "importId") import: Import; @ForeignKey(() => Import) @Column(DataType.UUID) importId: string; } export default ImportTask;