From cabf05e03ef8899773d6ea0d98a8c4708c176e50 Mon Sep 17 00:00:00 2001 From: Ajay Nishad <ajay.nishad@eminds.ai> Date: Sat, 2 Dec 2023 20:11:53 +0530 Subject: [PATCH] feat: add init endpoint --- mappings/init.jsonata | 6 ++++ mappings/on_init.jsonata | 61 ++++++++++++++++++++++++++++++++++++++++ src/gcl/gcl.service.ts | 10 +++---- 3 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 mappings/init.jsonata create mode 100644 mappings/on_init.jsonata diff --git a/mappings/init.jsonata b/mappings/init.jsonata new file mode 100644 index 0000000..64fe7ea --- /dev/null +++ b/mappings/init.jsonata @@ -0,0 +1,6 @@ +$.data.message.orders.{ + "context": $context(%.%.context, $action), + "message": { + "order": $ + } +}[] diff --git a/mappings/on_init.jsonata b/mappings/on_init.jsonata new file mode 100644 index 0000000..7d8f731 --- /dev/null +++ b/mappings/on_init.jsonata @@ -0,0 +1,61 @@ +$.responses.{ + "context":context, + "message": { + "order": { + "type": message.order.type, + "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 + }, + "media": message.order.provider.descriptor.media.{ + "url": url + } + }, + "items": message.order.items.{ + "id": id, + "name": descriptor.name, + "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 + } + } +}[] diff --git a/src/gcl/gcl.service.ts b/src/gcl/gcl.service.ts index 9a535b9..a490664 100644 --- a/src/gcl/gcl.service.ts +++ b/src/gcl/gcl.service.ts @@ -26,13 +26,11 @@ export class GCLService { } async init(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; + 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 "In Progress"; + return response; } async confirm(body: any) { -- GitLab