2020-04-12 11:52:50 +00:00
|
|
|
import {
|
|
|
|
AutoIncrement,
|
|
|
|
BelongsTo,
|
|
|
|
Column,
|
|
|
|
createIndexDecorator,
|
|
|
|
DataType,
|
|
|
|
ForeignKey,
|
|
|
|
Model,
|
|
|
|
PrimaryKey,
|
|
|
|
Table
|
|
|
|
} from 'sequelize-typescript'
|
|
|
|
import { Note, User } from './index'
|
2016-07-30 03:21:38 +00:00
|
|
|
|
2020-04-12 11:52:50 +00:00
|
|
|
const NoteUserIndex = createIndexDecorator({ unique: true })
|
2019-11-23 20:34:31 +00:00
|
|
|
|
2020-04-10 20:06:12 +00:00
|
|
|
@Table
|
|
|
|
export class Author extends Model<Author> {
|
|
|
|
@PrimaryKey
|
|
|
|
@AutoIncrement
|
|
|
|
@Column(DataType.INTEGER)
|
2020-04-12 11:52:50 +00:00
|
|
|
id: number
|
2019-04-12 04:05:32 +00:00
|
|
|
|
2020-04-10 20:06:12 +00:00
|
|
|
@Column(DataType.STRING)
|
2020-04-12 11:52:50 +00:00
|
|
|
color: string
|
2019-04-12 04:05:32 +00:00
|
|
|
|
2020-04-10 20:06:12 +00:00
|
|
|
@ForeignKey(() => Note)
|
|
|
|
@NoteUserIndex
|
2020-04-10 22:23:48 +00:00
|
|
|
@Column(DataType.UUID)
|
2020-04-12 11:52:50 +00:00
|
|
|
noteId: string
|
2020-04-11 10:26:40 +00:00
|
|
|
|
2020-04-10 20:06:12 +00:00
|
|
|
@BelongsTo(() => Note, { foreignKey: 'noteId', onDelete: 'CASCADE', constraints: false, hooks: true })
|
2020-04-12 11:52:50 +00:00
|
|
|
note: Note
|
2020-04-10 20:06:12 +00:00
|
|
|
|
|
|
|
@ForeignKey(() => User)
|
|
|
|
@NoteUserIndex
|
2020-04-10 22:23:48 +00:00
|
|
|
@Column(DataType.UUID)
|
2020-04-12 11:52:50 +00:00
|
|
|
userId: string
|
2019-11-23 20:34:31 +00:00
|
|
|
|
2020-04-10 20:06:12 +00:00
|
|
|
@BelongsTo(() => User, { foreignKey: 'userId', onDelete: 'CASCADE', constraints: false, hooks: true })
|
2020-04-12 11:52:50 +00:00
|
|
|
user: User
|
2020-04-10 20:06:12 +00:00
|
|
|
}
|