I have two sets of arrays data, one for orders and one for picking orders. The order id of those arrays is the same. Data for picking orders is nested arrays. There is one value named orderHasAlcohol in the Picking orders data. I'd like to make a new array in which I can add orderHasAlcohol from the Orders data.
I am not sure how I can do it.
const ordersData = [
{
additionalInfo: null,
comment: null,
deliveryDate: "2022-07-14",
deliveryMethod: "PICKUP",
deliveryTime: "10-12",
discountCode: null,
id: "1234", // orderId
orderStatus: "NEW",
paymentMethod: "ON_DELIVERY",
paymentStatus: "UNAVAILABLE",
storeId: "12345",
},
{
additionalInfo: null,
comment: null,
deliveryDate: "2022-07-23",
deliveryMethod: "PICKUP",
deliveryTime: "10-12",
discountCode: null,
id: "123", // orderId
orderStatus: "NEW",
paymentMethod: "ON_DELIVERY",
paymentStatus: "UNAVAILABLE",
storeId: "12345",
},
{
additionalInfo: null,
comment: null,
deliveryDate: "2022-07-23",
deliveryMethod: "PICKUP",
deliveryTime: "10-12",
discountCode: null,
id: "198", // orderId
orderStatus: "NEW",
paymentMethod: "ON_DELIVERY",
paymentStatus: "UNAVAILABLE",
storeId: "12345",
},
{
additionalInfo: null,
comment: null,
deliveryDate: "2022-07-23",
deliveryMethod: "PICKUP",
deliveryTime: "10-12",
discountCode: null,
id: "125", // orderId
orderStatus: "NEW",
paymentMethod: "ON_DELIVERY",
paymentStatus: "UNAVAILABLE",
storeId: "12345",
},
];
const pickingOrder = {
ordersPickedAndDone: {
orderCount: 0,
rows: [],
},
ordersPickedAndPaid: {
orderCount: 0,
rows: [],
},
ordersPickedCanStart: {
orderCount: 2,
rows: [
{
orderHasAlcohol: false,
orderId: "123",
},
{
orderHasAlcohol: true,
orderId: "198",
},
],
},
ordersPickingProgress: {
orderCount: 2,
rows: [
{
pickingRun: 1,
partitions: [
{
orderHasAlcohol: false,
orderId: "125",
},
{
orderHasAlcohol: true,
orderId: "1234",
},
],
},
],
},
};
// This is my expected arrays output
const expectedArrays = [
{
additionalInfo: null,
comment: null,
deliveryDate: "2022-07-14",
deliveryMethod: "PICKUP",
deliveryTime: "10-12",
discountCode: null,
id: "1234", // orderId
orderStatus: "NEW",
paymentMethod: "ON_DELIVERY",
paymentStatus: "UNAVAILABLE",
storeId: "12345",
orderHasAlcohol: true,
},
{
additionalInfo: null,
comment: null,
deliveryDate: "2022-07-23",
deliveryMethod: "PICKUP",
deliveryTime: "10-12",
discountCode: null,
id: "123", // orderId
orderStatus: "NEW",
paymentMethod: "ON_DELIVERY",
paymentStatus: "UNAVAILABLE",
storeId: "12345",
orderHasAlcohol: false,
},
{
additionalInfo: null,
comment: null,
deliveryDate: "2022-07-23",
deliveryMethod: "PICKUP",
deliveryTime: "10-12",
discountCode: null,
id: "198", // orderId
orderStatus: "NEW",
paymentMethod: "ON_DELIVERY",
paymentStatus: "UNAVAILABLE",
storeId: "12345",
orderHasAlcohol: true,
},
{
additionalInfo: null,
comment: null,
deliveryDate: "2022-07-23",
deliveryMethod: "PICKUP",
deliveryTime: "10-12",
discountCode: null,
id: "125", // orderId
orderStatus: "NEW",
paymentMethod: "ON_DELIVERY",
paymentStatus: "UNAVAILABLE",
storeId: "12345",
orderHasAlcohol: false,
},
];
console.log({expectedArrays});
P.S.: I am using ramda for my function validation. it would be nice to create new array by using ramda. but not necessary.