diff --git a/mappings/confirm.jsonata b/mappings/confirm.jsonata new file mode 100644 index 0000000000000000000000000000000000000000..f39c2c8645f9a45b84c066cdb38b9368e77517fb --- /dev/null +++ b/mappings/confirm.jsonata @@ -0,0 +1,6 @@ +$.data.message.orders.{ + "context": $context(%.%.context, $action), + "message": { + "order": $ + } +}[] \ No newline at end of file diff --git a/mappings/on_confirm.jsonata b/mappings/on_confirm.jsonata new file mode 100644 index 0000000000000000000000000000000000000000..f4df33b4e7e0e54f3ecff499a0dd807d63860f95 --- /dev/null +++ b/mappings/on_confirm.jsonata @@ -0,0 +1,59 @@ +{ + "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/package.json b/package.json index c26160c5d580e54dfdb6149dec8bd3d57b906172..809a900e1eba0c580348cd4801e60597af320eeb 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@types/ini": "^1.3.33", "@types/uuid": "^9.0.7", "nodemon": "^3.0.1", + "ts-node": "^10.9.1", "typescript": "^5.2.2" } } diff --git a/src/gcl/gcl.service.ts b/src/gcl/gcl.service.ts index b0a51de26d4a2704a49bb6e205eff5971b6f9385..b211831e772e94b80c709514f5f2d5ce509816b4 100644 --- a/src/gcl/gcl.service.ts +++ b/src/gcl/gcl.service.ts @@ -4,60 +4,58 @@ import { PSClientService } from "../psclient/psclient.service"; @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, "select"); - // const psResponse = await this.psClientService.postMany(payload); - // const response = await this.tlService.transform(psResponse, "on_select"); + 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; + } - return "In Progress"; - } + 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; + } }