]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/oauth/oauth-client.ts
Update sequelize
[github/Chocobozzz/PeerTube.git] / server / models / oauth / oauth-client.ts
CommitLineData
3fd3ab2d
C
1import { AllowNull, Column, CreatedAt, DataType, HasMany, Model, Table, UpdatedAt } from 'sequelize-typescript'
2import { OAuthTokenModel } from './oauth-token'
e02643f3 3
3fd3ab2d
C
4@Table({
5 tableName: 'oAuthClient',
6 indexes: [
feb4bdfd 7 {
3fd3ab2d
C
8 fields: [ 'clientId' ],
9 unique: true
feb4bdfd
C
10 },
11 {
3fd3ab2d
C
12 fields: [ 'clientId', 'clientSecret' ],
13 unique: true
feb4bdfd 14 }
3fd3ab2d
C
15 ]
16})
17export class OAuthClientModel extends Model<OAuthClientModel> {
feb4bdfd 18
3fd3ab2d
C
19 @AllowNull(false)
20 @Column
21 clientId: string
e02643f3 22
3fd3ab2d
C
23 @AllowNull(false)
24 @Column
25 clientSecret: string
e02643f3 26
1735c825 27 @Column({ type: DataType.ARRAY(DataType.STRING) }) // FIXME: sequelize typings
3fd3ab2d
C
28 grants: string[]
29
1735c825 30 @Column({ type: DataType.ARRAY(DataType.STRING) }) // FIXME: sequelize typings
3fd3ab2d
C
31 redirectUris: string[]
32
33 @CreatedAt
34 createdAt: Date
69b0a27c 35
3fd3ab2d
C
36 @UpdatedAt
37 updatedAt: Date
69b0a27c 38
3fd3ab2d 39 @HasMany(() => OAuthTokenModel, {
e02643f3
C
40 onDelete: 'cascade'
41 })
3fd3ab2d 42 OAuthTokens: OAuthTokenModel[]
e02643f3 43
3fd3ab2d
C
44 static countTotal () {
45 return OAuthClientModel.count()
46 }
69b0a27c 47
3fd3ab2d
C
48 static loadFirstClient () {
49 return OAuthClientModel.findOne()
50 }
69b0a27c 51
3fd3ab2d
C
52 static getByIdAndSecret (clientId: string, clientSecret: string) {
53 const query = {
54 where: {
55 clientId: clientId,
56 clientSecret: clientSecret
57 }
feb4bdfd 58 }
feb4bdfd 59
3fd3ab2d
C
60 return OAuthClientModel.findOne(query)
61 }
69b0a27c 62}