Мне нужна ваша поддержка, чтобы получить следующий результат в ramda.
Я сделал несколько способов и достиг этих результатов, но теперь мне нужно выполнить слияние с помощью productCode, генерирующего следующее результат, где serviceType будет массивом, упорядоченным и связанным по продолжительности:
ДАННЫЕ
data = [
{
"id": "ck5ii4ysl04vn0744z7liu0f3",
"pdvIntegrationStatus": "WAITING",
"sapIntegrationStatus": "WAITING",
"updatedAt": "2020-01-17T18:34:13.075Z",
"category": {
"code": "CEL",
"description": "Celular e Smartphones"
},
"serviceType": {
"code": "RF",
"description": "descrição SEGURO ROUBO OU FURTO"
},
"productCode": "4004593",
"duration": [
24,
12
]
},
{
"id": "ck5ii4yr704vc0744sjw3tljd",
"pdvIntegrationStatus": "WAITING",
"sapIntegrationStatus": "WAITING",
"updatedAt": "2020-01-17T18:34:13.075Z",
"category": {
"code": "CEL",
"description": "Celular e Smartphones"
},
"serviceType": {
"code": "GE",
"description": "descrição da garantia estendida"
},
"productCode": "4004593",
"duration": [
12
]
},
{
"id": "ck5ii4yr704vc0744sjw3tljr",
"pdvIntegrationStatus": "INTEGRATED",
"sapIntegrationStatus": "INTEGRATED",
"updatedAt": "2020-01-18T15:34:09.000Z",
"category": {
"code": "DUC",
"description": "Duchas e chuveiros"
},
"serviceType": {
"code": "GE",
"description": "descrição da garantia estendida"
},
"productCode": "4004594",
"duration": [
24
]
},
{
"id": "ck5ii4ysl04vn0744z7liu0f6",
"pdvIntegrationStatus": "WAITING",
"sapIntegrationStatus": "INTEGRATED",
"updatedAt": "2020-01-17T18:34:13.075Z",
"category": {
"code": "DUC",
"description": "Duchas e chuveiros"
},
"serviceType": {
"code": "RF",
"description": "descrição SEGURO ROUBO OU FURTO"
},
"productCode": "4004596",
"duration": [
24,
12
]
},
{
"id": "ck5ii4ysl04vn0744z7liu0f0",
"pdvIntegrationStatus": "INTEGRATED",
"sapIntegrationStatus": "WAITING",
"updatedAt": "2020-01-17T18:34:13.075Z",
"category": {
"code": "CEL",
"description": "Celular e Smartphones"
},
"serviceType": {
"code": "GE",
"description": "descrição da garantia estendida"
},
"productCode": "4004595",
"duration": [
12
]
},
{
"id": "ck5ii4ysl04vn0744z7liu0f1",
"pdvIntegrationStatus": "INTEGRATED",
"sapIntegrationStatus": "INTEGRATED",
"updatedAt": "2020-01-17T18:34:13.075Z",
"category": {
"code": "DUC",
"description": "Duchas e chuveiros"
},
"serviceType": {
"code": "GE",
"description": "descrição da garantia estendida"
},
"productCode": "4004596",
"duration": [
12
]
},
{
"id": "ck5ii4ysl04vn0744z7liu0f2",
"pdvIntegrationStatus": "INTEGRATED",
"sapIntegrationStatus": "INTEGRATED",
"updatedAt": "2020-01-17T18:34:13.075Z",
"category": {
"code": "VENT",
"description": "Ventiladores"
},
"serviceType": {
"code": "GE",
"description": "descrição da garantia estendida"
},
"productCode": "4004597",
"duration": [
24
]
},
{
"id": "ck5ii4ysl04vn0744z7liu0f4",
"pdvIntegrationStatus": "INTEGRATED",
"sapIntegrationStatus": "INTEGRATED",
"updatedAt": "2020-01-17T18:34:13.075Z",
"category": {
"code": "DUC",
"description": "Duchas e chuveiros"
},
"serviceType": {
"code": "RF",
"description": "descrição SEGURO ROUBO OU FURTO"
},
"productCode": "4004594",
"duration": [
12
]
},
{
"id": "ck5ii4ysl04vn0744z7liu0f5",
"pdvIntegrationStatus": "WAITING",
"sapIntegrationStatus": "WAITING",
"updatedAt": "2020-01-17T18:34:13.075Z",
"category": {
"code": "CEL",
"description": "Celular e Smartphones"
},
"serviceType": {
"code": "RF",
"description": "descrição SEGURO ROUBO OU FURTO"
},
"productCode": "4004595",
"duration": [
24
]
},
{
"id": "ck5ii4ysl04vn0744z7liu0f9",
"pdvIntegrationStatus": "WAITING",
"sapIntegrationStatus": "WAITING",
"updatedAt": "2020-01-17T15:34:13.000Z",
"category": {
"code": "VENT",
"description": "Ventiladores"
},
"serviceType": {
"code": "RF",
"description": "descrição SEGURO ROUBO OU FURTO"
},
"productCode": "4004597",
"duration": [
24
]
}
]
РЕЗУЛЬТАТ РЕЗУЛЬТАТОВ
resultExpected = [
{
"id": "ck5ii4ysl04vn0744z7liu0f3",
"productCode": "4004593",
"category": {
"code": "CEL",
"description": "Celular e Smartphones"
},
"updatedAt": "2020-01-17T18:34:13.075Z",
"pdvIntegrationStatus": false,
"sapIntegrationStatus": false,
"serviceType": [
{
"code": "GE",
"description": "descrição da garantia estendida"
},{
"code": "RF",
"description": "descrição SEGURO ROUBO OU FURTO"
}
],
"duration_GE": [
12
],
"duration_RF": [
24,
12
]
},
{
"id": "ck5ii4yr704vc0744sjw3tljr",
"productCode": "4004594",
"category": {
"code": "DUC",
"description": "Duchas e chuveiros"
},
"updatedAt": "2020-01-18T15:34:09.000Z",
"pdvIntegrationStatus": true,
"sapIntegrationStatus": true,
"serviceType": [
{
"code": "GE",
"description": "descrição da garantia estendida"
},
{
"code": "RF",
"description": "descrição SEGURO ROUBO OU FURTO"
}
],
"duration_GE": [
12
],
"duration_RF": [
24
]
},
{
"id": "ck5ii4ysl04vn0744z7liu0f0",
"productCode": "4004595",
"category": {
"code": "CEL",
"description": "Celular e Smartphones"
},
"updatedAt": "2020-01-17T18:34:13.075Z",
"pdvIntegrationStatus": true,
"sapIntegrationStatus": false,
"serviceType": [
{
"code": "GE",
"description": "descrição da garantia estendida"
},
{
"code": "RF",
"description": "descrição SEGURO ROUBO OU FURTO"
}
],
"duration_GE": [
24
],
"duration_RF": [
12
]
},
{
"id": "ck5ii4ysl04vn0744z7liu0f6",
"productCode": "4004596",
"category": {
"code": "DUC",
"description": "Duchas e chuveiros"
},
"updatedAt": "2020-01-17T18:34:13.075Z",
"pdvIntegrationStatus": false,
"sapIntegrationStatus": true,
"serviceType": [
{
"code": "GE",
"description": "descrição da garantia estendida"
}, {
"code": "RF",
"description": "descrição SEGURO ROUBO OU FURTO"
}
],
"duration_GE": [
12
],
"duration_RF": [
24,
12
]
},
{
"id": "ck5ii4ysl04vn0744z7liu0f2",
"productCode": "4004597",
"category": {
"code": "VENT",
"description": "Ventiladores"
},
"updatedAt": "2020-01-17T18:34:13.075Z",
"pdvIntegrationStatus": true,
"sapIntegrationStatus": true,
"serviceType": [
{
"code": "GE",
"description": "descrição da garantia estendida"
},
{
"code": "RF",
"description": "descrição SEGURO ROUBO OU FURTO"
}
],
"duration_GE": [
24
],
"duration_RF": [
24
]
}
]
Я пытался создать этот код, но массив длительности сохраняет его случайным образом по мере поступления информации, и мне нужно первое расположение в пределах продолжительности для «Garantia Extendida» и второе для «Robo o Furto» и знаю как идентифицировать это соглашение о продолжительности, к которому оно относится, например:
Продолжительность: {GE: ['12', '24'], RF: ['24']}
> const groupByTransaction = R.groupBy(R.prop('productCode'));
> const mergeToObject = (rows) => Object.values(rows).map( item => ( { ...R.pickAll(['id'], item[0]), ...R.pickAll(['productCode'], item[0]), ...R.pickAll(['category'],
> item[0]), ...R.pickAll(['updatedAt'], item[0]),
> pdvIntegrationStatus: R.contains(R.pluck('pdvIntegrationStatus',
> item)[0], 'INTEGRATED'), sapIntegrationStatus:
> R.contains(R.pluck('sapIntegrationStatus', item)[0], 'INTEGRATED'),
> serviceType: R.pluck('serviceType', item), duration_GE:
> (R.pluck('duration', item))[1], duration_RF: (R.pluck('duration',
> item))[0] } ));
> const hasDuplicates = R.pipe( groupByTransaction, mergeToObject );
>
> rows = hasDuplicates(rows);