mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-26 23:27:45 -06:00
init project evolution api
This commit is contained in:
36
src/whatsapp/routers/webhook.router.ts
Normal file
36
src/whatsapp/routers/webhook.router.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { RequestHandler, Router } from 'express';
|
||||
import { instanceNameSchema, webhookSchema } from '../../validate/validate.schema';
|
||||
import { RouterBroker } from '../abstract/abstract.router';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { WebhookDto } from '../dto/webhook.dto';
|
||||
import { webhookController } from '../whatsapp.module';
|
||||
import { HttpStatus } from './index.router';
|
||||
|
||||
export class WebhookRouter extends RouterBroker {
|
||||
constructor(...guards: RequestHandler[]) {
|
||||
super();
|
||||
this.router
|
||||
.post(this.routerPath('set'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<WebhookDto>({
|
||||
request: req,
|
||||
schema: webhookSchema,
|
||||
ClassRef: WebhookDto,
|
||||
execute: (instance, data) => webhookController.createWebhook(instance, data),
|
||||
});
|
||||
|
||||
res.status(HttpStatus.CREATED).json(response);
|
||||
})
|
||||
.get(this.routerPath('find'), ...guards, async (req, res) => {
|
||||
const response = await this.dataValidate<InstanceDto>({
|
||||
request: req,
|
||||
schema: instanceNameSchema,
|
||||
ClassRef: InstanceDto,
|
||||
execute: (instance) => webhookController.findWebhook(instance),
|
||||
});
|
||||
|
||||
res.status(HttpStatus.OK).json(response);
|
||||
});
|
||||
}
|
||||
|
||||
public readonly router = Router();
|
||||
}
|
||||
Reference in New Issue
Block a user