import { Controller, Post, Body, UseGuards } from '@nestjs/common' import { isNil } from 'lodash' import { Messaging } from '../domain/messaging' import { BaseEventParams } from '../../../params' import { BasicAuthorizationGuard } from '../../../guards' @UseGuards(BasicAuthorizationGuard) @Controller('notifications') export class NotificationsController { constructor(private readonly messaging: Messaging) {} @Post('nutri_reply') async nutriReply(@Body() { event }: BaseEventParams): Promise { if (isNil(event?.data?.new['text']) || isNil(event?.data?.new['replied_by_user_id'])) return await this.messaging.nutriReplyNotification(event.data.new['patient_id']) } @Post('meal_rated') async mealRated(@Body() { event }: BaseEventParams): Promise { if (isNil(event?.data?.new['state']) || event.data.new['state'] !== 'rated') return await this.messaging.mealRatedNotification(event.data.new['patient_id']) } @Post('food_plan_ready') async foodPlanReady(@Body() { event }: BaseEventParams): Promise { if (isNil(event?.data?.new['published_food_plan_id'])) return if (event.data.new['published_food_plan_id'] === event?.data?.old['published_food_plan_id']) return await this.messaging.foodPlanReadyNotification(event.data.new['id']) } @Post('notify_incoming_appointments_in_chat') async notifyIncomingAppointments(): Promise { await this.messaging.incomingAppointmentsChatNofitication() } }