CoastalCommitsPastes/server/lib/models/File.ts

50 lines
823 B
TypeScript
Raw Normal View History

2022-03-06 19:46:59 -05:00
import { BelongsTo, Column, CreatedAt, DataType, ForeignKey, IsUUID, Model, PrimaryKey, Scopes, Table } from 'sequelize-typescript';
import { Post } from './Post';
import { User } from './User';
@Scopes(() => ({
full: {
include: [{
model: User,
through: { attributes: [] },
},
{
model: Post,
through: { attributes: [] },
}]
}
}))
@Table
export class File extends Model {
@IsUUID(4)
@PrimaryKey
@Column({
type: DataType.UUID,
defaultValue: DataType.UUIDV4,
})
id!: string
@Column
title!: string;
@Column
content!: string;
@Column
sha!: string;
@ForeignKey(() => User)
@BelongsTo(() => User, 'userId')
user!: User;
@ForeignKey(() => Post)
@BelongsTo(() => Post, 'postId')
post!: Post;
@CreatedAt
@Column
createdAt!: Date;
}