All files / services/user/models UserToken.model.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 0/0
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 363x 3x       3x 3x 3x                                                        
import { timestamp, randomId } from "@lib/objection-utils/model.decorator.lib";
import BaseModel from "@lib/objection-utils/BaseModel";
 
@timestamp()
@randomId("utk")
export default class UserToken extends BaseModel {
  static tableName = "user_tokens";
  static idColumn = "id";
 
  id: string;
  userId: string;
  accessToken: string;
  refreshToken: string;
 
  type: "user" | "api"; // user: a native login user, api: a third party api token
 
  /**
   * A permission map that limit this token to do
   * if token type is "user", scope will be { all: true }.
   */
  scope: string;
  /**
   * The application id for the third party app.
   * if token type is "user", appId will be null
   */
  appId?: string;
 
  /**
   * Metadata of this token issue.
   * Including the login method, ip, etc.
   */
  meta: string;
 
  expiresAt: Date;
}