From de220ae02adcb1587dd687eefad588af76834116 Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 23 Jun 2024 22:50:56 +0200 Subject: [PATCH] Reformatted the attachment model --- src/model/Attachment.ts | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/model/Attachment.ts b/src/model/Attachment.ts index 6b82fcb..ba2ebbe 100644 --- a/src/model/Attachment.ts +++ b/src/model/Attachment.ts @@ -1,12 +1,29 @@ -import { Association, BelongsToGetAssociationMixin, BelongsToManyGetAssociationsMixin, CreationOptional, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core"; -import { Post } from "./Post"; +import { + Association, + CreationOptional, + DataTypes, + ForeignKey, + InferAttributes, + InferCreationAttributes, + Model, + NonAttribute +} from "@sequelize/core"; + +import { + Attribute, + AutoIncrement, + BelongsTo, + NotNull, + PrimaryKey, + Unique +} from "@sequelize/core/decorators-legacy"; -import { SqliteDialect } from '@sequelize/sqlite3'; -import { Attribute, AutoIncrement, BelongsTo, BelongsToMany, NotNull, PrimaryKey, Unique } from "@sequelize/core/decorators-legacy"; import { Bucket } from "./Bucket"; -import { UUID } from "crypto"; +type AttachmentAttributes = InferAttributes; +type AttachmentCreationAttributes = InferCreationAttributes; + +export class Attachment extends Model { -export class Attachment extends Model, InferCreationAttributes> { @PrimaryKey @AutoIncrement @Attribute(DataTypes.INTEGER) @@ -14,17 +31,17 @@ export class Attachment extends Model, InferCreation declare id: CreationOptional; @Attribute(DataTypes.STRING) declare filename: string - + // Associations @Attribute(DataTypes.UUIDV4) @NotNull declare bucket_id: ForeignKey; - @BelongsTo(()=>Bucket,{foreignKey: 'bucket_id', inverse: {type: "hasMany", as: 'attachments'}}) - declare bucket?:NonAttribute; + @BelongsTo(() => Bucket, { foreignKey: 'bucket_id', inverse: { type: "hasMany", as: 'attachments' } }) + declare bucket?: NonAttribute; declare static associations: { bucket: Association; }; - + }