Skip to content

Commit

Permalink
Merge pull request #281 from EnMarche/feature/door/fixes
Browse files Browse the repository at this point in the history
Fix door to door comments part 1
  • Loading branch information
felginep committed Jan 12, 2022
2 parents c23fedf + f442896 commit ad69556
Show file tree
Hide file tree
Showing 35 changed files with 342 additions and 139 deletions.
Binary file removed src/assets/images/papPositionIcon.png
Binary file not shown.
Binary file removed src/assets/images/[email protected]
Binary file not shown.
Binary file removed src/assets/images/[email protected]
Binary file not shown.
Binary file modified src/assets/images/papToFinishCard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/assets/localizables/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,9 @@
"noPassage": "Aucun passage",
"passageOn": "le {{date}}",
"lastPassageBy": "{{firstname}} {{lastname}}., le {{date}}",
"electorsMet": "Électeurs rencontrés",
"doorKnocked": "Portes frappées",
"date_format": "D MMM YYYY",
"doorsSurveysCount": "{{numberOfSurveys}}/{{numberOfDoors}}",
"doorsSurveysCount": "{{numberOfDoors}}/{{numberOfSurveys}}",
"votersCount": "{{votersCount}}",
"ranking": {
"title": "Classements",
Expand Down Expand Up @@ -556,7 +555,8 @@
"newDoor": "Une porte de plus !",
"recap": "Tu as réalisé un total de {{doorsCount}} porte frappée et récolté {{pollsCount}} questionnaire. Merci pour ton engagement !",
"knockNewDoor": "Frapper à une nouvelle porte",
"stop": "Arrêter le porte-à-porte"
"stop": "Arrêter le porte-à-porte",
"ranking": "Classement"
}
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/core/entities/BuildingBlock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid from 'react-native-uuid'
import { BuildingType } from './DoorToDoor'

export interface BuildingBlock {
name: string
Expand All @@ -21,6 +22,9 @@ export type BuildingBlockStatus = 'todo' | 'ongoing' | 'completed'
export type BuildingBlocFloorStatus = 'todo' | 'ongoing' | 'completed'

export class BuildingBlockHelper {
private HOUSE_DEFAULT_FLOOR_COUNT = 1
private BUILDING_DEFAULT_FLOOR_COUNT = 3

public createLocalFloor(name: number): BuildingBlockFloor {
return {
number: name,
Expand All @@ -32,7 +36,14 @@ export class BuildingBlockHelper {
}
}

public createLocalBlock(name: string, floorsCount: number): BuildingBlock {
public createLocalBlock(
name: string,
buildingType: BuildingType,
): BuildingBlock {
const floorsCount =
buildingType === 'building'
? this.BUILDING_DEFAULT_FLOOR_COUNT
: this.HOUSE_DEFAULT_FLOOR_COUNT
const floors = Array.from({ length: floorsCount }, (_, i) =>
this.createLocalFloor(i),
)
Expand Down
2 changes: 1 addition & 1 deletion src/core/entities/DoorToDoorPollParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface DoorToDoorPollParams {
campaignId: string
interlocutorStatus: string
status: string
buildingId: string
block: string
floor: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import DoorToDoorRepository from '../../data/DoorToDoorRepository'
import { DoorToDoorCampaign } from '../entities/DoorToDoorCampaign'
import { DoorToDoorCampaignRanking } from '../entities/DoorToDoorCampaignRanking'

export class GetDoorToDoorCampaignPopupInteractor {
export class GetDoorToDoorCampaignInfoInteractor {
private repository = DoorToDoorRepository.getInstance()

public async execute(campaignId: string): Promise<DoorToDoorCampaignPopup> {
public async execute(campaignId: string): Promise<DoorToDoorCampaignInfo> {
const campaign = await this.repository.getCampaign(campaignId)
const ranking = await this.repository.getDoorToDoorCampaignRanking(
campaignId,
Expand All @@ -17,7 +17,7 @@ export class GetDoorToDoorCampaignPopupInteractor {
}
}

export interface DoorToDoorCampaignPopup {
export interface DoorToDoorCampaignInfo {
campaign: DoorToDoorCampaign
ranking: DoorToDoorCampaignRanking
}
10 changes: 5 additions & 5 deletions src/core/interactor/SendDoorPollAnswersInteractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ export class SendDoorPollAnswersInteractor {

public async execute(
campaignId: string,
interlocutorStatus: string,
status: string,
buildingParams: BuildingSelectedParams,
pollResult: DoorToDoorPollResult,
pollResult?: DoorToDoorPollResult,
): Promise<void> {
const pollParams = {
campaignId: campaignId,
buildingId: buildingParams.id,
interlocutorStatus: interlocutorStatus,
status: status,
block: buildingParams.block,
floor: buildingParams.floor,
door: buildingParams.door,
}
const response = await this.repository.createDoorPollCampaignHistory(
pollParams,
pollResult,
pollResult ?? { answers: [], qualificationAnswers: [] },
)
if (interlocutorStatus === INTERLOCUTOR_ACCEPT_TO_ANSWER_CODE) {
if (status === INTERLOCUTOR_ACCEPT_TO_ANSWER_CODE && pollResult) {
await this.repository.sendDoorToDoorPollAnswers(response.uuid, pollResult)
}
}
Expand Down
69 changes: 69 additions & 0 deletions src/core/interactor/UpdateBuildingLayoutInteractor.ts
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
}
}
2 changes: 1 addition & 1 deletion src/data/mapper/DoorToDoorMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const DoorToDoorMapper = {
const buildingType = restObject.building.type
if (rest_campaign !== null && buildingType !== null) {
const campaign = {
numberOfDoors: rest_campaign.nb_doors,
numberOfDoors: rest_campaign.nb_visited_doors,
numberOfSurveys: rest_campaign.nb_surveys,
status: rest_campaign.status,
id: rest_campaign.uuid,
Expand Down
2 changes: 1 addition & 1 deletion src/data/mapper/RestDoorToDoorPollRequestMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const RestDoorToDoorPollRequestMapper = {
return {
...RestPollExtraAnswersRequestMapper.map(pollResult.qualificationAnswers),
campaign: pollParams.campaignId,
status: pollParams.interlocutorStatus,
status: pollParams.status,
building: pollParams.buildingId,
building_block: pollParams.block,
floor: pollParams.floor,
Expand Down
8 changes: 4 additions & 4 deletions src/data/restObjects/BuildingLayoutMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export const BuildingLayoutMapper = {
return {
number: restFloor.number,
id: restFloor.uuid,
status: restFloor.campaign_statistics.status,
nbSurveys: restFloor.campaign_statistics.nb_surveys,
visitedDoors: restFloor.campaign_statistics.visited_doors,
status: restFloor.campaign_statistics?.status ?? 'todo',
nbSurveys: restFloor.campaign_statistics?.nb_surveys ?? 0,
visitedDoors: restFloor.campaign_statistics?.visited_doors ?? [],
local: false,
}
}),
id: restBlock.uuid,
status: restBlock.campaign_statistics.status,
status: restBlock.campaign_statistics?.status ?? 'todo',
local: false,
}
})
Expand Down
4 changes: 2 additions & 2 deletions src/data/restObjects/RestBuildingBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface RestBuildingBlock {
name: string
floors: RestBuildingBlockFloor[]
uuid: string
campaign_statistics: RestBuildingBlockCampaignStatistics
campaign_statistics?: RestBuildingBlockCampaignStatistics
}

export interface RestBuildingBlockCampaignStatistics {
Expand All @@ -12,7 +12,7 @@ export interface RestBuildingBlockCampaignStatistics {
export type RestBuildingBlockFloor = {
number: number
uuid: string
campaign_statistics: RestBuildingBlockFloorCampaignStatistics
campaign_statistics?: RestBuildingBlockFloorCampaignStatistics
}

export type RestBuildingBlockFloorCampaignStatistics = {
Expand Down
2 changes: 1 addition & 1 deletion src/data/restObjects/RestDoorToDoorAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface RestDoorToDoorAddress {
uuid: string
campaign_statistics: {
uuid: string
nb_doors: number
nb_visited_doors: number
nb_surveys: number
last_passage: string | null
status: 'todo' | 'ongoing' | 'completed'
Expand Down
Loading

0 comments on commit ad69556

Please sign in to comment.