1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import { AllowNull, Column, CreatedAt, DataType, HasMany, Model, Table, UpdatedAt } from 'sequelize-typescript'
- import { OAuthTokenModel } from './oauth-token'
- @Table({
- tableName: 'oAuthClient',
- indexes: [
- {
- fields: [ 'clientId' ],
- unique: true
- },
- {
- fields: [ 'clientId', 'clientSecret' ],
- unique: true
- }
- ]
- })
- export class OAuthClientModel extends Model<OAuthClientModel> {
- @AllowNull(false)
- @Column
- clientId: string
- @AllowNull(false)
- @Column
- clientSecret: string
- @Column(DataType.ARRAY(DataType.STRING))
- grants: string[]
- @Column(DataType.ARRAY(DataType.STRING))
- redirectUris: string[]
- @CreatedAt
- createdAt: Date
- @UpdatedAt
- updatedAt: Date
- @HasMany(() => OAuthTokenModel, {
- onDelete: 'cascade'
- })
- OAuthTokens: OAuthTokenModel[]
- static countTotal () {
- return OAuthClientModel.count()
- }
- static loadFirstClient () {
- return OAuthClientModel.findOne()
- }
- static getByIdAndSecret (clientId: string, clientSecret: string) {
- const query = {
- where: {
- clientId: clientId,
- clientSecret: clientSecret
- }
- }
- return OAuthClientModel.findOne(query)
- }
- }
|