diff --git a/routes/index.ts b/routes/index.ts index 719c2c2..f1d052e 100644 --- a/routes/index.ts +++ b/routes/index.ts @@ -16,8 +16,8 @@ indexRouter.get('/', async (request: Request, response: Response) => { if ( request.query.limit - && Number(request.query.limit) >= 10 - && Number(request.query.limit) <= 500 + && Number(request.query.limit) >= 10 + && Number(request.query.limit) <= 500 ) { responseData = responseData?.slice(0, Number(request.query.limit)); } else { diff --git a/types/kandilli.ts b/types/kandilli.ts index 593b8b9..6fae48a 100644 --- a/types/kandilli.ts +++ b/types/kandilli.ts @@ -1,4 +1,5 @@ export type Earthquake = { + id: string; tarih: string; saat: string; enlem: string; diff --git a/utilities/gen-id.ts b/utilities/gen-id.ts new file mode 100644 index 0000000..86b8726 --- /dev/null +++ b/utilities/gen-id.ts @@ -0,0 +1,7 @@ +export function genId(sehir: string, bolge: string, date: string): string { + return `${getPlaceShortName(sehir, bolge)}-${new Date(date).getTime()}`; +} + +function getPlaceShortName(sehir: string, bolge: string): string { + return sehir.slice(0, 2).concat(bolge.slice(0, 2)); +} diff --git a/utilities/kandilli.ts b/utilities/kandilli.ts index 3176543..0e5a3c1 100644 --- a/utilities/kandilli.ts +++ b/utilities/kandilli.ts @@ -1,10 +1,11 @@ import jsdom from 'jsdom'; import {type Earthquake} from '../types/kandilli.js'; +import {genId} from './gen-id.js'; const {JSDOM} = jsdom; const bolgeNameParser = (name: string) => { - name = name.replaceAll('-', ' '); + name = name.replaceAll('-', '/'); return name.trim(); }; @@ -33,6 +34,11 @@ const parseLine = (lineArray: string[]): Earthquake => { const [, bolge, sehir]: any = /^(.*?)(?:\((.*)\))?$/.exec(fullYer); const nitelik = lineArray.slice(121); const dataLine: Earthquake = { + id: genId( + String(sehir).trim().toLowerCase(), + String(bolge).trim().toLowerCase(), + `${combineString(tarih)} ${combineString(saat)}`, + ), tarih: combineString(tarih), saat: combineString(saat), enlem: combineString(enlem),