Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate typhoon to new mock #1488

Merged
merged 12 commits into from
Jan 22, 2025
6 changes: 6 additions & 0 deletions interfaces/IBF-dashboard/src/app/services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,12 @@ export class ApiService {
} else if (disasterType.disasterType === DisasterTypeKey.malaria) {
apiPath = 'mock/malaria';
isNewBodyFormat = true;
} else if (disasterType.disasterType === DisasterTypeKey.drought) {
apiPath = 'mock/drought';
isNewBodyFormat = true;
} else if (disasterType.disasterType === DisasterTypeKey.typhoon) {
apiPath = 'mock/typhoon';
isNewBodyFormat = true;
}

const body = isNewBodyFormat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
} from 'class-validator';
import { JoinColumn, ManyToOne } from 'typeorm';

import indicatorData from '../../../scripts/mock-data/drought/ETH/trigger/Belg JAS_Belg/upload-alert_threshold-2.json';
import { DynamicDataPlaceCodeDto } from '../../admin-area-dynamic-data/dto/dynamic-data-place-code.dto';
import indicatorData from '../../admin-area-dynamic-data/dto/example/ETH/drought/upload-alert_threshold-2.json';
import { UpdateableStaticIndicator } from '../../admin-area-dynamic-data/enum/dynamic-data-unit';
import { AdminLevel } from '../../country/admin-level.enum';
import { CountryEntity } from '../../country/country.entity';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs';
import path from 'path';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';

Expand Down Expand Up @@ -260,10 +261,15 @@ export class AdminAreaDynamicDataService {
);
}
try {
fs.writeFileSync(
`./geoserver-volume/raster-files/output/${subfolder}/${data.originalname}`,
data.buffer,
const ROOT_DIR = path.resolve('./geoserver-volume/raster-files/output');
jannisvisser marked this conversation as resolved.
Show resolved Hide resolved
const filePath = path.resolve(
ROOT_DIR,
`${subfolder}/${data.originalname}`,
);
if (!filePath.startsWith(ROOT_DIR)) {
throw new Error('Invalid file path');
}
fs.writeFileSync(filePath, data.buffer);
} catch (e) {
console.error(e);
throw new HttpException('File not written: ' + e, HttpStatus.NOT_FOUND);
Expand Down
Loading
Loading