Skip to content

Commit

Permalink
fix: AB#6356 update based on review. Change snake to camelcase
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenGeo committed Mar 1, 2021
1 parent 9f5a924 commit c6e87c3
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
'chat-component.active-event-active-trigger.welcome'
| translate
: {
startDate: eventService.state.event.start_date,
startDate: eventService.state.event.startDate,
days: eventService.state.firstLeadTime
}
"
Expand All @@ -75,8 +75,8 @@
'chat-component.active-event-no-trigger.welcome'
| translate
: {
startDate: eventService.state.event.start_date,
endDate: eventService.state.event.end_date
startDate: eventService.state.event.startDate,
endDate: eventService.state.event.endDate
}
"
></p>
Expand All @@ -97,7 +97,7 @@
*ngFor="let area of filteredAreas; first as isFirst"
[isConnected]="!isFirst"
>
<form (submit)="submitEapAction(area.pcode)">
<form (submit)="submitEapAction(area.placeCode)">
<ion-row>
<ion-col size-lg="2" size-md="2" size-xs="2">
<ion-img
Expand All @@ -120,8 +120,7 @@
| translate
: {
exposedNumber:
area[indicatorName.population_affected]
| number: '.0-0'
area['populationAffected'] | number: '.0-0'
}
"
>
Expand All @@ -140,7 +139,11 @@
[checked]="action.checked"
name="action.action"
(ionChange)="
changeAction(area.pcode, action.action, $event.detail.checked)
changeAction(
area.placeCode,
action.action,
$event.detail.checked
)
"
></ion-checkbox>
<ion-label class="action-label ion-text-wrap"
Expand Down
29 changes: 16 additions & 13 deletions interfaces/IBF-dashboard/src/app/components/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class ChatComponent implements OnDestroy {
.getTriggeredAreas()
.subscribe((newAreas) => {
this.triggeredAreas = newAreas;
console.log('this.triggeredAreas: ', this.triggeredAreas);
this.filteredAreas = [...this.triggeredAreas];
this.triggeredAreas.forEach((area) => (area.submitDisabled = true));
});
Expand All @@ -85,7 +86,7 @@ export class ChatComponent implements OnDestroy {
.subscribe((placeCode: PlaceCode) => {
if (placeCode) {
this.filteredAreas = this.triggeredAreas.filter(
(area) => area.pcode === placeCode.placeCode,
(area) => area.placeCode === placeCode.placeCode,
);
} else {
this.filteredAreas = [...this.triggeredAreas];
Expand All @@ -100,12 +101,12 @@ export class ChatComponent implements OnDestroy {
this.placeCodeSubscription.unsubscribe();
}

public changeAction(pcode: string, action: string, checkbox: boolean) {
public changeAction(placeCode: string, action: string, checkbox: boolean) {
this.countryService
.getCountrySubscription()
.subscribe((country: Country) => {
this.analyticsService.logEvent(AnalyticsEvent.eapAction, {
placeCode: pcode,
placeCode: placeCode,
eapAction: action,
eapActionStatus: checkbox,
page: AnalyticsPage.dashboard,
Expand All @@ -115,7 +116,7 @@ export class ChatComponent implements OnDestroy {
});
});

const area = this.triggeredAreas.find((i) => i.pcode === pcode);
const area = this.triggeredAreas.find((i) => i.placeCode === placeCode);
const changedAction = area.eapActions.find((i) => i.action === action);
changedAction.checked = checkbox;
if (!this.changedActions.includes(changedAction)) {
Expand All @@ -125,30 +126,32 @@ export class ChatComponent implements OnDestroy {
(item) => !(changedAction.action === item.action),
);
}
this.triggeredAreas.find((i) => i.pcode === pcode).submitDisabled =
this.triggeredAreas.find((i) => i.placeCode === placeCode).submitDisabled =
this.changedActions.length === 0;
}

public async submitEapAction(pcode: string) {
public async submitEapAction(placeCode: string) {
this.countryService
.getCountrySubscription()
.subscribe((country: Country) => {
this.analyticsService.logEvent(AnalyticsEvent.eapSubmit, {
placeCode: pcode,
placeCode: placeCode,
page: AnalyticsPage.dashboard,
country: country.countryCodeISO3,
isActiveEvent: this.eventService.state.activeEvent,
isActiveTrigger: this.eventService.state.activeTrigger,
});
});

this.triggeredAreas.find((i) => i.pcode === pcode).submitDisabled = true;
this.triggeredAreas.find(
(i) => i.placeCode === placeCode,
).submitDisabled = true;
const activeCountry = this.countryService.getActiveCountry();

try {
const submitEAPActionResult = await Promise.all(
this.changedActions.map(async (action) => {
if (action.pcode === pcode) {
if (action.pcode === placeCode) {
return this.eapActionsService.checkEapAction(
action.action,
activeCountry.countryCodeISO3,
Expand All @@ -162,7 +165,7 @@ export class ChatComponent implements OnDestroy {
);

this.changedActions = this.changedActions.filter(
(i) => i.pcode !== pcode,
(i) => i.pcode !== placeCode,
);

this.actionResult(this.updateSuccessMessage, (): void =>
Expand Down Expand Up @@ -205,13 +208,13 @@ export class ChatComponent implements OnDestroy {
{
text: this.closeEventPopup['cancel'],
handler: () => {
console.log('Cancel close pcode');
console.log('Cancel close place code');
},
},
{
text: this.closeEventPopup['confirm'],
handler: () => {
this.closePlaceCodeEvent(area.id, area.pcode);
this.closePlaceCodeEvent(area.id, area.placeCode);
},
},
],
Expand All @@ -223,7 +226,7 @@ export class ChatComponent implements OnDestroy {
eventPlaceCodeId: number,
placeCode: string,
) {
this.apiService.closeEventPlaceCode(eventPlaceCodeId);
await this.apiService.closeEventPlaceCode(eventPlaceCodeId);
this.filteredAreas = this.filteredAreas.filter(
(item) => item.id !== eventPlaceCodeId,
);
Expand Down
6 changes: 3 additions & 3 deletions interfaces/IBF-dashboard/src/app/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ export class ApiService {
).toPromise();
}

closeEventPlaceCode(eventPcodeId: number) {
closeEventPlaceCode(eventPlacecodeId: number) {
return this.post(
'event/close-pcode',
'event/close-place-code',
{
eventPcodeId,
eventPlacecodeId,
},
false,
).toPromise();
Expand Down
4 changes: 2 additions & 2 deletions interfaces/IBF-dashboard/src/app/services/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export class EventService {
this.state.event = await this.timelineService.getEvent();
this.state.activeEvent = !!this.state.event;
this.state.activeTrigger =
this.state.event && this.state.event.active_trigger;
this.state.event && this.state.event.activeTrigger;
this.state.newEvent =
this.state.event?.start_date ===
this.state.event?.startDate ===
this.timelineService.state.today.format('YYYY-MM-DD');
this.setAlertState();

Expand Down
6 changes: 3 additions & 3 deletions services/API-service/src/api/data/data.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ export class TriggeredArea {

export class CountryEvent {
public country_code: string;
public start_date: string;
public end_date: string;
public active_trigger: boolean;
public startDate: string;
public endDate: string;
public activeTrigger: boolean;
}

export class CountryMetaData {
Expand Down
2 changes: 1 addition & 1 deletion services/API-service/src/api/data/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class DataService {
.readFileSync('./src/api/data/sql/get-country-event.sql')
.toString();
const result = await this.manager.query(query, [countryCodeISO3]);
if (!result[0].start_date) {
if (!result[0].startDate) {
return null;
}
return result[0];
Expand Down
35 changes: 19 additions & 16 deletions services/API-service/src/api/data/sql/get-country-event.sql
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@



select
to_char(max(end_date) , 'yyyy-mm-dd') as end_date,
to_char(min(start_date), 'yyyy-mm-dd') as start_date,
max(country_code) as country_code,
max(active_trigger::int)::boolean as active_trigger
to_char(max("endDate") , 'yyyy-mm-dd') as "endDate",
to_char(min("startDate"), 'yyyy-mm-dd') as "startDate",
max(country_code) as "countryCode",
max("activeTrigger"::int)::boolean as "activeTrigger"
from
(
select
e.pcode,
e."placeCode" ,
coalesce(a2.country_code , a1.country_code) as country_code,
coalesce(a2.population_affected, a1.population_affected) as population_affected,
e.end_date,
e.start_date,
e.active_trigger
e."endDate",
e."startDate",
e."activeTrigger"
from
"IBF-pipeline-output".event_pcode e
"IBF-pipeline-output".event_place_code e
left join "IBF-API"."Admin_area_data2" a2 on
a2.pcode = e.pcode
a2.pcode = e."placeCode"
and a2.current_prev = 'Current'
and a2.country_code is not null
left join "IBF-API"."Admin_area_data1" a1 on
a1.pcode = e.pcode
a1.pcode = e."placeCode"
and a1.current_prev = 'Current'
and a1.country_code is not null
where
closed = false
group by
e.pcode,
e."placeCode",
a2.population_affected,
a1.population_affected,
a2.country_code,
a1.country_code,
e.end_date,
e.start_date,
e."active_trigger"
e."endDate",
e."startDate",
e."activeTrigger"
order by
population_affected desc ) as event_pcode_country where country_code = $1
population_affected desc ) as event_place_code_country where country_code = $1
17 changes: 9 additions & 8 deletions services/API-service/src/api/data/sql/get-triggered-areas.sql
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
select

select
*
from
(
select
e.pcode,
e."placeCode",
coalesce(a2.name, a1.name) as name,
coalesce(a2.population_affected, a1.population_affected) as population_affected,
coalesce(a2.population_affected, a1.population_affected) as "populationAffected",
e.id
from
"IBF-pipeline-output".event_pcode e
"IBF-pipeline-output".event_place_code e
left join "IBF-API"."Admin_area_data2" a2 on
a2.pcode = e.pcode
a2.pcode = e."placeCode"
and a2.country_code = $1
and a2.name is not null
and a2.current_prev = 'Current'
left join "IBF-API"."Admin_area_data1" a1 on
a1.pcode = e.pcode
a1.pcode = e."placeCode"
and a1.current_prev = 'Current'
and a1.name is not null
and a1.country_code = $2
where
closed = false
group by
e.pcode,
e."placeCode",
a2.population_affected,
a1.population_affected,
a2.name,
a1.name,
e.id
order by
population_affected desc ) as ec
"populationAffected" desc ) as ec
where
name is not null
14 changes: 7 additions & 7 deletions services/API-service/src/api/event/event-place-code.entity.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { Entity, Column, Check, PrimaryGeneratedColumn } from 'typeorm';

@Entity('event_pcode', { schema: 'IBF-pipeline-output' })
@Entity('event_place_code', { schema: 'IBF-pipeline-output' })
export class EventPlaceCodeEntity {
@PrimaryGeneratedColumn()
public id: number;

@Column({})
public pcode: string;
public placeCode: string;

@Column({ type: 'timestamp' })
public start_date: Date;
public startDate: Date;

@Column({ type: 'timestamp', nullable: true })
@Check(`"start_date" < "end_date"`)
public end_date: Date;
@Check(`"startDate" < "endDate"`)
public endDate: Date;

@Column({ type: 'timestamp', nullable: true })
public manual_closed_date: Date;
public manualClosedDate: Date;

@Column({ default: true })
public active_trigger: boolean;
public activeTrigger: boolean;

@Column({ default: false })
public closed: boolean;
Expand Down
4 changes: 2 additions & 2 deletions services/API-service/src/api/event/event.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventPcodeEntity } from './event-pcode.entity';
import { EventPlaceCodeEntity } from './event-place-code.entity';
import { EventService } from './event.service';
import { Test, TestingModule } from '@nestjs/testing';
import { EventController } from './event.controller';
Expand All @@ -14,7 +14,7 @@ describe('EventController', (): void => {
const module: TestingModule = await Test.createTestingModule({
imports: [
TypeOrmModule.forRoot(),
TypeOrmModule.forFeature([UserEntity, EventPcodeEntity]),
TypeOrmModule.forFeature([UserEntity, EventPlaceCodeEntity]),
UserModule,
],
controllers: [EventController],
Expand Down
4 changes: 2 additions & 2 deletions services/API-service/src/api/event/event.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class EventController {
this.eventService = eventService;
}

@ApiOperation({ summary: 'Check EAP actions as done' })
@Post('close-pcode')
@ApiOperation({ summary: 'Close place code event' })
@Post('close-place-code')
public async closeEventPcode(
@Body() eventPlaceCodeDto: EventPlaceCodeDto,
): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions services/API-service/src/api/event/event.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { EventPcodeEntity } from './event-pcode.entity';
import { EventService } from './event.service';
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { repositoryMockFactory } from '../../mock/repositoryMock.factory';
import { EventPlaceCodeEntity } from './event-place-code.entity';

describe('User service', (): void => {
let service: EventService;
Expand All @@ -11,7 +11,7 @@ describe('User service', (): void => {
const module: TestingModule = await Test.createTestingModule({
providers: [
{
provide: getRepositoryToken(EventPcodeEntity),
provide: getRepositoryToken(EventPlaceCodeEntity),
useFactory: repositoryMockFactory,
},
EventService,
Expand Down
Loading

0 comments on commit c6e87c3

Please sign in to comment.