2022-03-06 19:46:59 -05:00
|
|
|
import { BelongsToMany, Column, CreatedAt, DataType, HasMany, IsUUID, Model, PrimaryKey, Scopes, Table, UpdatedAt } from 'sequelize-typescript';
|
|
|
|
import { PostAuthor } from './PostAuthor';
|
|
|
|
import { User } from './User';
|
|
|
|
import { File } from './File';
|
|
|
|
|
|
|
|
@Scopes(() => ({
|
|
|
|
user: {
|
|
|
|
include: [{
|
|
|
|
model: User,
|
|
|
|
through: { attributes: [] },
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
full: {
|
|
|
|
include: [{
|
|
|
|
model: User,
|
|
|
|
through: { attributes: [] },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: File,
|
|
|
|
through: { attributes: [] },
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
@Table
|
|
|
|
export class Post extends Model {
|
|
|
|
@IsUUID(4)
|
|
|
|
@PrimaryKey
|
|
|
|
@Column({
|
|
|
|
type: DataType.UUID,
|
|
|
|
defaultValue: DataType.UUIDV4,
|
|
|
|
})
|
|
|
|
id!: string
|
|
|
|
|
|
|
|
@Column
|
|
|
|
title!: string;
|
|
|
|
|
|
|
|
@BelongsToMany(() => User, () => PostAuthor)
|
|
|
|
users?: User[];
|
|
|
|
|
|
|
|
@HasMany(() => File)
|
|
|
|
files?: File[];
|
|
|
|
|
|
|
|
@CreatedAt
|
|
|
|
@Column
|
|
|
|
createdAt!: Date;
|
|
|
|
|
|
|
|
@Column
|
|
|
|
visibility!: string;
|
|
|
|
|
2022-03-21 06:28:06 -04:00
|
|
|
@Column
|
|
|
|
password?: string;
|
|
|
|
|
2022-03-06 19:46:59 -05:00
|
|
|
@UpdatedAt
|
|
|
|
@Column
|
|
|
|
updatedAt!: Date;
|
|
|
|
}
|