-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #281 from EnMarche/feature/door/fixes
Fix door to door comments part 1
- Loading branch information
Showing
35 changed files
with
342 additions
and
139 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import DoorToDoorRepository from '../../data/DoorToDoorRepository' | ||
import AlphabetHelper from '../../utils/AlphabetHelper' | ||
import { | ||
BuildingBlock, | ||
BuildingBlockFloor, | ||
BuildingBlockHelper, | ||
} from '../entities/BuildingBlock' | ||
import { BuildingType } from '../entities/DoorToDoor' | ||
|
||
export class UpdateBuildingLayoutInteractor { | ||
private buildingBlockHelper = new BuildingBlockHelper() | ||
private repository = DoorToDoorRepository.getInstance() | ||
|
||
public async execute( | ||
buildingId: string, | ||
campaignId: string, | ||
buildingType: BuildingType, | ||
currentBuidlingLayout: Array<BuildingBlock>, | ||
): Promise<Array<BuildingBlock>> { | ||
const remoteBlocks = await this.repository.buildingBlocks( | ||
buildingId, | ||
campaignId, | ||
) | ||
|
||
const localBuildingBlocks = currentBuidlingLayout.filter( | ||
(item) => item.local || item.floors.some((floor) => floor.local), | ||
) | ||
|
||
const blocksMap = remoteBlocks.reduce((map, block) => { | ||
return map.set(block.name, block) | ||
}, new Map<string, BuildingBlock>()) | ||
|
||
localBuildingBlocks.forEach((localBlock) => { | ||
if (blocksMap.has(localBlock.name)) { | ||
// Add missing local floors to building block | ||
const currentBlock = blocksMap.get(localBlock.name) | ||
if (currentBlock) { | ||
const floors = currentBlock?.floors ?? [] | ||
const floorsMap = floors.reduce((map, floor) => { | ||
return map.set(floor.number, floor) | ||
}, new Map<number, BuildingBlockFloor>()) | ||
|
||
localBlock.floors.forEach((floor) => { | ||
if (!floorsMap?.has(floor.number)) { | ||
floorsMap.set(floor.number, floor) | ||
} | ||
}) | ||
|
||
currentBlock.floors = Array.from(floorsMap.values()) | ||
} | ||
} else { | ||
// Add missing local building block | ||
blocksMap.set(localBlock.name, localBlock) | ||
} | ||
}) | ||
|
||
const mergedBlocks = Array.from(blocksMap.values()) | ||
if (mergedBlocks.length === 0) { | ||
mergedBlocks.push( | ||
this.buildingBlockHelper.createLocalBlock( | ||
AlphabetHelper.firstLetterInAlphabet, | ||
buildingType, | ||
), | ||
) | ||
} | ||
|
||
return mergedBlocks | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.