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