diff --git a/src/server/index.test.js b/src/server/index.test.js index eaeb633..7e5f11c 100644 --- a/src/server/index.test.js +++ b/src/server/index.test.js @@ -89,7 +89,7 @@ describe("Item", () => { const res = await query({ query: gql` query { - items(ids: ["38912", "38911"]) { + items(ids: ["38912", "38911", "37375"]) { id name @@ -113,6 +113,23 @@ describe("Item", () => { expect(res.data).toMatchInlineSnapshot(` Object { "items": Array [ + Object { + "appearanceOn": Object { + "layers": Array [ + Object { + "id": "30203", + "imageUrl": "https://impress-asset-images.s3.amazonaws.com/object/000/000/006/6829/600x600.png?0", + "zone": Object { + "depth": 3, + "id": "3", + "label": "Background", + }, + }, + ], + }, + "id": "37375", + "name": "Moon and Stars Background", + }, Object { "appearanceOn": Object { "layers": Array [ @@ -153,26 +170,30 @@ describe("Item", () => { expect(queryFn.mock.calls).toMatchInlineSnapshot(` Array [ Array [ - "SELECT * FROM items WHERE id IN (?,?)", + "SELECT * FROM items WHERE id IN (?,?,?)", Array [ "38912", "38911", + "37375", ], ], Array [ - "SELECT * FROM item_translations WHERE item_id IN (?,?) AND locale = \\"en\\"", + "SELECT * FROM item_translations WHERE item_id IN (?,?,?) AND locale = \\"en\\"", Array [ + "37375", "38911", "38912", ], ], Array [ - "SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?)", + "SELECT * FROM pet_types WHERE (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?) OR (species_id = ? AND color_id = ?)", Array [ "54", "75", "54", "75", + "54", + "75", ], ], Array [ @@ -180,8 +201,10 @@ describe("Item", () => { INNER JOIN parents_swf_assets rel ON rel.parent_type = \\"Item\\" AND rel.swf_asset_id = sa.id - WHERE (rel.parent_id = ? AND sa.body_id = ?) OR (rel.parent_id = ? AND sa.body_id = ?)", + WHERE (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0)) OR (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0)) OR (rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0))", Array [ + "37375", + "180", "38911", "180", "38912", @@ -189,15 +212,17 @@ describe("Item", () => { ], ], Array [ - "SELECT * FROM zones WHERE id IN (?,?)", + "SELECT * FROM zones WHERE id IN (?,?,?)", Array [ + "3", "40", "26", ], ], Array [ - "SELECT * FROM zone_translations WHERE zone_id IN (?,?) AND locale = \\"en\\"", + "SELECT * FROM zone_translations WHERE zone_id IN (?,?,?) AND locale = \\"en\\"", Array [ + "3", "40", "26", ], diff --git a/src/server/loaders.js b/src/server/loaders.js index d23ebf1..f34e38f 100644 --- a/src/server/loaders.js +++ b/src/server/loaders.js @@ -57,7 +57,9 @@ const buildSwfAssetLoader = (db) => const conditions = []; const values = []; for (const { itemId, bodyId } of itemAndBodyPairs) { - conditions.push("(rel.parent_id = ? AND sa.body_id = ?)"); + conditions.push( + "(rel.parent_id = ? AND (sa.body_id = ? OR sa.body_id = 0))" + ); values.push(itemId, bodyId); } @@ -73,7 +75,10 @@ const buildSwfAssetLoader = (db) => const entities = rows.map(normalizeRow); return itemAndBodyPairs.map(({ itemId, bodyId }) => - entities.filter((e) => e.parentId === itemId && e.bodyId === bodyId) + entities.filter( + (e) => + e.parentId === itemId && (e.bodyId === bodyId || e.bodyId === "0") + ) ); });