Skip to content

Commit

Permalink
feat: Update based on review AB#6356
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenGeo committed Feb 28, 2021
1 parent 8df106b commit 9f5a924
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
</ion-row>
</form>
<ion-button
(click)="closePcodeEventPopup(area)"
(click)="closePlaceCodeEventPopup(area)"
color="ibf-royal-blue"
expand="block"
[translate]="'chat-component.active-event.close-event-button'"
Expand Down
24 changes: 14 additions & 10 deletions interfaces/IBF-dashboard/src/app/components/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,12 @@ export class ChatComponent implements OnDestroy {
await alert.present();
}

public async closePcodeEventPopup(area) {
const message = this.closeEventPopup['message'].replace(
'{{ name of district }}',
area.name,
);
public async closePlaceCodeEventPopup(area) {
const message = await this.translateService
.get('chat-component.active-event.close-event-popup.message', {
placCodeName: area.name,
})
.toPromise();
const alert = await this.alertController.create({
message: message,
buttons: [
Expand All @@ -210,18 +211,21 @@ export class ChatComponent implements OnDestroy {
{
text: this.closeEventPopup['confirm'],
handler: () => {
this.closePcodeEvent(area.id, area.pcode);
this.closePlaceCodeEvent(area.id, area.pcode);
},
},
],
});
await alert.present();
}

public async closePcodeEvent(eventPcodeId: number, pcode: string) {
this.apiService.closeEventPcode(eventPcodeId);
public async closePlaceCodeEvent(
eventPlaceCodeId: number,
placeCode: string,
) {
this.apiService.closeEventPlaceCode(eventPlaceCodeId);
this.filteredAreas = this.filteredAreas.filter(
(item) => item.id !== eventPcodeId,
(item) => item.id !== eventPlaceCodeId,
);
this.countryService
.getCountrySubscription()
Expand All @@ -231,7 +235,7 @@ export class ChatComponent implements OnDestroy {
country: country.countryCodeISO3,
isActiveEvent: this.eventService.state.activeEvent,
isActiveTrigger: this.eventService.state.activeTrigger,
pcode: pcode,
placeCode: placeCode,
});
});
let loading = await this.loadingCtrl.create({});
Expand Down
2 changes: 1 addition & 1 deletion interfaces/IBF-dashboard/src/app/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class ApiService {
).toPromise();
}

closeEventPcode(eventPcodeId: number) {
closeEventPlaceCode(eventPcodeId: number) {
return this.post(
'event/close-pcode',
{
Expand Down
6 changes: 3 additions & 3 deletions interfaces/IBF-dashboard/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@
"place-name": "District: <strong>{{ placeName }}</strong>",
"exposed-population": "Exposed Population: <strong>{{ exposedNumber }}</strong>",
"submit-button-label": "Submit",
"close-event-button": "Close event",
"close-event-button": "Close Event",
"update-success": "EAP action(s) updated in database.",
"update-failure": "Failed to update EAP action(s) updated in database.",
"prompt-button-label": "OK",
"close-event-popup": {
"message": "You are about to close the triggered event in {{ name of district }}. This action can not be undone.",
"confirm": "Close event",
"message": "You are about to close the triggered event in {{ placCodeName }}. This action can not be undone.",
"confirm": "Close Event",
"cancel": "Cancel"

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

@ApiOperation({ summary: 'Get active country event' })
@ApiParam({ name: 'countryCode', required: true, type: 'string' })
@Get('event/:countryCode')
@ApiParam({ name: 'countryCodeISO3', required: true, type: 'string' })
@Get('event/:countryCodeISO3')
public async getCountryEvent(@Param() params): Promise<CountryEvent> {
return await this.dataService.getCountryEvent(params.countryCode);
return await this.dataService.getCountryEvent(params.countryCodeISO3);
}
}
20 changes: 11 additions & 9 deletions services/API-service/src/api/data/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export class DataService {
}

public async getAdminAreaData(
countryCode: string,
countryCodeISO3: string,
adminLevel: number,
leadTime: string,
): Promise<GeoJson> {
let pcodes;
pcodes = (await this.getTriggeredAreas(countryCode)).map(
(area): string => "'" + area.pcode + "'",
let placeCodes;
placeCodes = (await this.getTriggeredAreas(countryCodeISO3)).map(
(triggeredArea): string => "'" + triggeredArea.pcode + "'",
);
const query = (
'select * \
Expand All @@ -41,11 +41,13 @@ export class DataService {
and current_prev = 'Current' \
and country_code = $2"
).concat(
pcodes.length > 0 ? ' and pcode in (' + pcodes.toString() + ')' : '',
placeCodes.length > 0
? ' and pcode in (' + placeCodes.toString() + ')'
: '',
);
const rawResult: AdminAreaDataRecord[] = await this.manager.query(query, [
leadTime,
countryCode,
countryCodeISO3,
]);
const result = this.toGeojson(rawResult);
return result;
Expand Down Expand Up @@ -128,12 +130,12 @@ export class DataService {
return result;
}

public async getCountryEvent(countryCode: string): Promise<CountryEvent> {
public async getCountryEvent(countryCodeISO3: string): Promise<CountryEvent> {
const query = fs
.readFileSync('./src/api/data/sql/get-country-event.sql')
.toString();
const result = await this.manager.query(query, [countryCode]);
if (!result[0].country_code) {
const result = await this.manager.query(query, [countryCodeISO3]);
if (!result[0].start_date) {
return null;
}
return result[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export class EapActionsService {
closed = false
and pcode = $1`;

const eventPcodeId = await this.manager.query(query, [eapAction.pcode])[0][
'id'
];
const eventPlaceCodeId = await this.manager.query(query, [
eapAction.pcode,
])[0]['id'];

const action = new EapActionStatusEntity();
action.status = eapAction.status;
action.pcode = eapAction.pcode;
action.event = eventPcodeId;
action.event = eventPlaceCodeId;
action.actionChecked = actionId;

// If no user, take default user for now
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IsNotEmpty, IsNumber } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export class EventPcodeDto {
export class EventPlaceCodeDto {
@ApiProperty()
@IsNotEmpty()
@IsNumber()
public eventPcodeId: number;
public eventPlacecodeId: number;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Entity, Column, Check, PrimaryGeneratedColumn } from 'typeorm';

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

@Column({ nullable: true })
@Column({})
public pcode: string;

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

@Column({ type: 'timestamp', nullable: true })
Expand Down
6 changes: 3 additions & 3 deletions services/API-service/src/api/event/event.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventPcodeDto } from './dto/event-pcode.dto';
import { EventPlaceCodeDto } from './dto/event-place-code.dto';
import { EventService } from './event.service';
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
Expand All @@ -18,8 +18,8 @@ export class EventController {
@ApiOperation({ summary: 'Check EAP actions as done' })
@Post('close-pcode')
public async closeEventPcode(
@Body() eventPcodeDto: EventPcodeDto,
@Body() eventPlaceCodeDto: EventPlaceCodeDto,
): Promise<void> {
return await this.eventService.closeEventPcode(eventPcodeDto);
return await this.eventService.closeEventPcode(eventPlaceCodeDto);
}
}
4 changes: 2 additions & 2 deletions services/API-service/src/api/event/event.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { EventPcodeEntity } from './event-pcode.entity';
import { EventPlaceCodeEntity } from './event-place-code.entity';
import { UserModule } from './../user/user.module';
import { Module } from '@nestjs/common';
import { EventController } from './event.controller';
import { EventService } from './event.service';
import { TypeOrmModule } from '@nestjs/typeorm';

@Module({
imports: [UserModule, TypeOrmModule.forFeature([EventPcodeEntity])],
imports: [UserModule, TypeOrmModule.forFeature([EventPlaceCodeEntity])],
controllers: [EventController],
providers: [EventService],
exports: [EventService],
Expand Down
24 changes: 13 additions & 11 deletions services/API-service/src/api/event/event.service.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
/* eslint-disable @typescript-eslint/camelcase */
import { EventPcodeEntity } from './event-pcode.entity';
import { EventPlaceCodeEntity } from './event-place-code.entity';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { EventPcodeDto } from './dto/event-pcode.dto';
import { EventPlaceCodeDto } from './dto/event-place-code.dto';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';

@Injectable()
export class EventService {
@InjectRepository(EventPcodeEntity)
private readonly eventPcodeRepo: Repository<EventPcodeEntity>;
@InjectRepository(EventPlaceCodeEntity)
private readonly eventPlaceCodeRepo: Repository<EventPlaceCodeEntity>;

public async closeEventPcode(eventPcodeDto: EventPcodeDto): Promise<void> {
const eventPcode = await this.eventPcodeRepo.findOne(
eventPcodeDto.eventPcodeId,
public async closeEventPcode(
eventPlaceCodeDto: EventPlaceCodeDto,
): Promise<void> {
const eventPlaceCode = await this.eventPlaceCodeRepo.findOne(
eventPlaceCodeDto.eventPlacecodeId,
);
if (!eventPcode) {
if (!eventPlaceCode) {
const errors = 'Event Pcode not found';
throw new HttpException({ errors }, HttpStatus.NOT_FOUND);
}
eventPcode.closed = true;
eventPcode.manual_closed_date = new Date();
await this.eventPcodeRepo.save(eventPcode);
eventPlaceCode.closed = true;
eventPlaceCode.manual_closed_date = new Date();
await this.eventPlaceCodeRepo.save(eventPlaceCode);
}
}
2 changes: 1 addition & 1 deletion services/API-service/src/api/indicator/indicator.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
export class IndicatorEntity {
@PrimaryGeneratedColumn('uuid')
public id: string;
@Column({ nullable: true })
@Column()
public country_codes: string;
@Column()
public name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ from (
where t1.fc_trigger=1
and t1.current_prev = 'Current'
and t2.lead_time = '7-day'
GROUP BY t1.pcode, start_date, end_date
) districtsToday
left join "IBF-pipeline-output".event_pcode districtsExisting
on districtsToday.pcode = districtsExisting.pcode
Expand Down

0 comments on commit 9f5a924

Please sign in to comment.