import { Abstract, Type } from '@nestjs/common' import { SQSRecord } from 'aws-lambda' import { last } from 'lodash' import { logNotification } from '../middlewares' export async function runEvent( record: SQSRecord, controller: Type | Abstract | string | symbol, ): Promise { logNotification(record) const name = record?.eventSourceARN ? last(record.eventSourceARN.split(':')).replace(`-${process.env.STAGE}`, '') : null if (!controller[`process${name}`]) throw new Error(`Processor for queue "${name}" not found`) return controller[`process${name}`](record) } export async function runNotificationHook( controller: Type | Abstract | string | symbol, records: SQSRecord[], ): Promise { await Promise.all(records.map(record => runEvent(record, controller))) }