You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Drift/server/src/lib/models/User.ts

74 lines
899 B
TypeScript

import {
Model,
Column,
Table,
BelongsToMany,
Scopes,
CreatedAt,
UpdatedAt,
IsUUID,
PrimaryKey,
DataType,
Unique
} from "sequelize-typescript"
import { Post } from "./Post"
import { PostAuthor } from "./PostAuthor"
@Scopes(() => ({
posts: {
include: [
{
model: Post,
through: { attributes: [] }
}
]
},
withoutPassword: {
attributes: {
exclude: ["password"]
}
}
}))
@Table({
tableName: "users"
})
export class User extends Model {
@IsUUID(4)
@PrimaryKey
@Unique
@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
@Column
role!: string
@Column
email?: string
@Column
displayName?: string
@Column
bio?: string
}