Skip to main content
async pending promise
Origen Enlace
Jonathan
  • 313
  • 3
  • 14
const ordersDispached = async disp => disp.map(e => e.stops.reduce((acc, e2) => ({ ...acc, [e2.siteId]: e2.numberOfOrders }), {}))

const timerService = async disp => disp.map(e => e.stops.reduce((acc, e2) => ({ ...acc, [e2.siteId]: `${e2.numberOfOrders * 10}min` }), {}))

    const mergeObjets = async(disp, sites) => {
  try{
    let obj1 = await ordersDispached(disp).then(r=>r).catch(e=>e)
    let obj2 = await timerServicetimerServiceByStops(sitesdisp).then(r=>r).catch(e=>e)
    newObjvar obj = {..Object.assign({}, obj1, obj2})
    console.log(newObjobj)
  }
  catch(e){
    console.error(e)
  }
} 

console.log(mergeObjets(disp, sites))
const ordersDispached = async disp => disp.map(e => e.stops.reduce((acc, e2) => ({ ...acc, [e2.siteId]: e2.numberOfOrders }), {}))

const timerService = async disp => disp.map(e => e.stops.reduce((acc, e2) => ({ ...acc, [e2.siteId]: `${e2.numberOfOrders * 10}min` }), {}))

const mergeObjets = async(disp, sites) => {
  try{
    let obj1 = await ordersDispached(disp)
    let obj2 = await timerService(sites)
    newObj = {...obj1, obj2}
    console.log(newObj)
  }
  catch(e){
    console.error(e)
  }
}
console.log(mergeObjets(disp, sites))
const ordersDispached = async disp => disp.map(e => e.stops.reduce((acc, e2) => ({ ...acc, [e2.siteId]: e2.numberOfOrders }), {}))

const timerService = async disp => disp.map(e => e.stops.reduce((acc, e2) => ({ ...acc, [e2.siteId]: `${e2.numberOfOrders * 10}min` }), {}))

    const mergeObjets = async(disp) => {
  try{
    let obj1 = await ordersDispached(disp).then(r=>r).catch(e=>e)
    let obj2 = await timerServiceByStops(disp).then(r=>r).catch(e=>e)
    var obj = Object.assign({}, obj1, obj2)
    console.log(obj)
  }
  catch(e){
    console.error(e)
  }
} 

console.log(mergeObjets(disp, sites))
array sites =
  [
    {
        "id": 1,
        "type": "distribution-center",
        "openTime": null,
        "closeTime": null
    },]];
array disp = const disp = [
    {
        "id": 1,
        "startTime": "08:55",
        "stops": [
            {
                "siteId": 1,
                "sequence": 1,
                "numberOfOrders": null
            },]
    }];
array sites =
 [
    {
        "id": 1,
        "type": "distribution-center",
        "openTime": null,
        "closeTime": null
    },]
array disp = const disp = [
    {
        "id": 1,
        "startTime": "08:55",
        "stops": [
            {
                "siteId": 1,
                "sequence": 1,
                "numberOfOrders": null
            },]}
sites = [
    {
        "id": 1,
        "type": "distribution-center",
        "openTime": null,
        "closeTime": null
}];
disp = const disp = [
    {
        "id": 1,
        "startTime": "08:55",
        "stops": [
            {
                "siteId": 1,
                "sequence": 1,
                "numberOfOrders": null
            }]
    }];
arrays, que inyecto en la funcion
Origen Enlace
Jonathan
  • 313
  • 3
  • 14
const ordersDispached = async disp => disp.map(e => e.stops.reduce((acc, e2) => ({ ...acc, [e2.siteId]: e2.numberOfOrders }), {}))

const timerService = async disp => disp.map(e => e.stops.reduce((acc, e2) => ({ ...acc, [e2.siteId]: `${e2.numberOfOrders * 10}min` }), {}))

const mergeObjets = async(disp, sites) => {
  try{
    let obj1 = await ordersDispached(disp)
    let obj2 = await timerService(sites)
    newObj = {...obj1, obj2}
    console.log(newObj)
  }
  catch(e){
    console.error(e)
  }
}
console.log(mergeObjets(disp, sites))

Pero esto me retorna el error de TypeError: Cannot read property 'reduce' of undefined y no entiendo por que. arrays, que le inyecto a las funciones hijas para luego llamarlas en el mergeObjects inyectando estos mismo arrays

array sites =
[
    {
        "id": 1,
        "type": "distribution-center",
        "openTime": null,
        "closeTime": null
    },]
array disp = const disp = [
    {
        "id": 1,
        "startTime": "08:55",
        "stops": [
            {
                "siteId": 1,
                "sequence": 1,
                "numberOfOrders": null
            },]}
const ordersDispached = async disp => disp.map(e => e.stops.reduce((acc, e2) => ({ ...acc, [e2.siteId]: e2.numberOfOrders }), {}))

const timerService = async disp => disp.map(e => e.stops.reduce((acc, e2) => ({ ...acc, [e2.siteId]: `${e2.numberOfOrders * 10}min` }), {}))

const mergeObjets = async(disp, sites) => {
  try{
    let obj1 = await ordersDispached(disp)
    let obj2 = await timerService(sites)
    newObj = {...obj1, obj2}
    console.log(newObj)
  }
  catch(e){
    console.error(e)
  }
}

Pero esto me retorna el error de TypeError: Cannot read property 'reduce' of undefined y no entiendo por que.

const ordersDispached = async disp => disp.map(e => e.stops.reduce((acc, e2) => ({ ...acc, [e2.siteId]: e2.numberOfOrders }), {}))

const timerService = async disp => disp.map(e => e.stops.reduce((acc, e2) => ({ ...acc, [e2.siteId]: `${e2.numberOfOrders * 10}min` }), {}))

const mergeObjets = async(disp, sites) => {
  try{
    let obj1 = await ordersDispached(disp)
    let obj2 = await timerService(sites)
    newObj = {...obj1, obj2}
    console.log(newObj)
  }
  catch(e){
    console.error(e)
  }
}
console.log(mergeObjets(disp, sites))

Pero esto me retorna el error de TypeError: Cannot read property 'reduce' of undefined y no entiendo por que arrays, que le inyecto a las funciones hijas para luego llamarlas en el mergeObjects inyectando estos mismo arrays

array sites =
[
    {
        "id": 1,
        "type": "distribution-center",
        "openTime": null,
        "closeTime": null
    },]
array disp = const disp = [
    {
        "id": 1,
        "startTime": "08:55",
        "stops": [
            {
                "siteId": 1,
                "sequence": 1,
                "numberOfOrders": null
            },]}
Ortografía
Origen Enlace
g.4
  • 3.5k
  • 2
  • 11
  • 22
Loading
Origen Enlace
Jonathan
  • 313
  • 3
  • 14
Loading