ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

64 lines
1.2 KiB

  1. import { AllowNull, Column, CreatedAt, DataType, HasMany, Table, UpdatedAt } from 'sequelize-typescript'
  2. import { OAuthTokenModel } from './oauth-token.js'
  3. import { SequelizeModel } from '../shared/index.js'
  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 SequelizeModel<OAuthClientModel> {
  18. @AllowNull(false)
  19. @Column
  20. clientId: string
  21. @AllowNull(false)
  22. @Column
  23. clientSecret: string
  24. @Column(DataType.ARRAY(DataType.STRING))
  25. grants: string[]
  26. @Column(DataType.ARRAY(DataType.STRING))
  27. redirectUris: string[]
  28. @CreatedAt
  29. createdAt: Date
  30. @UpdatedAt
  31. updatedAt: Date
  32. @HasMany(() => OAuthTokenModel, {
  33. onDelete: 'cascade'
  34. })
  35. OAuthTokens: Awaited<OAuthTokenModel>[]
  36. static countTotal () {
  37. return OAuthClientModel.count()
  38. }
  39. static loadFirstClient () {
  40. return OAuthClientModel.findOne()
  41. }
  42. static getByIdAndSecret (clientId: string, clientSecret: string) {
  43. const query = {
  44. where: {
  45. clientId,
  46. clientSecret
  47. }
  48. }
  49. return OAuthClientModel.findOne(query)
  50. }
  51. }