Last active
June 18, 2019 03:04
-
-
Save diegodfsd/0093e2cecb422b686744d81ce65d548e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Com o uso de javascript você deve transformar os dados recebidos da api externa | |
// no modelo esperado no Nexp. Estão disponíveis construções do ES6. | |
// É obrigatório que a função principal seja atribuida para a variável 'transform' | |
// declarada com var. | |
// Utilize as variaveis disponiveis no contexto para informar sobre o sucesso ou falha | |
// do seu processo de transformação. | |
var transform = function(response) { | |
const data = JSON.parse(response); | |
try { | |
const orders = data.orders.map(o => { | |
return ({ | |
orderNumber: o.header.orderNumber, | |
channel: o.header.channel, | |
status: o.header.orderStatus, | |
createdAt: o.header.salesOrderCreationDate, | |
lastUpdate: o.header.orderLastUpdate, | |
inMultipleStores: [...new Set(o.item.map(i => i.storageLocationId))].length > 1, | |
items: o.item.map(i => ({ | |
sku: i.productId, | |
ean: i.productEAN, | |
quantity: i.productQuantity, | |
shipmentFrom: i.shipmentPlant, | |
quantity: i.productQuantity, | |
deliveryType: i.deliveryTypeName, | |
deliveryDate: i.deliveryDateItem, | |
deliveryModeName: i.deliveryModeName, | |
storageLocation: i.storageLocationId, | |
itemId: i.orderItem, | |
lote: i.productBatchId, | |
isExpress: /expressa/i.test(i.deliveryModeName) | |
})).filter(i => i.storageLocation === 'C050') | |
}); | |
}).filter(o => o.items.length > 0); | |
context.HasNexpPage = data.header.total > (data.header._offset + data.header._limit); | |
context.Result = JSON.stringify(orders); | |
context.Success = true; | |
} catch(error) { | |
context.ErrorMessage = error.message; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment