metamigo-db: build, fmt, lint
This commit is contained in:
parent
2ffb15b1f9
commit
2a1ced5383
17 changed files with 160 additions and 125 deletions
50
packages/metamigo-db/src/records/webhooks.ts
Normal file
50
packages/metamigo-db/src/records/webhooks.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import {
|
||||
RepositoryBase,
|
||||
recordInfo,
|
||||
UUID,
|
||||
Flavor,
|
||||
} from "@digiresilience/metamigo-common";
|
||||
|
||||
/*
|
||||
* Webhook
|
||||
*
|
||||
* A webhook allows external services to be notified when a recorded call is available
|
||||
*/
|
||||
|
||||
export type WebhookId = Flavor<UUID, "Webhook Id">;
|
||||
|
||||
export interface HttpHeaders {
|
||||
header: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface UnsavedWebhook {
|
||||
name: string;
|
||||
voiceLineId: string;
|
||||
endpointUrl: string;
|
||||
httpMethod: "post" | "put";
|
||||
headers?: HttpHeaders[];
|
||||
}
|
||||
|
||||
export interface SavedWebhook extends UnsavedWebhook {
|
||||
id: WebhookId;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export const WebhookRecord = recordInfo<UnsavedWebhook, SavedWebhook>(
|
||||
"app_public",
|
||||
"webhooks"
|
||||
);
|
||||
|
||||
export class WebhookRecordRepository extends RepositoryBase(WebhookRecord) {
|
||||
async findAllByBackendId(
|
||||
backendType: string,
|
||||
backendId: string
|
||||
): Promise<SavedWebhook[]> {
|
||||
return this.db.any(
|
||||
"select * from $1 where backend_type = $2 and backend_id = $3",
|
||||
[this.schemaTable, backendType, backendId]
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue