2020-04-10 16:06:12 -04:00
|
|
|
import { AutoIncrement, Table, Column, DataType, PrimaryKey, Model, BelongsTo, createIndexDecorator, ForeignKey } from 'sequelize-typescript'
|
|
|
|
import { Note } from './note';
|
|
|
|
import { User } from './user';
|
2016-07-29 23:21:38 -04:00
|
|
|
|
2020-04-10 16:06:12 -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)
|
|
|
|
id: number;
|
2019-04-12 00:05:32 -04:00
|
|
|
|
2020-04-10 16:06:12 -04:00
|
|
|
@Column(DataType.STRING)
|
|
|
|
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-10 16:06:12 -04:00
|
|
|
noteId: string;
|
|
|
|
|
|
|
|
@BelongsTo(() => Note, { foreignKey: 'noteId', onDelete: 'CASCADE', constraints: false, hooks: true })
|
|
|
|
note: Note;
|
|
|
|
|
|
|
|
@ForeignKey(() => User)
|
|
|
|
@NoteUserIndex
|
2020-04-10 18:23:48 -04:00
|
|
|
@Column(DataType.UUID)
|
2020-04-10 16:06:12 -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 })
|
|
|
|
user: User;
|
|
|
|
}
|