My array returned prints same objects multiple times, using await Promise.all with map()

96 Views Asked by At

When I print the length of the array it is 3, so basically arr[0], arr[1], arr[2] contain same objects, why is that so The array returned should be of length 1 containing all the objects.

const arr = await Promise.all(
          ratingsArr.map(async (rating) => {
            const pmRatingObj = {
              rateeId: rating.employeeId,
              createdAt: rating.createdAt,
              updatedAt: rating.updatedAt,
              rateeType: 'employee',
              raterId: rating.projectManagerId,
              freeze: rating.PMFreeze,
            };
            const pmRatingId = await queryInterface.bulkInsert('ratings', [pmRatingObj]);
            // console.log(pmRatingId);
    
            const archRatingObj = {
              rateeId: rating.employeeId,
              createdAt: rating.createdAt,
              updatedAt: rating.updatedAt,
              rateeType: 'employee',
              raterId: rating.projectArchitectId,
              freeze: rating.PMFreeze,
            };
            const archRatingId = await queryInterface.bulkInsert('ratings', [archRatingObj]);
    
            const pmArr = await createPMAttributes(pmRatingId, rating);
            pmArr.map((pm) => {
              newArr.push(pm);
            });
            const archArr = await createArchAttributes(archRatingId, rating);
            archArr.map((arch) => {
              newArr.push(arch);
            });
    
            return newArr;
    
            
          }),
        );
0

There are 0 best solutions below