redmine-time-manager/src/logic/open.ts
2023-11-09 12:45:39 +07:00

21 lines
773 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {config} from "./config";
import axios from "axios";
type TimeEntry = Record<string, any>;
type TimeEntriesResponse = {time_entries: TimeEntry[]};
export async function loadEntries(date: string): Promise<TimeEntry[]> {
const url = `${config.redmine.url}/time_entries.json`;
const params = {
user_id: config.redmine.user_id,
from: date,
to: date
};
const resp = await axios.get<TimeEntriesResponse>(url, {params: params});
if (!resp || resp.status !== 200 || !resp.data || !resp.data.time_entries) {
throw new Error('Не удалось загрузить записи за дату');
}
return resp.data.time_entries.filter((entry) => {
return entry.user.id === config.redmine.user_id;
});
}