implemented file upload for attachments

This commit is contained in:
2024-06-11 02:23:22 +02:00
parent e841ba8938
commit 86eb422dd5
23 changed files with 332 additions and 147 deletions
+31
View File
@@ -0,0 +1,31 @@
import { Association, BelongsToGetAssociationMixin, BelongsToManyGetAssociationsMixin, DataTypes, ForeignKey, InferAttributes, InferCreationAttributes, Model, NonAttribute, Sequelize } from "@sequelize/core";
import { Post } from "./Post";
import { SqliteDialect } from '@sequelize/sqlite3';
import { Attribute, AutoIncrement, BelongsTo, BelongsToMany, NotNull, PrimaryKey, Unique } from "@sequelize/core/decorators-legacy";
export class Attachment extends Model<InferAttributes<Attachment>, InferCreationAttributes<Attachment>> {
@PrimaryKey
@AutoIncrement
@Attribute(DataTypes.INTEGER)
@Unique
declare id: number;
@Attribute(DataTypes.STRING)
declare path: string
// Associations
@Attribute(DataTypes.INTEGER)
@NotNull
declare postid: number;
@BelongsTo(()=>Post,{foreignKey: 'postid', inverse: {type: "hasMany", as: 'attachments'}})
declare post?:NonAttribute<Post>;
declare static associations: {
posts: Association<Post, Attachment>;
};
}
const sequelize = new Sequelize({
dialect: SqliteDialect,
storage: 'db.sqlite',
models: [Attachment]
})
+5
View File
@@ -5,6 +5,7 @@ import { Attribute, AutoIncrement, BelongsTo, BelongsToMany, CreatedAt, Default,
import { Tag } from "./Tag";
import { PostTag } from "./PostTag";
import { Project } from "./Project";
import { Attachment } from "./Attachment";
export class Post extends Model<InferAttributes<Post>, InferCreationAttributes<Post>> {
@@ -45,6 +46,10 @@ export class Post extends Model<InferAttributes<Post>, InferCreationAttributes<P
@BelongsToMany(()=>Tag, { through: { model: ()=>PostTag, unique: false}, inverse: {as: 'taggedPosts'} })
declare postTags?:NonAttribute<Tag[]>;
/** Defined by {@link Attachment.post} */
declare Attachments:NonAttribute<Attachment>[];
declare getUser: BelongsToGetAssociationMixin<User>;