From 0422ab38d04da0e1e6c58ef4ddbf6661705691a3 Mon Sep 17 00:00:00 2001 From: ilias-musin-3d Date: Mon, 21 Jun 2021 14:24:35 +0300 Subject: [PATCH 1/2] feat: try look methods --- lib/api/person.js | 55 ++++++++++++++++++++++++++++++++++++++++++++ lib/api/sizechart.js | 4 ++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/lib/api/person.js b/lib/api/person.js index a66d3af..83c00d6 100644 --- a/lib/api/person.js +++ b/lib/api/person.js @@ -59,6 +59,8 @@ class Person { * @param {string} params.gender - person's gender * @param {number} params.height - person's height * @param {string} [params.measurementsType] - type of measurements - all + * @param {boolean} [params.hasVirtualTryOn] - should apply virtual try on + * @param {any} [params.product] - product sku which would be used for virtual try on * @param {string} [params.frontImage] - person's Base64 encoded front photo * @param {string} [params.sideImage] - person's Base64 encoded side photo * @param {string} [params.weight] - person's weight in kg @@ -107,6 +109,14 @@ class Person { getParams.measurements_type = params.measurementsType; } + if (params.hasVirtualTryOn) { + getParams.virtual_tryon = true; + } + + if (params.product) { + getParams.product_sku = params.product; + } + return this.axios({ url: this.api, method: 'post', @@ -261,6 +271,8 @@ class Person { * @param {number} id - Person''s ID * @param {Object} params - Person's parameters * @param {string} [params.measurementsType] - type of measurements - all + * @param {boolean} [params.hasVirtualTryOn] - should apply virtual try on + * @param {any} [params.product] - product sku which would be used for virtual try on * @param {string} [params.gender] - Person's parameters * @param {number} [params.height] - Person's height * @param {string} [params.frontImage] - Person's Base64 encoded frontImage @@ -311,6 +323,14 @@ class Person { getParams.measurements_type = params.measurementsType; } + if (params.hasVirtualTryOn) { + getParams.virtual_tryon = true; + } + + if (params.product) { + getParams.product_sku = params.product; + } + return this.axios({ url: `${this.api}${id}/`, method: 'put', @@ -370,6 +390,41 @@ class Person { return taskSetId; }); } + + /** + * Processing virtual tryon for specific person and product + * result also would be available in person.get(id).virtual_tryons + * [ + * { + * "id": , + * "product_sku": "" + * "created": 'datetime', + * "image: "https://url.to.tryon.image.com" + * } + * ] + * + * @async + * @param {number} id - Person's ID + * @param {any} product - Product sku + * @returns {Promise} Taskset id + */ + virtualTryOn(id, product) { + if (!id) { + throw new Error('id is not specified'); + } + + if (!product) { + throw new Error('product is not specified'); + } + + return this.axios({ + url: `${this.api}${id}/virtual_tryon/`, + method: 'post', + data: { + product_sku: product, + }, + }).then(response => response.data); + } } export default Person; diff --git a/lib/api/sizechart.js b/lib/api/sizechart.js index 7dc7070..8bb3d4b 100644 --- a/lib/api/sizechart.js +++ b/lib/api/sizechart.js @@ -72,11 +72,11 @@ class Sizechart { throw new Error('waist is not specified'); } - if (!params.body_part) { + if (!params.body_part && !params.uuid) { throw new Error('body_part is not specified'); } - if (!params.brand) { + if (!params.brand && !params.uuid) { throw new Error('brand is not specified'); } From 02e3b19d526db4a5bad627591c7a577e88b64cc8 Mon Sep 17 00:00:00 2001 From: ilias-musin-3d Date: Mon, 21 Jun 2021 15:55:41 +0300 Subject: [PATCH 2/2] fix: js cod --- lib/api/person.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/api/person.js b/lib/api/person.js index 83c00d6..18f8f64 100644 --- a/lib/api/person.js +++ b/lib/api/person.js @@ -396,8 +396,8 @@ class Person { * result also would be available in person.get(id).virtual_tryons * [ * { - * "id": , - * "product_sku": "" + * "id": tryonId, + * "product_sku": "productSku" * "created": 'datetime', * "image: "https://url.to.tryon.image.com" * } @@ -406,7 +406,12 @@ class Person { * @async * @param {number} id - Person's ID * @param {any} product - Product sku - * @returns {Promise} Taskset id + * @returns {Promise} virtual try on Object { + * "id": tryonId, + * "product_sku": "productSku" + * "created": 'datetime', + * "image: "https://url.to.tryon.image.com" + * } */ virtualTryOn(id, product) { if (!id) {