mirror of
https://github.com/ershisan99/vacancies-trends-front.git
synced 2025-12-16 12:34:06 +00:00
initial commit
This commit is contained in:
23
app/services/vacancies/vacancies.service.ts
Normal file
23
app/services/vacancies/vacancies.service.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Vacancies, VacancyData } from '~/services/vacancies/vacancies.types'
|
||||
|
||||
export class VacanciesService {
|
||||
async getAll(): Promise<Vacancies> {
|
||||
return await fetch('http://localhost:4321/vacancies').then(res => res.json())
|
||||
}
|
||||
async getAggregateByCreatedAt(): Promise<VacancyData> {
|
||||
return await fetch('http://localhost:4321/vacancies/aggregated')
|
||||
.then(res => res.json())
|
||||
.then(this.formatDateOnData)
|
||||
}
|
||||
|
||||
formatDateOnData(data: VacancyData): VacancyData {
|
||||
return data.map(item => {
|
||||
return {
|
||||
...item,
|
||||
date: new Date(item.date).toLocaleTimeString('ru'),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const vacanciesService = new VacanciesService()
|
||||
Reference in New Issue
Block a user