CoastalCommitsPastes/server/lib/models/User.ts

48 lines
902 B
TypeScript
Raw Normal View History

2022-03-06 19:46:59 -05:00
import { Model, Column, Table, BelongsToMany, Scopes, CreatedAt, UpdatedAt, IsUUID, PrimaryKey, DataType } from "sequelize-typescript";
import { Post } from "./Post";
import { PostAuthor } from "./PostAuthor";
@Scopes(() => ({
posts: {
include: [
{
model: Post,
through: { attributes: [] },
},
],
},
withoutPassword: {
attributes: {
exclude: ["password"]
}
}
}))
@Table
export class User extends Model {
@IsUUID(4)
@PrimaryKey
@Column({
type: DataType.UUID,
defaultValue: DataType.UUIDV4,
})
id!: string
@Column
username!: string;
@Column
password!: string;
@BelongsToMany(() => Post, () => PostAuthor)
posts?: Post[];
@CreatedAt
@Column
createdAt!: Date;
@UpdatedAt
@Column
updatedAt!: Date;
}