Skip to content

Commit

Permalink
Merge pull request #22 from 3dlook-me/try-look-methods
Browse files Browse the repository at this point in the history
feat: try look methods
  • Loading branch information
ilias-musin-3d committed Jun 21, 2021
2 parents 4cdcab4 + 02e3b19 commit a600be3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
60 changes: 60 additions & 0 deletions lib/api/person.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -370,6 +390,46 @@ class Person {
return taskSetId;
});
}

/**
* Processing virtual tryon for specific person and product
* result also would be available in person.get(id).virtual_tryons
* [
* {
* "id": tryonId,
* "product_sku": "productSku"
* "created": 'datetime',
* "image: "https://url.to.tryon.image.com"
* }
* ]
*
* @async
* @param {number} id - Person's ID
* @param {any} product - Product sku
* @returns {Promise<Object>} virtual try on Object {
* "id": tryonId,
* "product_sku": "productSku"
* "created": 'datetime',
* "image: "https://url.to.tryon.image.com"
* }
*/
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;
4 changes: 2 additions & 2 deletions lib/api/sizechart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down

0 comments on commit a600be3

Please sign in to comment.