From 2b68d204545d806e45a01935d2eeb22067bef8ac Mon Sep 17 00:00:00 2001 From: shreyvishal <shreya.vishal@eminds.ai> Date: Thu, 7 Dec 2023 15:59:09 +0530 Subject: [PATCH] Added: update-api --- mappings/on_update.jsonata | 60 +++++++++++++++++++++ mappings/update.jsonata | 11 ++++ src/gcl/gcl.controller.ts | 95 ++++++++++++++++++---------------- src/gcl/gcl.service.ts | 103 ++++++++++++++++++++----------------- 4 files changed, 176 insertions(+), 93 deletions(-) create mode 100644 mappings/on_update.jsonata create mode 100644 mappings/update.jsonata diff --git a/mappings/on_update.jsonata b/mappings/on_update.jsonata new file mode 100644 index 0000000..56652d5 --- /dev/null +++ b/mappings/on_update.jsonata @@ -0,0 +1,60 @@ +{ + "data":$.responses.{ + "context":context, + "message":{ + "orderId":message.order.id, + "provider":{ + "id":message.order.provider.id, + "name":message.order.provider.descriptor.name, + "short_desc":message.order.provider.descriptor.short_desc, + "long_desc":message.order.provider.descriptor.long_desc, + "rating":message.order.provider.rating, + "images":message.order.provider.descriptor.images.{ + "url":url, + "size_type":size_type + }[] + }, + "items":message.order.items.{ + "id":id, + "name":descriptor.name, + "code":descriptor.code, + "short_desc":descriptor.short_desc, + "long_desc":descriptor.long_desc, + "price": price, + "rating": rating, + "rateable": rateable, + "time": time, + "quantity": quantity, + "categories": $map( + $filter(%.provider.categories, function($category) { $boolean($category.id in category_ids)}), + function($category) { + { "id": $category.id, "name": $category.descriptor.name, "code": $category.descriptor.code } + } + )[], + "locations": $map( + $filter(%.provider.locations, function($location) { $boolean($location.id in location_ids)}), + function($location) { + { + "id": $location.id, + "city": $location.city.name, + "state": $location.state.name, + "country": $location.country.name + } + } + )[], + "tags": tags.{ + "code": descriptor.code, + "name": descriptor.name, + "display": display, + "list": list.{ "code": descriptor.code, "name": descriptor.name, "value": value }[] + }[] + }, + "fulfillments": message.order.fulfillments, + "quote": message.order.quote, + "billing": message.order.billing, + "payments": message.order.payments, + "cancellation_terms": message.order.cancellation_terms + } + + }[] +} \ No newline at end of file diff --git a/mappings/update.jsonata b/mappings/update.jsonata new file mode 100644 index 0000000..e8bd6c6 --- /dev/null +++ b/mappings/update.jsonata @@ -0,0 +1,11 @@ +$.data.{ + "context":$context(context, $action), + "message":{ + "order":{ + "order_id":orderId, + "fulfillments":updateDetails.fulfillments, + "billing":updateDetails.billing + }, + "update_target":updateDetails.updateTarget + } +}[] \ No newline at end of file diff --git a/src/gcl/gcl.controller.ts b/src/gcl/gcl.controller.ts index 6e66375..65bc7fd 100644 --- a/src/gcl/gcl.controller.ts +++ b/src/gcl/gcl.controller.ts @@ -2,50 +2,55 @@ import { inject } from "inversify"; import { controller, httpPost, requestBody } from "inversify-express-utils"; import { GCLService } from "./gcl.service"; -@controller('/') +@controller("/") export class GCLController { - - constructor(@inject(GCLService) private service: GCLService) { } - - @httpPost('search') - public async search(@requestBody() body: any): Promise<any> { - const searchResult = await this.service.search(body); - return searchResult; - } - - @httpPost('select') - public async select(@requestBody() body: any): Promise<any> { - const selectResult = await this.service.select(body); - return selectResult; - } - - @httpPost('init') - public async init(@requestBody() body: any): Promise<any> { - const initResult = await this.service.init(body); - return initResult; - } - - @httpPost('confirm') - public async confirm(@requestBody() body: any): Promise<any> { - const confirmResult = await this.service.confirm(body); - return confirmResult; - } - - @httpPost('status') - public async status(@requestBody() body: any): Promise<any> { - const statusResult = await this.service.status(body); - return statusResult; - } - - @httpPost('rating') - public async rating(@requestBody() body: any): Promise<any> { - const statusResult = await this.service.rating(body); - return statusResult; - } - - @httpPost('cancel') - public async cancel(@requestBody() body: any): Promise<any> { - const statusResult = await this.service.cancel(body); - return statusResult; - } + constructor(@inject(GCLService) private service: GCLService) {} + + @httpPost("search") + public async search(@requestBody() body: any): Promise<any> { + const searchResult = await this.service.search(body); + return searchResult; + } + + @httpPost("select") + public async select(@requestBody() body: any): Promise<any> { + const selectResult = await this.service.select(body); + return selectResult; + } + + @httpPost("init") + public async init(@requestBody() body: any): Promise<any> { + const initResult = await this.service.init(body); + return initResult; + } + + @httpPost("confirm") + public async confirm(@requestBody() body: any): Promise<any> { + const confirmResult = await this.service.confirm(body); + return confirmResult; + } + + @httpPost("status") + public async status(@requestBody() body: any): Promise<any> { + const statusResult = await this.service.status(body); + return statusResult; + } + + @httpPost("rating") + public async rating(@requestBody() body: any): Promise<any> { + const statusResult = await this.service.rating(body); + return statusResult; + } + + @httpPost("cancel") + public async cancel(@requestBody() body: any): Promise<any> { + const statusResult = await this.service.cancel(body); + return statusResult; + } + + @httpPost("update") + public async update(@requestBody() body: any): Promise<any> { + const updateResult = await this.service.update(body); + return updateResult; + } } diff --git a/src/gcl/gcl.service.ts b/src/gcl/gcl.service.ts index 0131812..f53b951 100644 --- a/src/gcl/gcl.service.ts +++ b/src/gcl/gcl.service.ts @@ -1,70 +1,77 @@ import { inject, injectable } from "inversify"; import { TLService } from "../tl/tl.service"; import { PSClientService } from "../psclient/psclient.service"; -import data from '../../data.json'; @injectable() export class GCLService { - constructor( - @inject(TLService) private tlService: TLService, - @inject(PSClientService) private psClientService: PSClientService - ) { } + constructor( + @inject(TLService) private tlService: TLService, + @inject(PSClientService) private psClientService: PSClientService + ) {} - async search(body: any) { - const payload = await this.tlService.transform(body, "search"); - const psResponse = await this.psClientService.post(payload); - const response = await this.tlService.transform(psResponse, "on_search"); + async search(body: any) { + const payload = await this.tlService.transform(body, "search"); + const psResponse = await this.psClientService.post(payload); + const response = await this.tlService.transform(psResponse, "on_search"); - return response; - } + return response; + } - async select(body: any) { - const payload = await this.tlService.transform(body, "select"); - const psResponse = await this.psClientService.postMany(payload); - const response = await this.tlService.transform(psResponse, "on_select"); + async select(body: any) { + const payload = await this.tlService.transform(body, "select"); + const psResponse = await this.psClientService.postMany(payload); + const response = await this.tlService.transform(psResponse, "on_select"); - return response; - } + return response; + } - async init(body: any) { - const payload = await this.tlService.transform(body, "init"); - const psResponse = await this.psClientService.postMany(payload); - const response = await this.tlService.transform(psResponse, "on_init"); + async init(body: any) { + const payload = await this.tlService.transform(body, "init"); + const psResponse = await this.psClientService.postMany(payload); + const response = await this.tlService.transform(psResponse, "on_init"); - return response; - } + return response; + } - async confirm(body: any) { - const payload = await this.tlService.transform(body, "confirm"); - const psResponse = await this.psClientService.postMany(payload); - const response = await this.tlService.transform(psResponse, "on_confirm"); + async confirm(body: any) { + const payload = await this.tlService.transform(body, "confirm"); + const psResponse = await this.psClientService.postMany(payload); + const response = await this.tlService.transform(psResponse, "on_confirm"); - return response; - } + return response; + } - async status(body: any) { - // const payload = await this.tlService.transform(body, "select"); - // const psResponse = await this.psClientService.postMany(payload); - // const response = await this.tlService.transform(psResponse, "on_select"); + async status(body: any) { + // const payload = await this.tlService.transform(body, "select"); + // const psResponse = await this.psClientService.postMany(payload); + // const response = await this.tlService.transform(psResponse, "on_select"); - // return response; + // return response; - return "In Progress"; - } + return "In Progress"; + } - async rating(body: any) { - const payload = await this.tlService.transform(body, "rating"); - const psResponse = await this.psClientService.post(payload); - const response = await this.tlService.transform(psResponse, "on_rating"); + async rating(body: any) { + const payload = await this.tlService.transform(body, "rating"); + const psResponse = await this.psClientService.post(payload); + const response = await this.tlService.transform(psResponse, "on_rating"); - return response; - } + return response; + } - async cancel(body: any) { - const payload = await this.tlService.transform(body, "cancel"); - const psResponse = await this.psClientService.post(payload); - const response = await this.tlService.transform(psResponse, "on_cancel"); + async cancel(body: any) { + const payload = await this.tlService.transform(body, "cancel"); + const psResponse = await this.psClientService.post(payload); + const response = await this.tlService.transform(psResponse, "on_cancel"); - return response; - } + return response; + } + + async update(body: any) { + const payload = await this.tlService.transform(body, "update"); + const psResponse = await this.psClientService.postMany(payload); + const response = await this.tlService.transform(psResponse, "on_update"); + + return response; + } } -- GitLab