Refactoring 3
This commit is contained in:
parent
e4b78ceec2
commit
d1fb9b4d06
20 changed files with 201 additions and 123 deletions
31
apps/bridge-worker/tasks/common/notify-webhooks.ts
Normal file
31
apps/bridge-worker/tasks/common/notify-webhooks.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { db } from "bridge-common";
|
||||
|
||||
export interface NotifyWebhooksOptions {
|
||||
backendId: string;
|
||||
payload: any;
|
||||
}
|
||||
|
||||
const notifyWebhooksTask = async (
|
||||
options: NotifyWebhooksOptions,
|
||||
): Promise<void> => {
|
||||
const { backendId, payload } = options;
|
||||
|
||||
const webhooks = await db
|
||||
.selectFrom("Webhook")
|
||||
.selectAll()
|
||||
.where("backendId", "=", backendId)
|
||||
.execute();
|
||||
|
||||
for (const webhook of webhooks) {
|
||||
const { endpointUrl, httpMethod, headers } = webhook;
|
||||
const finalHeaders = { "Content-Type": "application/json", ...headers };
|
||||
|
||||
await fetch(endpointUrl, {
|
||||
method: httpMethod,
|
||||
headers: finalHeaders,
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default notifyWebhooksTask;
|
||||
Loading…
Add table
Add a link
Reference in a new issue