Team Ai
Apppublic

oex2003/evolution-api

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
pusher.router.ts33 linesDownload Raw Back to pusher
1import { RouterBroker } from '@api/abstract/abstract.router';2import { InstanceDto } from '@api/dto/instance.dto';3import { EventDto } from '@api/integrations/event/event.dto';4import { HttpStatus } from '@api/routes/index.router';5import { eventManager } from '@api/server.module';6import { instanceSchema, pusherSchema } from '@validate/validate.schema';7import { RequestHandler, Router } from 'express';8export class PusherRouter extends RouterBroker {9  constructor(...guards: RequestHandler[]) {10    super();11    this.router12      .post(this.routerPath('set'), ...guards, async (req, res) => {13        const response = await this.dataValidate<EventDto>({14          request: req,15          schema: pusherSchema,16          ClassRef: EventDto,17          execute: (instance, data) => eventManager.pusher.set(instance.instanceName, data),18        });19        res.status(HttpStatus.CREATED).json(response);20      })21      .get(this.routerPath('find'), ...guards, async (req, res) => {22        const response = await this.dataValidate<InstanceDto>({23          request: req,24          schema: instanceSchema,25          ClassRef: InstanceDto,26          execute: (instance) => eventManager.pusher.get(instance.instanceName),27        });28        res.status(HttpStatus.OK).json(response);29      });30  }31  public readonly router: Router = Router();32}33