server/database/entities/Token.ts

58 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-09-13 21:02:16 +02:00
import {
Entity,
BaseEntity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
ManyToOne,
} from "typeorm";
import { User } from "./User";
import { Application } from "./Application";
2023-09-28 20:19:21 +02:00
/**
* Represents an access token for a user or application.
*/
2023-09-13 21:02:16 +02:00
@Entity({
name: "tokens",
})
export class Token extends BaseEntity {
2023-09-28 20:19:21 +02:00
/** The unique identifier for the token. */
2023-09-13 21:02:16 +02:00
@PrimaryGeneratedColumn("uuid")
id!: string;
2023-09-28 20:19:21 +02:00
/** The type of token. */
2023-09-13 21:02:16 +02:00
@Column("varchar")
2023-09-14 04:25:45 +02:00
token_type: TokenType = TokenType.BEARER;
2023-09-13 21:02:16 +02:00
2023-09-28 20:19:21 +02:00
/** The scope of the token. */
2023-09-13 21:02:16 +02:00
@Column("varchar")
scope!: string;
2023-09-28 20:19:21 +02:00
/** The access token string. */
2023-09-13 21:02:16 +02:00
@Column("varchar")
access_token!: string;
2023-09-28 20:19:21 +02:00
/** The authorization code used to obtain the token. */
2023-09-14 04:25:45 +02:00
@Column("varchar")
code!: string;
2023-09-28 20:19:21 +02:00
/** The date and time the token was created. */
2023-09-13 21:02:16 +02:00
@CreateDateColumn()
created_at!: Date;
2023-09-28 20:19:21 +02:00
/** The user associated with the token. */
2023-09-13 21:02:16 +02:00
@ManyToOne(() => User, user => user.id)
user!: User;
2023-09-28 20:19:21 +02:00
/** The application associated with the token. */
2023-09-13 21:02:16 +02:00
@ManyToOne(() => Application, application => application.id)
application!: Application;
}
2023-09-28 20:19:21 +02:00
/**
* The type of token.
*/
2023-10-01 04:35:37 +02:00
export enum TokenType {
BEARER = "Bearer",
2023-09-28 20:19:21 +02:00
}