mirror of
https://github.com/ershisan99/vacancies-trends-front.git
synced 2025-12-16 12:34:06 +00:00
24 lines
686 B
TypeScript
24 lines
686 B
TypeScript
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()
|