Skip to content

Commit 1d0a7ce

Browse files
committed
[feat] id prop
1 parent 4535837 commit 1d0a7ce

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

routes/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ indexRouter.get('/', async (request: Request, response: Response) => {
1616

1717
if (
1818
request.query.limit
19-
&& Number(request.query.limit) >= 10
20-
&& Number(request.query.limit) <= 500
19+
&& Number(request.query.limit) >= 10
20+
&& Number(request.query.limit) <= 500
2121
) {
2222
responseData = responseData?.slice(0, Number(request.query.limit));
2323
} else {

types/kandilli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export type Earthquake = {
2+
id: string;
23
tarih: string;
34
saat: string;
45
enlem: string;

utilities/gen-id.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function genId(sehir: string, bolge: string, date: string): string {
2+
return `${getPlaceShortName(sehir, bolge)}-${new Date(date).getTime()}`;
3+
}
4+
5+
function getPlaceShortName(sehir: string, bolge: string): string {
6+
return sehir.slice(0, 2).concat(bolge.slice(0, 2));
7+
}

utilities/kandilli.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import jsdom from 'jsdom';
22
import {type Earthquake} from '../types/kandilli.js';
3+
import {genId} from './gen-id.js';
34

45
const {JSDOM} = jsdom;
56

67
const bolgeNameParser = (name: string) => {
7-
name = name.replaceAll('-', ' ');
8+
name = name.replaceAll('-', '/');
89
return name.trim();
910
};
1011

@@ -33,6 +34,11 @@ const parseLine = (lineArray: string[]): Earthquake => {
3334
const [, bolge, sehir]: any = /^(.*?)(?:\((.*)\))?$/.exec(fullYer);
3435
const nitelik = lineArray.slice(121);
3536
const dataLine: Earthquake = {
37+
id: genId(
38+
String(sehir).trim().toLowerCase(),
39+
String(bolge).trim().toLowerCase(),
40+
`${combineString(tarih)} ${combineString(saat)}`,
41+
),
3642
tarih: combineString(tarih),
3743
saat: combineString(saat),
3844
enlem: combineString(enlem),

0 commit comments

Comments
 (0)