]>
Commit | Line | Data |
---|---|---|
f05a1c30 | 1 | import { AllowNull, Column, CreatedAt, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3fd3ab2d | 2 | import { isHostValid } from '../../helpers/custom-validators/servers' |
f05a1c30 | 3 | import { ActorModel } from '../activitypub/actor' |
3fd3ab2d | 4 | import { throwIfNotValid } from '../utils' |
60862425 | 5 | |
3fd3ab2d C |
6 | @Table({ |
7 | tableName: 'server', | |
8 | indexes: [ | |
60862425 | 9 | { |
3fd3ab2d C |
10 | fields: [ 'host' ], |
11 | unique: true | |
60862425 | 12 | } |
60862425 | 13 | ] |
3fd3ab2d C |
14 | }) |
15 | export class ServerModel extends Model<ServerModel> { | |
16 | ||
17 | @AllowNull(false) | |
18 | @Is('Host', value => throwIfNotValid(value, isHostValid, 'valid host')) | |
19 | @Column | |
20 | host: string | |
21 | ||
3fd3ab2d C |
22 | @CreatedAt |
23 | createdAt: Date | |
24 | ||
25 | @UpdatedAt | |
26 | updatedAt: Date | |
f05a1c30 C |
27 | |
28 | @HasMany(() => ActorModel, { | |
29 | foreignKey: { | |
30 | name: 'serverId', | |
31 | allowNull: true | |
32 | }, | |
33 | onDelete: 'CASCADE', | |
34 | hooks: true | |
35 | }) | |
36 | Actors: ActorModel[] | |
39445ead | 37 | } |