feat: use webhooks for logs when possible
This commit is contained in:
parent
1081d1b361
commit
55a39e0758
12 changed files with 318 additions and 29 deletions
37
backend/src/data/Webhooks.ts
Normal file
37
backend/src/data/Webhooks.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { getRepository, Repository } from "typeorm";
|
||||
import { Webhook } from "./entities/Webhook";
|
||||
import { BaseRepository } from "./BaseRepository";
|
||||
import { decrypt, encrypt } from "../utils/crypt";
|
||||
|
||||
export class Webhooks extends BaseRepository {
|
||||
repository: Repository<Webhook> = getRepository(Webhook);
|
||||
|
||||
protected async _processEntityFromDB(entity) {
|
||||
entity.token = await decrypt(entity.token);
|
||||
return entity;
|
||||
}
|
||||
|
||||
protected async _processEntityToDB(entity) {
|
||||
entity.token = await encrypt(entity.token);
|
||||
return entity;
|
||||
}
|
||||
|
||||
async findByChannelId(channelId: string): Promise<Webhook | null> {
|
||||
const result = await this.repository.findOne({
|
||||
where: {
|
||||
channel_id: channelId,
|
||||
},
|
||||
});
|
||||
|
||||
return result ? this.processEntityFromDB(result) : null;
|
||||
}
|
||||
|
||||
async create(data: Partial<Webhook>): Promise<void> {
|
||||
data = await this.processEntityToDB(data);
|
||||
await this.repository.insert(data);
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<void> {
|
||||
await this.repository.delete({ id });
|
||||
}
|
||||
}
|
14
backend/src/data/entities/Webhook.ts
Normal file
14
backend/src/data/entities/Webhook.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { Column, Entity, PrimaryColumn } from "typeorm";
|
||||
|
||||
@Entity("webhooks")
|
||||
export class Webhook {
|
||||
@Column()
|
||||
@PrimaryColumn()
|
||||
id: string;
|
||||
|
||||
@Column() guild_id: string;
|
||||
|
||||
@Column() channel_id: string;
|
||||
|
||||
@Column() token: string;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue