Send Guard Decorator

Send Guard Decorator#

This decorator defines whether the event should be sent or not depending on the returned result. Requires PusherEvent to be defined in your route otherwise is not executed.

Example#

import { Controller, Get } from '@nestjs/common';
import { PusherChannel, PusherSendGuard } from 'nestjs-pusher';
const shouldSend = (req: any, res: any, eventName: string) => {
//Do whatever logic you need
return true
}
@Controller('cats')
export class CatsController {
constructor(private readonly catService: CatService) {
//Imaginary service for the sake of the example
}
@PusherSendGuard(shouldSend)
@PusherChannel('private-channel-of-cats')
@PusherEvent('cat.created')
@Post()
async createCat(@Body() dto): string {
const newCat = await this.catService.create(dto)
//The return value will be used as the content
return newCat
}
}