Skip to content

Commit

Permalink
[feat] id prop
Browse files Browse the repository at this point in the history
  • Loading branch information
ibodev1 committed Dec 29, 2023
1 parent 4535837 commit 1d0a7ce
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions types/kandilli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type Earthquake = {
id: string;
tarih: string;
saat: string;
enlem: string;
Expand Down
7 changes: 7 additions & 0 deletions utilities/gen-id.ts
Original file line number Diff line number Diff line change
@@ -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));
}
8 changes: 7 additions & 1 deletion utilities/kandilli.ts
Original file line number Diff line number Diff line change
@@ -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();
};

Expand Down Expand Up @@ -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),
Expand Down

1 comment on commit 1d0a7ce

@vercel
Copy link

@vercel vercel bot commented on 1d0a7ce Dec 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kandilli-api – ./

kandilli-api-git-main-ibodev1.vercel.app
kandilli-api.vercel.app
kandilli-api-ibodev1.vercel.app

Please sign in to comment.