Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#1,895 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
javascript, nodejs
領域
api

調査の方向性

createSyncCategories とそのエントリーポイントである buildActions から始め、提供されている asset 名更新の例を再現します。結果が removeAsset アクションと addAsset アクションを含む 1 つのフラットな配列であり、配列の配列ではないことを確認します。

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
JavaScript
スター
77
フォーク
70
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

commercetools/nodejs のほかの issue

commercetools/nodejs の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。