Reformatted the attachment model

This commit is contained in:
Andreas 2024-06-23 22:50:56 +02:00
parent dff64b31a4
commit de220ae02a

View File

@ -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<Attachment>;
type AttachmentCreationAttributes = InferCreationAttributes<Attachment>;
export class Attachment extends Model<AttachmentAttributes,AttachmentCreationAttributes> {
export class Attachment extends Model<InferAttributes<Attachment>, InferCreationAttributes<Attachment>> {
@PrimaryKey
@AutoIncrement
@Attribute(DataTypes.INTEGER)
@ -14,17 +31,17 @@ export class Attachment extends Model<InferAttributes<Attachment>, InferCreation
declare id: CreationOptional<number>;
@Attribute(DataTypes.STRING)
declare filename: string
// Associations
@Attribute(DataTypes.UUIDV4)
@NotNull
declare bucket_id: ForeignKey<Bucket['id']>;
@BelongsTo(()=>Bucket,{foreignKey: 'bucket_id', inverse: {type: "hasMany", as: 'attachments'}})
declare bucket?:NonAttribute<Bucket>;
@BelongsTo(() => Bucket, { foreignKey: 'bucket_id', inverse: { type: "hasMany", as: 'attachments' } })
declare bucket?: NonAttribute<Bucket>;
declare static associations: {
bucket: Association<Bucket, Attachment>;
};
}