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