From 0c1a8995c2067d70def73dd2064e9bbc97d7b122 Mon Sep 17 00:00:00 2001 From: Kaushik Rishi Manchukonda Date: Tue, 30 Apr 2024 18:06:34 +0530 Subject: [PATCH] rewrite entrypoint file --- template/src/api/index.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/template/src/api/index.js b/template/src/api/index.js index c5980f99..73b363cd 100644 --- a/template/src/api/index.js +++ b/template/src/api/index.js @@ -22,7 +22,7 @@ export default function indexEntrypointFile({asyncapi, params}) { `; const channelHandlerImports = asyncapi.channels().all().map(channel => { - const channelName = channel.address(); + const channelName = channel.id(); return `const ${camelCase(channelName)} = require('./routes/${convertToFilename(channelName)}.js');`; }).join('\n'); @@ -46,7 +46,7 @@ export default function indexEntrypointFile({asyncapi, params}) { ` const channelsMiddleware = asyncapi.channels().all().map(channel => { - const channelName = channel.address(); + const channelName = channel.id(); let channelLogic = ''; if (channel.operations().filterByReceive().length > 0) { channelLogic += `console.log(cyan.bold.inverse(' SUB '), gray('Subscribed to'), yellow('${channelName}')); @@ -90,16 +90,11 @@ export default function indexEntrypointFile({asyncapi, params}) { `; const handlers = asyncapi.channels().all().map(channel => { - const channelName = channel.address(); - let handler = ''; - for (let operation of channel.operations()) { - const operationId = operation.id(); - if (operation.isReceive()) - handler += `${convertOpertionIdToMiddlewareFn(operationId)} : require('./handlers/${convertToFilename(channelName)}').${convertOpertionIdToMiddlewareFn(operationId)},`; - if (operation.isSend()) - handler += `${convertOpertionIdToMiddlewareFn(operationId)} : require('./handlers/${convertToFilename(channelName)}').${convertOpertionIdToMiddlewareFn(operationId)},`; - } - return handler; + const channelName = channel.id(); + return channel.operations().all().map(operation => { + let operationId = operation.id(); + return `${convertOpertionIdToMiddlewareFn(operationId)} : require('./handlers/${convertToFilename(channelName)}').${convertOpertionIdToMiddlewareFn(operationId)}` + }).join(','); }).join('\n'); return