47 lines
902 B
TypeScript
47 lines
902 B
TypeScript
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;
|
|
}
|