2023-09-12 22:48:10 +02:00
|
|
|
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from "typeorm";
|
|
|
|
|
import { APIApplication } from "~types/entities/application";
|
2023-09-22 00:42:59 +02:00
|
|
|
import { Token } from "./Token";
|
2023-09-12 22:48:10 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Applications from clients
|
|
|
|
|
*/
|
|
|
|
|
@Entity({
|
|
|
|
|
name: "applications",
|
|
|
|
|
})
|
|
|
|
|
export class Application extends BaseEntity {
|
|
|
|
|
@PrimaryGeneratedColumn("uuid")
|
|
|
|
|
id!: string;
|
|
|
|
|
|
|
|
|
|
@Column("varchar")
|
|
|
|
|
name!: string;
|
|
|
|
|
|
|
|
|
|
@Column("varchar", {
|
|
|
|
|
nullable: true,
|
|
|
|
|
})
|
|
|
|
|
website!: string | null;
|
|
|
|
|
|
|
|
|
|
@Column("varchar", {
|
|
|
|
|
nullable: true,
|
|
|
|
|
})
|
|
|
|
|
vapid_key!: string | null;
|
|
|
|
|
|
2023-09-14 04:25:45 +02:00
|
|
|
@Column("varchar")
|
|
|
|
|
client_id!: string;
|
|
|
|
|
|
2023-09-13 21:11:24 +02:00
|
|
|
@Column("varchar")
|
|
|
|
|
secret!: string;
|
|
|
|
|
|
|
|
|
|
@Column("varchar")
|
|
|
|
|
scopes = "read";
|
|
|
|
|
|
|
|
|
|
@Column("varchar")
|
|
|
|
|
redirect_uris = "urn:ietf:wg:oauth:2.0:oob";
|
|
|
|
|
|
2023-09-22 00:42:59 +02:00
|
|
|
static async getFromToken(token: string) {
|
|
|
|
|
const dbToken = await Token.findOne({
|
|
|
|
|
where: {
|
|
|
|
|
access_token: token,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return dbToken?.application || null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-12 22:48:10 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
|
|
|
async toAPI(): Promise<APIApplication> {
|
|
|
|
|
return {
|
2023-09-13 21:11:24 +02:00
|
|
|
name: this.name,
|
|
|
|
|
website: this.website,
|
|
|
|
|
vapid_key: this.vapid_key,
|
2023-09-13 02:29:13 +02:00
|
|
|
};
|
2023-09-12 22:48:10 +02:00
|
|
|
}
|
2023-09-13 02:29:13 +02:00
|
|
|
}
|