Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

syncCategories.buildActions returns action in the wrong format (array of arrays)

Đang mở
#1,895 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, nodejs
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu tại createSyncCategories và điểm vào buildActions của nó, tái hiện ví dụ cập nhật tên asset được cung cấp. Xác minh rằng kết quả là một mảng phẳng duy nhất chứa các action removeAsset và addAsset, thay vì một mảng các mảng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Support reference number
Description
const { createSyncCategories } = require('@commercetools/sync-actions')

const syncCategories = createSyncCategories()

const newCategory = {
  key: 'category-8accca22-4d57-4692-bee0-483e43502088',
  name: {
    de: 'Test',
  },
  slug: {
    en: 'category-8accca22-4d57-4692-bee0-483e43502088-slug',
  },
  assets: [
    {
      key: 'asset-key-1-4ab57b6d-3a0e-46a3-b9b2-539ce4fde618',
      name: {
        en: 'asset name - 1',
      },
      description: {
        en: 'asset description - 1',
      },
      sources: [
        {
          key: 'source-key-138d0808-f4f4-4fa8-a9de-48d803eec277',
          uri: 'https://google.com',
        },
      ],
      tags: ['tag-1', 'tag-2'],
    },
    {
      key: 'asset-key-3-551a2305-25cc-4fb3-a79c-fcb272be3b89',
      name: {
        en: 'asset name - 3',
      },
      description: {
        en: 'asset description - 3',
      },
      sources: [
        {
          key: 'source-key-ca27d6c8-5b65-431f-ad65-21bed9abd2a9',
          uri: 'https://google.com',
        },
      ],
      tags: ['tag-5', 'tag-6'],
    },
    {
      key: 'asset-key-2-986daecf-f793-462f-a598-0ee769af331d',
      name: {
        en: 'asset name - updated',
      },
      description: {
        en: 'asset description - 2',
      },
      sources: [
        {
          key: 'source-key-8ccb652c-6abc-4c6b-bec0-071ca8948106',
          uri: 'https://google.com',
        },
      ],
      tags: ['tag-3', 'tag-4'],
    },
  ],
  orderHint: '0.000017176731611011768329613',
}
const category = {
  id: '5cd1b242-9e27-4199-9cc5-f7057c5f988d',
  version: 1,
  versionModifiedAt: '2024-06-06T11:26:01.104Z',
  lastMessageSequenceNumber: 1,
  createdAt: '2024-06-06T11:26:01.104Z',
  lastModifiedAt: '2024-06-06T11:26:01.104Z',
  lastModifiedBy: {
    clientId: 'REDACTED',
    isPlatformClient: false,
  },
  createdBy: {
    clientId: 'REDACTED',
    isPlatformClient: false,
  },
  key: 'category-8accca22-4d57-4692-bee0-483e43502088',
  name: {
    en: 'Category 8accca22-4d57-4692-bee0-483e43502088',
  },
  slug: {
    en: 'category-8accca22-4d57-4692-bee0-483e43502088-slug',
  },
  ancestors: [],
  orderHint: '0.000017176731611011768329613',
  assets: [
    {
      id: 'a7112cd1-0e67-4b35-84a3-3ede87d392e7',
      sources: [
        {
          uri: 'https://google.com',
          key: 'source-key-138d0808-f4f4-4fa8-a9de-48d803eec277',
        },
      ],
      name: {
        en: 'asset name - 1',
      },
      key: 'asset-key-1-4ab57b6d-3a0e-46a3-b9b2-539ce4fde618',
      description: {
        en: 'asset description - 1',
      },
      tags: ['tag-1', 'tag-2'],
    },
    {
      id: '4ed62080-ce1e-4f92-93e7-e07e2a6e06bc',
      sources: [
        {
          uri: 'https://google.com',
          key: 'source-key-8ccb652c-6abc-4c6b-bec0-071ca8948106',
        },
      ],
      name: {
        en: 'asset name - 2',
      },
      key: 'asset-key-2-986daecf-f793-462f-a598-0ee769af331d',
      description: {
        en: 'asset description - 2',
      },
      tags: ['tag-3', 'tag-4'],
    },
    {
      id: '38acda20-4722-4d84-8bcd-b7a8dc33f096',
      sources: [
        {
          uri: 'https://google.com',
          key: 'source-key-ca27d6c8-5b65-431f-ad65-21bed9abd2a9',
        },
      ],
      name: {
        en: 'asset name - 3',
      },
      key: 'asset-key-3-551a2305-25cc-4fb3-a79c-fcb272be3b89',
      description: {
        en: 'asset description - 3',
      },
      tags: ['tag-5', 'tag-6'],
    },
  ],
}

const onlyAssetNameChanged = {
  ...category,
  assets: category.assets.map((asset, index) => {
    if (index !== 1) return asset

    return {
      ...asset,
      name: {
        ...asset.name,
        en: asset.name.en + ' - updated',
      },
    }
  }),
}

const actions = syncCategories.buildActions(onlyAssetNameChanged, category)
console.log(JSON.stringify(actions, null, 2))


Expected Behavior

I expect to get array of actions


  [
    {
      "action": "removeAsset",
      "assetId": "4ed62080-ce1e-4f92-93e7-e07e2a6e06bc"
    },
    {
      "action": "addAsset",
      "asset": {
        "id": "4ed62080-ce1e-4f92-93e7-e07e2a6e06bc",
        "sources": [
          {
            "uri": "https://google.com",
            "key": "source-key-8ccb652c-6abc-4c6b-bec0-071ca8948106"
          }
        ],
        "name": {
          "en": "asset name - 2 - updated"
        },
        "key": "asset-key-2-986daecf-f793-462f-a598-0ee769af331d",
        "description": {
          "en": "asset description - 2"
        },
        "tags": [
          "tag-3",
          "tag-4"
        ]
      }
    }
  ]

Current Behavior

Currently I get, array of array of actions

[
  [
    {
      "action": "removeAsset",
      "assetId": "4ed62080-ce1e-4f92-93e7-e07e2a6e06bc"
    },
    {
      "action": "addAsset",
      "asset": {
        "id": "4ed62080-ce1e-4f92-93e7-e07e2a6e06bc",
        "sources": [
          {
            "uri": "https://google.com",
            "key": "source-key-8ccb652c-6abc-4c6b-bec0-071ca8948106"
          }
        ],
        "name": {
          "en": "asset name - 2 - updated"
        },
        "key": "asset-key-2-986daecf-f793-462f-a598-0ee769af331d",
        "description": {
          "en": "asset description - 2"
        },
        "tags": [
          "tag-3",
          "tag-4"
        ]
      }
    }
  ]
]
Context
Possible Solution
Ngôn ngữ chính
JavaScript
Star
77
Fork
70
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của commercetools/nodejs

Tất cả issue của commercetools/nodejs

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.