Skip to content
Snippets Groups Projects
Commit d58f4e7c authored by shreyvishal's avatar shreyvishal
Browse files

Added: Search Request config from JSONata

parent 3a4f380a
No related branches found
No related tags found
No related merge requests found
{ {
"context":context,
} "message":{
"intent":{
"item":{
"descriptor":{
"name":searchString
},
"id":itemId
},
"fulfillment":{
"agent":{
"person":{
"name":fulfillment.agentName
}
},
"customer":{
"person":{
"gender":fulfillment.customerGender
}
}
},
"provider":{
"descriptor":{
"name":provider.providerName
},
"locations":$map( provider.providerCity, function($location) {
{"city":{
"name":$location
}}
})[],
"id":provider.providerId
},
"category":{
"descriptor":{
"code":category.categoryCode,
"name":category.categoryName
},
"id":category.categoryId
},
"location":{
"circle":{
"gps":location,
"radius":{
"type": "CONSTANT",
"value": "5",
"unit": "km"
}
}
}
}
}
}
\ No newline at end of file
...@@ -26,6 +26,5 @@ ...@@ -26,6 +26,5 @@
"category.categoryId": { "category.categoryId": {
"path": "message.intent.category.id" "path": "message.intent.category.id"
}, },
"location": { "path": "message.intent.location.circle.gps" }, "location": { "path": "message.intent.location.circle.gps" }
"someItem": { "path": "message.intent.someItem[arrayIndex].name" }
} }
import { Request, Response, NextFunction } from "express"; import { Request, Response, NextFunction } from "express";
import { searchService } from "./service"; import { searchService } from "./service";
export const searchController = async (req: Request, res: Response, next: NextFunction) => { export const searchController = async (
req: Request,
res: Response,
next: NextFunction
) => {
try { try {
const payloadForBAP = await searchService(req?.body); const payloadForBAP = await searchService(req?.body);
return res.status(200).send(payloadForBAP); return res.status(200).send(payloadForBAP);
} catch (error: any) { } } catch (error: any) {
return res.status(400).json({ success: false, message: error.message });
}
}; };
import { buildRequestContextVer1_1_0 } from "../../common";
import * as mapperService from "../../common/mapper.service"; import * as mapperService from "../../common/mapper.service";
import { ProtocolServer } from "../../common/protocol-server.service"; import { ProtocolServer } from "../../common/protocol-server.service";
export const searchService = async (body: any) => { export const searchService = async (body: any) => {
try { try {
const request = await mapperService.map(body, 'search'); const context = buildRequestContextVer1_1_0(body?.context, "search");
const response = await (new ProtocolServer(request)).call(); const request = await mapperService.map({ ...body, context }, "search");
return await mapperService.map(response, "on_search") console.log(JSON.stringify(request));
} catch (error) { const response = await new ProtocolServer(request).call();
console.log(error);
return await mapperService.map(response.data, "on_search");
} catch (error: any) {
console.log(error.response.data.error.data.errors);
} }
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment