From 078e5d38cde3e4a8e5b6f88db1987a9e77e535f6 Mon Sep 17 00:00:00 2001 From: bennetr <76742318+bennetrr@users.noreply.github.com> Date: Sun, 26 Mar 2023 16:15:30 +0200 Subject: [PATCH 1/3] Added fix for duplicated parts --- src/connectors/RebrickableAPI.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/connectors/RebrickableAPI.ts b/src/connectors/RebrickableAPI.ts index 426d290..0d81540 100644 --- a/src/connectors/RebrickableAPI.ts +++ b/src/connectors/RebrickableAPI.ts @@ -44,7 +44,7 @@ export default class RebrickableApi { const minifigsResponse = await this.ax.get(`sets/${setNumber}/minifigs/?page_size=10000`); const minifigsResponseData = minifigsResponse.data.results; - const partsData: LegoPartsRecord[] = partsResponseData.map(part => ({ + const partsDataUnCleaned: LegoPartsRecord[] = partsResponseData.map(part => ({ part_number: part.part.part_num, part_name: part.part.name, color_name: part.color.name, @@ -54,6 +54,23 @@ export default class RebrickableApi { set: undefined })); + // Rebrickable has multiple entries for the same part when there are spare parts + // Combine these entries in one single entry + let partsData: LegoPartsRecord[] = []; + + // Sets only allow unique items + const partNumbers = new Set(partsDataUnCleaned.map(part => part.part_number)); + + partNumbers.forEach(partNumber => { + // Get all parts with the same product number + const partEntries = partsDataUnCleaned.filter(part => part.part_number == partNumber); + const newPartEntry = partEntries[0]; + + // Add up the total counts of every entry + newPartEntry.total_count = partEntries.map(part => part.total_count).reduce((a, b) => a + b); + partsData = [...partsData, newPartEntry]; + }); + const minifigsData: LegoPartsRecord[] = minifigsResponseData.map(minifig => ({ part_number: minifig.set_num, part_name: minifig.set_name, From 3098bbf4886983422c05f8d78623cb242993471d Mon Sep 17 00:00:00 2001 From: wemogy Mac 1 <76742318+bennetrr@users.noreply.github.com> Date: Sun, 26 Mar 2023 16:28:59 +0200 Subject: [PATCH 2/3] Included colors as part identifiers --- src/connectors/RebrickableAPI.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/connectors/RebrickableAPI.ts b/src/connectors/RebrickableAPI.ts index 0d81540..4e9c5b9 100644 --- a/src/connectors/RebrickableAPI.ts +++ b/src/connectors/RebrickableAPI.ts @@ -59,11 +59,11 @@ export default class RebrickableApi { let partsData: LegoPartsRecord[] = []; // Sets only allow unique items - const partNumbers = new Set(partsDataUnCleaned.map(part => part.part_number)); + const partIdentifier = new Set(partsDataUnCleaned.map(part => `${part.part_number}###${part.color_name}`)); - partNumbers.forEach(partNumber => { + partIdentifier.forEach(identifier => { // Get all parts with the same product number - const partEntries = partsDataUnCleaned.filter(part => part.part_number == partNumber); + const partEntries = partsDataUnCleaned.filter(part => identifier == `${part.part_number}###${part.color_name}`); const newPartEntry = partEntries[0]; // Add up the total counts of every entry From 9bb22ee59d049d7af624466366019b9eb3fc9e33 Mon Sep 17 00:00:00 2001 From: wemogy Mac 1 <76742318+bennetrr@users.noreply.github.com> Date: Sun, 26 Mar 2023 16:29:38 +0200 Subject: [PATCH 3/3] Update docker-compose.yml --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 0af1aa7..f2e3243 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ volumes: services: pocketbase: - image: ghcr.io/bennetrr/lego-pocketbase:v1.0.0 + image: ghcr.io/bennetrr/lego-pocketbase:v1.0.1 container_name: lego-pocketBase restart: always ports: @@ -16,7 +16,7 @@ services: target: /pb/ app: - image: ghcr.io/bennetrr/lego-app:v1.0.0 + image: ghcr.io/bennetrr/lego-app:v1.0.1 container_name: lego-app restart: always ports: