From 031a3bb8187800604185eb620c6015fb77264eeb Mon Sep 17 00:00:00 2001 From: bipinparajuli Date: Tue, 9 Dec 2025 14:28:36 +0545 Subject: [PATCH 1/4] feat:get series by data source --- apps/triggers/src/constant/index.ts | 3 ++ .../src/sources-data/dto/get-series.ts | 19 +++++++++ .../sources-data/sources-data.controller.ts | 8 ++++ .../src/sources-data/sources-data.service.ts | 39 +++++++++++++++++++ .../dhm-adapter/src/services/dhm.service.ts | 31 +++++++++++++-- packages/gfh-adapter/src/gfh.service.ts | 17 ++++++++ .../glofas-adapter/src/glofas.services.ts | 17 ++++++++ 7 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 apps/triggers/src/sources-data/dto/get-series.ts diff --git a/apps/triggers/src/constant/index.ts b/apps/triggers/src/constant/index.ts index dc1f695..cada000 100644 --- a/apps/triggers/src/constant/index.ts +++ b/apps/triggers/src/constant/index.ts @@ -111,6 +111,9 @@ export const MS_TRIGGERS_JOBS = { GET_ONE: 'ms.jobs.sources.getOne', GET_HEALTH: 'ms.jobs.sources.getHealth', }, + SOURCE_DATA: { + GET_SERIES_BY_DATA_SOURCE: 'ms.jobs.sources-data.getSeriesByDataSource', + }, ACTIVITIES: { GET_ONE: 'ms.jobs.activities.getOne', GET_ALL: 'ms.jobs.activities.getAll', diff --git a/apps/triggers/src/sources-data/dto/get-series.ts b/apps/triggers/src/sources-data/dto/get-series.ts new file mode 100644 index 0000000..2415f8d --- /dev/null +++ b/apps/triggers/src/sources-data/dto/get-series.ts @@ -0,0 +1,19 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { DataSource, SourceType } from '@lib/database'; +import { IsEnum, IsOptional, IsString } from 'class-validator'; + +export class GetSeriesDto { + @ApiProperty({ + type: String, + }) + @IsString() + @IsOptional() + type?: SourceType; + + @ApiProperty({ + example: DataSource.DHM, + }) + @IsEnum(DataSource) + @IsString() + dataSource: DataSource; +} diff --git a/apps/triggers/src/sources-data/sources-data.controller.ts b/apps/triggers/src/sources-data/sources-data.controller.ts index 9a76150..48f6166 100644 --- a/apps/triggers/src/sources-data/sources-data.controller.ts +++ b/apps/triggers/src/sources-data/sources-data.controller.ts @@ -5,6 +5,7 @@ import { DhmService } from './dhm.service'; import { GlofasService } from './glofas.service'; import { GetSouceDataDto } from './dto/get-source-data'; import { SourcesDataService } from './sources-data.service'; +import { GetSeriesDto } from './dto/get-series'; @Controller('sources-data') export class SourcesDataController { @@ -56,6 +57,13 @@ export class SourcesDataController { return this.dhmService.getRiverStations(); } + @MessagePattern({ + cmd: MS_TRIGGERS_JOBS.SOURCE_DATA.GET_SERIES_BY_DATA_SOURCE, + }) + async getSeriesByDataSource(payload: GetSeriesDto) { + return this.sourceDataService.findSeriesByDataSource(payload); + } + @MessagePattern({ cmd: MS_TRIGGERS_JOBS.WATER_LEVELS.GET_DHM, }) diff --git a/apps/triggers/src/sources-data/sources-data.service.ts b/apps/triggers/src/sources-data/sources-data.service.ts index 62aa8ee..936bbfd 100644 --- a/apps/triggers/src/sources-data/sources-data.service.ts +++ b/apps/triggers/src/sources-data/sources-data.service.ts @@ -28,6 +28,10 @@ import { buildQueryParams, getFormattedDate } from 'src/common'; import { SettingsService } from '@lib/core'; import { DataSourceValue } from 'src/types/settings'; import { DhmService } from './dhm.service'; +import { GetSeriesDto } from './dto/get-series'; +import { DhmService as DHM } from '@lib/dhm-adapter'; +import { GlofasServices } from '@lib/glofas-adapter'; +import { GfhService } from '@lib/gfh-adapter'; const paginate: PaginatorTypes.PaginateFunction = paginator({ perPage: 10 }); const httpsAgent = new https.Agent({ rejectUnauthorized: false }); @@ -38,6 +42,9 @@ export class SourcesDataService { private prisma: PrismaService, private readonly dhmService: DhmService, private readonly httpService: HttpService, + private readonly dhm: DHM, + private readonly glofasServices: GlofasServices, + private readonly gfhServices: GfhService, ) {} async create(dto: CreateSourcesDataDto) { @@ -95,6 +102,38 @@ export class SourcesDataService { } } + async findSeriesByDataSource(payload: GetSeriesDto) { + try { + if (payload.dataSource === DataSource.DHM) { + const dhm = await this.dhm.getDataSource(); + const dhmTypeData = dhm[0][payload.type]; + + return [ + { + seriesId: Array.isArray(dhmTypeData.SERIESID) + ? dhmTypeData.SERIESID?.toString() + : dhmTypeData.SERIESID, + stationName: dhmTypeData.LOCATION, + }, + ]; + } + if (payload.dataSource === DataSource.GLOFAS) { + const glofas = await this.glofasServices.getDataSource(); + return glofas; + } + if (payload.dataSource === DataSource.GFH) { + const gfh = await this.gfhServices.getDataSource(); + return gfh[0].STATION_LOCATIONS_DETAILS.map((station) => ({ + seriesId: station.STATION_ID, + stationName: station.STATION_NAME, + })); + } + } catch (error: any) { + this.logger.error('Error while fetching source data', error); + throw new RpcException(error); + } + } + async findOne(id: number) { try { this.logger.log(`Fetching sourceData with uuid: ${id}`); diff --git a/packages/dhm-adapter/src/services/dhm.service.ts b/packages/dhm-adapter/src/services/dhm.service.ts index 49fb955..4523f56 100644 --- a/packages/dhm-adapter/src/services/dhm.service.ts +++ b/packages/dhm-adapter/src/services/dhm.service.ts @@ -1,4 +1,9 @@ -import { DataSource, PrismaService, SourceType } from "@lib/database"; +import { + DataSource, + DataSourceValue, + PrismaService, + SourceType, +} from "@lib/database"; import { Inject, Injectable, Logger } from "@nestjs/common"; import { RainfallStationData, @@ -12,7 +17,7 @@ export class DhmService { async saveDataInDhm( type: SourceType, riverBasin: string, - payload: RiverStationData | RainfallStationData, + payload: RiverStationData | RainfallStationData ): Promise { try { return await this.prisma.$transaction(async (tx) => { @@ -51,11 +56,11 @@ export class DhmService { } this.logger.log( - `Series mismatch. Creating new for: ${payloadData.name}`, + `Series mismatch. Creating new for: ${payloadData.name}` ); } else { this.logger.log( - `No record found. Creating new for: ${payloadData.name}`, + `No record found. Creating new for: ${payloadData.name}` ); } @@ -81,4 +86,22 @@ export class DhmService { throw error; } } + + async getDataSource() { + try { + const sourceData = await this.prisma.setting.findFirst({ + where: { + name: "DATASOURCE", + }, + select: { + value: true, + }, + }); + const dhm = (sourceData?.value as Record)["DHM"]; + return dhm; + } catch (error: any) { + this.logger.error("Error while fetching source data", error); + throw error; + } + } } diff --git a/packages/gfh-adapter/src/gfh.service.ts b/packages/gfh-adapter/src/gfh.service.ts index 566e28e..e90b80b 100644 --- a/packages/gfh-adapter/src/gfh.service.ts +++ b/packages/gfh-adapter/src/gfh.service.ts @@ -79,4 +79,21 @@ export class GfhService { throw err; } } + async getDataSource() { + try { + const sourceData = await this.prisma.setting.findFirst({ + where: { + name: "DATASOURCE", + }, + select: { + value: true, + }, + }); + const gfh = (sourceData?.value as Record)["GFH"]; + return gfh; + } catch (error: any) { + this.logger.error("Error while fetching source data", error); + throw error; + } + } } diff --git a/packages/glofas-adapter/src/glofas.services.ts b/packages/glofas-adapter/src/glofas.services.ts index e24f913..ee1fd62 100644 --- a/packages/glofas-adapter/src/glofas.services.ts +++ b/packages/glofas-adapter/src/glofas.services.ts @@ -62,4 +62,21 @@ export class GlofasServices { throw error; } } + async getDataSource() { + try { + const sourceData = await this.prisma.setting.findFirst({ + where: { + name: 'DATASOURCE', + }, + select: { + value: true, + }, + }); + const glofas = (sourceData?.value as Record)['GLOFAS']; + return glofas; + } catch (error: any) { + this.logger.error('Error while fetching source data', error); + throw error; + } + } } From ebd0b6568200b35e516dc5d10dc9ec9fce5ed8f4 Mon Sep 17 00:00:00 2001 From: bipinparajuli Date: Wed, 10 Dec 2025 10:15:35 +0545 Subject: [PATCH 2/4] fix:fetch data from source data --- .../src/sources-data/sources-data.service.ts | 57 ++++++++++++------- .../dhm-adapter/src/services/dhm.service.ts | 19 +++++-- packages/gfh-adapter/src/gfh.service.ts | 21 ++++--- .../src/types/gfh-observation.type.ts | 6 ++ .../glofas-adapter/src/glofas.services.ts | 20 ++++--- .../src/types/glofas-observation.type.ts | 5 ++ 6 files changed, 86 insertions(+), 42 deletions(-) diff --git a/apps/triggers/src/sources-data/sources-data.service.ts b/apps/triggers/src/sources-data/sources-data.service.ts index 936bbfd..3200d09 100644 --- a/apps/triggers/src/sources-data/sources-data.service.ts +++ b/apps/triggers/src/sources-data/sources-data.service.ts @@ -104,29 +104,42 @@ export class SourcesDataService { async findSeriesByDataSource(payload: GetSeriesDto) { try { - if (payload.dataSource === DataSource.DHM) { - const dhm = await this.dhm.getDataSource(); - const dhmTypeData = dhm[0][payload.type]; + const { dataSource, type, riverBasin } = payload; + + switch (dataSource) { + case DataSource.DHM: { + const dhm = await this.dhm.getSourceData(type, riverBasin); + return dhm.map((value) => ({ + seriesId: value.info['series_id'], + stationName: value.info['name'], + })); + } - return [ - { - seriesId: Array.isArray(dhmTypeData.SERIESID) - ? dhmTypeData.SERIESID?.toString() - : dhmTypeData.SERIESID, - stationName: dhmTypeData.LOCATION, - }, - ]; - } - if (payload.dataSource === DataSource.GLOFAS) { - const glofas = await this.glofasServices.getDataSource(); - return glofas; - } - if (payload.dataSource === DataSource.GFH) { - const gfh = await this.gfhServices.getDataSource(); - return gfh[0].STATION_LOCATIONS_DETAILS.map((station) => ({ - seriesId: station.STATION_ID, - stationName: station.STATION_NAME, - })); + case DataSource.GLOFAS: { + const glofas = await this.glofasServices.getSourceData( + type || SourceType.WATER_LEVEL, + riverBasin, + ); + + return glofas.map((value) => ({ + seriesId: value.info['location'].basinId, + stationName: value.info['location'].basinId, + })); + } + + case DataSource.GFH: { + const gfh = await this.gfhServices.getSourceData( + type || SourceType.WATER_LEVEL, + riverBasin, + ); + + return gfh.map((value) => ({ + seriesId: value.info['info'].riverGaugeId, + stationName: value.info['info'].stationName, + })); + } + default: + return []; } } catch (error: any) { this.logger.error('Error while fetching source data', error); diff --git a/packages/dhm-adapter/src/services/dhm.service.ts b/packages/dhm-adapter/src/services/dhm.service.ts index 4523f56..2ee8885 100644 --- a/packages/dhm-adapter/src/services/dhm.service.ts +++ b/packages/dhm-adapter/src/services/dhm.service.ts @@ -1,6 +1,7 @@ import { DataSource, DataSourceValue, + Prisma, PrismaService, SourceType, } from "@lib/database"; @@ -87,18 +88,24 @@ export class DhmService { } } - async getDataSource() { + async getSourceData( + type: SourceType, + riverBasin: string + ): Promise> { try { - const sourceData = await this.prisma.setting.findFirst({ + const sourceData = await this.prisma.sourcesData.findMany({ where: { - name: "DATASOURCE", + dataSource: DataSource.DHM, + source: { + riverBasin, + }, + type, }, select: { - value: true, + info: true, }, }); - const dhm = (sourceData?.value as Record)["DHM"]; - return dhm; + return sourceData; } catch (error: any) { this.logger.error("Error while fetching source data", error); throw error; diff --git a/packages/gfh-adapter/src/gfh.service.ts b/packages/gfh-adapter/src/gfh.service.ts index e90b80b..373d3e2 100644 --- a/packages/gfh-adapter/src/gfh.service.ts +++ b/packages/gfh-adapter/src/gfh.service.ts @@ -1,5 +1,6 @@ -import { DataSource, PrismaService, SourceType } from "@lib/database"; +import { DataSource, Prisma, PrismaService, SourceType } from "@lib/database"; import { Inject, Injectable, Logger } from "@nestjs/common"; +import { SourceInfo } from "types"; @Injectable() export class GfhService { @@ -79,18 +80,24 @@ export class GfhService { throw err; } } - async getDataSource() { + async getSourceData( + type: SourceType, + riverBasin: string + ): Promise { try { - const sourceData = await this.prisma.setting.findFirst({ + const sourceData = await this.prisma.sourcesData.findMany({ where: { - name: "DATASOURCE", + dataSource: DataSource.GFH, + source: { + riverBasin, + }, + type, }, select: { - value: true, + info: true, }, }); - const gfh = (sourceData?.value as Record)["GFH"]; - return gfh; + return sourceData as SourceInfo[]; } catch (error: any) { this.logger.error("Error while fetching source data", error); throw error; diff --git a/packages/gfh-adapter/src/types/gfh-observation.type.ts b/packages/gfh-adapter/src/types/gfh-observation.type.ts index 7d57e6f..db5630c 100644 --- a/packages/gfh-adapter/src/types/gfh-observation.type.ts +++ b/packages/gfh-adapter/src/types/gfh-observation.type.ts @@ -1,3 +1,5 @@ +import { Prisma } from "@lib/database"; + export type GfhStationDetails = { RIVER_BASIN: string; STATION_LOCATIONS_DETAILS: StationLoacationDetails[]; @@ -150,3 +152,7 @@ export interface GfhTransformedResult { forecastDate: string; history: GfhHistoryItem[]; } + +export type SourceInfo = { + info: Prisma.JsonObject; +}; diff --git a/packages/glofas-adapter/src/glofas.services.ts b/packages/glofas-adapter/src/glofas.services.ts index ee1fd62..796d4e3 100644 --- a/packages/glofas-adapter/src/glofas.services.ts +++ b/packages/glofas-adapter/src/glofas.services.ts @@ -1,6 +1,6 @@ import { DataSource, Prisma, PrismaService, SourceType } from '@lib/database'; import { Inject, Injectable, Logger } from '@nestjs/common'; -import { GlofasDataObject } from 'types/glofas-observation.type'; +import { GlofasDataObject, SourceInfo } from 'types/glofas-observation.type'; @Injectable() export class GlofasServices { @@ -62,18 +62,24 @@ export class GlofasServices { throw error; } } - async getDataSource() { + async getSourceData( + type: SourceType, + riverBasin: string, + ): Promise { try { - const sourceData = await this.prisma.setting.findFirst({ + const sourceData = await this.prisma.sourcesData.findMany({ where: { - name: 'DATASOURCE', + dataSource: DataSource.GLOFAS, + source: { + riverBasin, + }, + type, }, select: { - value: true, + info: true, }, }); - const glofas = (sourceData?.value as Record)['GLOFAS']; - return glofas; + return sourceData as SourceInfo[]; } catch (error: any) { this.logger.error('Error while fetching source data', error); throw error; diff --git a/packages/glofas-adapter/src/types/glofas-observation.type.ts b/packages/glofas-adapter/src/types/glofas-observation.type.ts index 92d7492..9f71530 100644 --- a/packages/glofas-adapter/src/types/glofas-observation.type.ts +++ b/packages/glofas-adapter/src/types/glofas-observation.type.ts @@ -1,3 +1,4 @@ +import { Prisma } from '@lib/database'; import axios from 'axios'; export interface GlofasObservation { @@ -63,3 +64,7 @@ export interface GlofasInfoObject { }; forecastDate: string; } + +export type SourceInfo = { + info: Prisma.JsonObject; +}; From 41a4a05c2993ab7241afd86053eea1e78d74c763 Mon Sep 17 00:00:00 2001 From: bipinparajuli Date: Wed, 10 Dec 2025 12:28:45 +0545 Subject: [PATCH 3/4] fix:moved mapping logging logic to service --- .../src/sources-data/sources-data.service.ts | 18 +++--------------- .../dhm-adapter/src/services/dhm.service.ts | 12 ++++++++++-- .../src/types/dhm-observation.type.ts | 5 +++++ packages/gfh-adapter/src/gfh.service.ts | 13 ++++++++++--- .../src/types/gfh-observation.type.ts | 4 ++-- packages/glofas-adapter/src/glofas.services.ts | 13 ++++++++++--- .../src/types/glofas-observation.type.ts | 4 ++-- 7 files changed, 42 insertions(+), 27 deletions(-) diff --git a/apps/triggers/src/sources-data/sources-data.service.ts b/apps/triggers/src/sources-data/sources-data.service.ts index 3200d09..2d02182 100644 --- a/apps/triggers/src/sources-data/sources-data.service.ts +++ b/apps/triggers/src/sources-data/sources-data.service.ts @@ -109,22 +109,14 @@ export class SourcesDataService { switch (dataSource) { case DataSource.DHM: { const dhm = await this.dhm.getSourceData(type, riverBasin); - return dhm.map((value) => ({ - seriesId: value.info['series_id'], - stationName: value.info['name'], - })); + return dhm; } - case DataSource.GLOFAS: { const glofas = await this.glofasServices.getSourceData( type || SourceType.WATER_LEVEL, riverBasin, ); - - return glofas.map((value) => ({ - seriesId: value.info['location'].basinId, - stationName: value.info['location'].basinId, - })); + return glofas; } case DataSource.GFH: { @@ -132,11 +124,7 @@ export class SourcesDataService { type || SourceType.WATER_LEVEL, riverBasin, ); - - return gfh.map((value) => ({ - seriesId: value.info['info'].riverGaugeId, - stationName: value.info['info'].stationName, - })); + return gfh; } default: return []; diff --git a/packages/dhm-adapter/src/services/dhm.service.ts b/packages/dhm-adapter/src/services/dhm.service.ts index 2ee8885..624a8cf 100644 --- a/packages/dhm-adapter/src/services/dhm.service.ts +++ b/packages/dhm-adapter/src/services/dhm.service.ts @@ -7,6 +7,7 @@ import { } from "@lib/database"; import { Inject, Injectable, Logger } from "@nestjs/common"; import { + DhmInfo, RainfallStationData, RiverStationData, } from "types/dhm-observation.type"; @@ -91,7 +92,7 @@ export class DhmService { async getSourceData( type: SourceType, riverBasin: string - ): Promise> { + ): Promise> { try { const sourceData = await this.prisma.sourcesData.findMany({ where: { @@ -105,7 +106,14 @@ export class DhmService { info: true, }, }); - return sourceData; + + return sourceData.map((value) => { + const info = value.info as DhmInfo; + return { + seriesId: info["series_id"], + stationName: info["name"], + }; + }); } catch (error: any) { this.logger.error("Error while fetching source data", error); throw error; diff --git a/packages/dhm-adapter/src/types/dhm-observation.type.ts b/packages/dhm-adapter/src/types/dhm-observation.type.ts index 2ce8e0f..4f62e72 100644 --- a/packages/dhm-adapter/src/types/dhm-observation.type.ts +++ b/packages/dhm-adapter/src/types/dhm-observation.type.ts @@ -125,3 +125,8 @@ export interface DhmStationResponse { rainfall_watch: RainfallStationItem[]; river_watch: RiverStationItem[]; } + +export type DhmInfo = { + series_id: string; + name: string; +}; diff --git a/packages/gfh-adapter/src/gfh.service.ts b/packages/gfh-adapter/src/gfh.service.ts index 373d3e2..fef5498 100644 --- a/packages/gfh-adapter/src/gfh.service.ts +++ b/packages/gfh-adapter/src/gfh.service.ts @@ -1,6 +1,6 @@ import { DataSource, Prisma, PrismaService, SourceType } from "@lib/database"; import { Inject, Injectable, Logger } from "@nestjs/common"; -import { SourceInfo } from "types"; +import { GfhInfo } from "types"; @Injectable() export class GfhService { @@ -83,7 +83,7 @@ export class GfhService { async getSourceData( type: SourceType, riverBasin: string - ): Promise { + ): Promise> { try { const sourceData = await this.prisma.sourcesData.findMany({ where: { @@ -97,7 +97,14 @@ export class GfhService { info: true, }, }); - return sourceData as SourceInfo[]; + + return sourceData.map((value) => { + const info = value.info as GfhInfo; + return { + seriesId: info["info"].riverGaugeId, + stationName: info["info"].stationName, + }; + }); } catch (error: any) { this.logger.error("Error while fetching source data", error); throw error; diff --git a/packages/gfh-adapter/src/types/gfh-observation.type.ts b/packages/gfh-adapter/src/types/gfh-observation.type.ts index db5630c..0c75e0d 100644 --- a/packages/gfh-adapter/src/types/gfh-observation.type.ts +++ b/packages/gfh-adapter/src/types/gfh-observation.type.ts @@ -153,6 +153,6 @@ export interface GfhTransformedResult { history: GfhHistoryItem[]; } -export type SourceInfo = { - info: Prisma.JsonObject; +export type GfhInfo = { + info: { riverGaugeId: string; stationName: string }; }; diff --git a/packages/glofas-adapter/src/glofas.services.ts b/packages/glofas-adapter/src/glofas.services.ts index 796d4e3..222e578 100644 --- a/packages/glofas-adapter/src/glofas.services.ts +++ b/packages/glofas-adapter/src/glofas.services.ts @@ -1,6 +1,6 @@ import { DataSource, Prisma, PrismaService, SourceType } from '@lib/database'; import { Inject, Injectable, Logger } from '@nestjs/common'; -import { GlofasDataObject, SourceInfo } from 'types/glofas-observation.type'; +import { GfofasInfo, GlofasDataObject } from 'types/glofas-observation.type'; @Injectable() export class GlofasServices { @@ -65,7 +65,7 @@ export class GlofasServices { async getSourceData( type: SourceType, riverBasin: string, - ): Promise { + ): Promise> { try { const sourceData = await this.prisma.sourcesData.findMany({ where: { @@ -79,7 +79,14 @@ export class GlofasServices { info: true, }, }); - return sourceData as SourceInfo[]; + + return sourceData.map((value) => { + const info = value.info as GfofasInfo; + return { + seriesId: info['location'].basinId, + stationName: info['location'].basinId, + }; + }); } catch (error: any) { this.logger.error('Error while fetching source data', error); throw error; diff --git a/packages/glofas-adapter/src/types/glofas-observation.type.ts b/packages/glofas-adapter/src/types/glofas-observation.type.ts index 9f71530..5109939 100644 --- a/packages/glofas-adapter/src/types/glofas-observation.type.ts +++ b/packages/glofas-adapter/src/types/glofas-observation.type.ts @@ -65,6 +65,6 @@ export interface GlofasInfoObject { forecastDate: string; } -export type SourceInfo = { - info: Prisma.JsonObject; +export type GfofasInfo = { + location: { basinId: string }; }; From 1d2c5d854364dfd642bfb61775a02a09c97e0e14 Mon Sep 17 00:00:00 2001 From: bipinparajuli Date: Thu, 11 Dec 2025 12:55:31 +0545 Subject: [PATCH 4/4] fix:added station name --- apps/triggers/src/sources-data/dto/get-series.ts | 13 +++++++++++++ .../src/sources-data/sources-data.service.ts | 3 ++- .../src/trigger/validation/trigger.schema.ts | 2 +- packages/gfh-adapter/src/gfh.service.ts | 9 ++++++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/apps/triggers/src/sources-data/dto/get-series.ts b/apps/triggers/src/sources-data/dto/get-series.ts index 2415f8d..3756d2d 100644 --- a/apps/triggers/src/sources-data/dto/get-series.ts +++ b/apps/triggers/src/sources-data/dto/get-series.ts @@ -16,4 +16,17 @@ export class GetSeriesDto { @IsEnum(DataSource) @IsString() dataSource: DataSource; + + @ApiProperty({ + example: 'karnali', + }) + @IsString() + riverBasin: string; + + @ApiProperty({ + example: 'karnali', + }) + @IsOptional() + @IsString() + stationName?: string; } diff --git a/apps/triggers/src/sources-data/sources-data.service.ts b/apps/triggers/src/sources-data/sources-data.service.ts index 2d02182..177f369 100644 --- a/apps/triggers/src/sources-data/sources-data.service.ts +++ b/apps/triggers/src/sources-data/sources-data.service.ts @@ -104,7 +104,7 @@ export class SourcesDataService { async findSeriesByDataSource(payload: GetSeriesDto) { try { - const { dataSource, type, riverBasin } = payload; + const { dataSource, type, riverBasin, stationName } = payload; switch (dataSource) { case DataSource.DHM: { @@ -123,6 +123,7 @@ export class SourcesDataService { const gfh = await this.gfhServices.getSourceData( type || SourceType.WATER_LEVEL, riverBasin, + stationName, ); return gfh; } diff --git a/apps/triggers/src/trigger/validation/trigger.schema.ts b/apps/triggers/src/trigger/validation/trigger.schema.ts index b6ed788..6177dc3 100644 --- a/apps/triggers/src/trigger/validation/trigger.schema.ts +++ b/apps/triggers/src/trigger/validation/trigger.schema.ts @@ -117,7 +117,7 @@ export const triggerPayloadSchema = z.object({ .transform((val) => (val === null ? undefined : val)), notes: z.string().trim().max(500).optional().default(''), title: z.string().trim().min(3).max(120), - description: z.string().trim().min(3).max(500), + description: z.string().optional(), isMandatory: z.boolean().optional().default(false), isTriggered: z.boolean().optional().default(false), isDeleted: z.boolean().optional().default(false), diff --git a/packages/gfh-adapter/src/gfh.service.ts b/packages/gfh-adapter/src/gfh.service.ts index fef5498..4193b1a 100644 --- a/packages/gfh-adapter/src/gfh.service.ts +++ b/packages/gfh-adapter/src/gfh.service.ts @@ -82,7 +82,8 @@ export class GfhService { } async getSourceData( type: SourceType, - riverBasin: string + riverBasin: string, + stationName?: string ): Promise> { try { const sourceData = await this.prisma.sourcesData.findMany({ @@ -92,6 +93,12 @@ export class GfhService { riverBasin, }, type, + ...(stationName && { + info: { + path: ["stationName"], + equals: stationName, + }, + }), }, select: { info: true,