1- import { TAccount , TCreateTimeEntry , TIssue , TSearchResult , TTimeEntryActivity } from "../types/redmine" ;
1+ import { formatISO } from "date-fns" ;
2+ import { TAccount , TCreateTimeEntry , TIssue , TSearchResult , TTimeEntry , TTimeEntryActivity } from "../types/redmine" ;
23import instance from "./axios.config" ;
34
45export const getMyAccount = async ( ) : Promise < TAccount > => {
56 return instance . get ( "/my/account.json" ) . then ( ( res ) => res . data . user ) ;
67} ;
78
9+ // Issues
810export const getAllMyOpenIssues = async ( offset = 0 , limit = 100 ) : Promise < TIssue [ ] > => {
911 return instance . get ( `/issues.json?offset=${ offset } &limit=${ limit } &status_id=open&assigned_to_id=me&sort=updated_on:desc` ) . then ( ( res ) => res . data . issues ) ;
1012} ;
@@ -13,12 +15,8 @@ export const getOpenIssues = async (ids: number[], offset = 0, limit = 100): Pro
1315 return instance . get ( `/issues.json?offset=${ offset } &limit=${ limit } &status_id=open&issue_id=${ ids . join ( "," ) } &sort=updated_on:desc` ) . then ( ( res ) => res . data . issues ) ;
1416} ;
1517
16- export const createTimeEntry = async ( entry : TCreateTimeEntry ) => {
17- return instance
18- . post ( "/time_entries.json" , {
19- time_entry : entry ,
20- } )
21- . then ( ( res ) => res . data ) ;
18+ export const searchOpenIssues = async ( query : string ) : Promise < TSearchResult [ ] > => {
19+ return instance . get ( `/search.json?q=${ query } &scope=my_project&titles_only=1&issues=1&open_issues=1` ) . then ( ( res ) => res . data . results ) ;
2220} ;
2321
2422export const updateIssue = async ( id : number , issue : Partial < Omit < TIssue , "id" > > ) => {
@@ -29,10 +27,19 @@ export const updateIssue = async (id: number, issue: Partial<Omit<TIssue, "id">>
2927 . then ( ( res ) => res . data ) ;
3028} ;
3129
32- export const getTimeEntryActivities = async ( ) : Promise < TTimeEntryActivity [ ] > => {
33- return instance . get ( "/enumerations/time_entry_activities.json" ) . then ( ( res ) => res . data . time_entry_activities ) ;
30+ // Time entries
31+ export const getAllMyTimeEntries = async ( from : Date , to : Date , offset = 0 , limit = 100 ) : Promise < TTimeEntry [ ] > => {
32+ return instance . get ( `/time_entries.json?offset=${ offset } &limit=${ limit } &user_id=me&from=${ formatISO ( from , { representation : "date" } ) } &to=${ formatISO ( to , { representation : "date" } ) } ` ) . then ( ( res ) => res . data . time_entries ) ;
3433} ;
3534
36- export const searchOpenIssues = async ( query : string ) : Promise < TSearchResult [ ] > => {
37- return instance . get ( `/search.json?q=${ query } &scope=my_project&titles_only=1&issues=1&open_issues=1` ) . then ( ( res ) => res . data . results ) ;
35+ export const createTimeEntry = async ( entry : TCreateTimeEntry ) => {
36+ return instance
37+ . post ( "/time_entries.json" , {
38+ time_entry : entry ,
39+ } )
40+ . then ( ( res ) => res . data ) ;
41+ } ;
42+
43+ export const getTimeEntryActivities = async ( ) : Promise < TTimeEntryActivity [ ] > => {
44+ return instance . get ( "/enumerations/time_entry_activities.json" ) . then ( ( res ) => res . data . time_entry_activities ) ;
3845} ;
0 commit comments