You are on page 1of 3

************** el único no opcional es sku **************

eliminar los sku's, volver a insertarlos (borrar solo los que vienen en el body)
eliminar y colver a cargar todas las listas relacionadas al sku

array de id's de listas puede estar vacía

-----------------------------------------------------------
METER A CÓDIGO

%dw 2.0
output application/json
var arr = {
"data":[
{
"defaultList":"01s4600000403pTAAQ",
"products":[
{
"sku":"200385",
"priceLists":[
{
"list":"01s4600000403pTAAQ",
"price":8.7
},
{
"list":"01s4p000003gD6CAAU",
"price":8.8
},
{
"list":"01s4p000003gTKeAAM",
"price":8.9
}
],
"name":"Bran Frut Fresa 58g",

"imageUrl":"https://cananalitica.mx/DM/Portal_Imagenes/imgs/7501000116447_200385_BR
AN FRUT FRESA 58G BIMBO SP_BM-036080-03-F20.png",
"cb":"7501000116447",
"category":"Barras",
"brand":"BIMBO",
"active":"true"
},
{
"sku":"200386",
"priceLists":[
{
"list":"01s4600000403pTAAQ",
"price":8.8
},
{
"list":"01s4p000003gD6CAAU",
"price":8.9
}
],
"name":"Bran Frut Piña 58g",

"imageUrl":"https://res.cloudinary.com/walmart-labs/image/upload/w_960,dpr_auto,f_a
uto,q_auto:best/gr/images/product-images/img_large/00750100013776L.jpg",
"cb":"7501000116448",
"category":"Barras",
"brand":"BIMBO",
"active":"true"
}
]
}
]
}
---
//arr.data.products

// current delete
//arr.data[0].products map ((item, index) -> {"sku": item.sku})
/*
arr.data.products[0] reduce ((item, acc = []) ->
acc ++ [{"sku": item.sku}]
)
*/

// Current prods insertion


/*
arr.data[0].products map ((item, index) ->
{
"sku": item.sku as Number,
"name": item.name,
"bucket_image_url": "123" ++ item.sku ++ ".png",
"category": item.category,
"brand": item.brand,
"cb": item.cb,
"active": item.active as Boolean,
"imageUrl": item.imageUrl
}
)*/
/*
arr.data.products[0] reduce ((item, acc = []) ->
acc ++ [
{
"sku": item.sku as Number,
"name": item.name,
"bucket_image_url": "123" ++ item.sku ++ ".png",
"category": item.category,
"brand": item.brand,
"cb": item.cb,
"active": item.active as Boolean,
"imageUrl": item.imageUrl
}
]
)
*/
// Current final insertion
/*
arr.data[0].products reduce ((item, acc = []) ->
acc ++ (
item.priceLists map ((itemMap, index) ->
{
"list_id": itemMap.list,
"sku": item.sku as Number,
"price": itemMap.price
}
)
)
)
*/
// New
/*
*/
arr.data.products[0] reduce ((item, acc = []) ->
acc ++ (
item.priceLists map ((itemMap, index) ->
{
"sku": item.sku as Number,
"list_id": itemMap.list,
"price": itemMap.price
}
)
)
)

You might also like