@hongkongkiwi/clockify-master-mcp
Version:
Clockify Master MCP - The most comprehensive Model Context Protocol server for Clockify time tracking with full API integration, advanced filtering, and enterprise features
88 lines • 3.78 kB
JavaScript
export class TimeEntryService {
client;
constructor(client) {
this.client = client;
}
async createTimeEntry(workspaceId, data) {
return this.client.post(`/workspaces/${workspaceId}/time-entries`, data);
}
async getTimeEntriesForUser(workspaceId, userId, options) {
return this.client.get(`/workspaces/${workspaceId}/user/${userId}/time-entries`, options);
}
async getTimeEntryById(workspaceId, timeEntryId, options) {
return this.client.get(`/workspaces/${workspaceId}/time-entries/${timeEntryId}`, options);
}
async updateTimeEntry(workspaceId, timeEntryId, data) {
return this.client.put(`/workspaces/${workspaceId}/time-entries/${timeEntryId}`, data);
}
async deleteTimeEntry(workspaceId, timeEntryId) {
return this.client.delete(`/workspaces/${workspaceId}/time-entries/${timeEntryId}`);
}
async stopRunningTimer(workspaceId, userId, data) {
return this.client.patch(`/workspaces/${workspaceId}/user/${userId}/time-entries`, data);
}
async getRunningTimeEntry(workspaceId, userId) {
const entries = await this.getTimeEntriesForUser(workspaceId, userId, {
'page-size': 1,
});
if (entries.length > 0 && !entries[0].timeInterval.end) {
return entries[0];
}
return null;
}
async bulkEditTimeEntries(workspaceId, timeEntryIds, data) {
return this.client.patch(`/workspaces/${workspaceId}/time-entries/bulk`, {
timeEntryIds,
...data,
});
}
async bulkDeleteTimeEntries(workspaceId, timeEntryIds) {
return this.client.post(`/workspaces/${workspaceId}/time-entries/delete`, {
timeEntryIds,
});
}
async duplicateTimeEntry(workspaceId, timeEntryId) {
const original = await this.getTimeEntryById(workspaceId, timeEntryId);
const now = new Date();
return this.createTimeEntry(workspaceId, {
start: now.toISOString(),
description: original.description,
projectId: original.projectId,
taskId: original.taskId,
tagIds: original.tagIds,
billable: original.billable,
});
}
async getTimeEntriesInRange(workspaceId, userId, startDate, endDate) {
return this.getTimeEntriesForUser(workspaceId, userId, {
start: startDate.toISOString(),
end: endDate.toISOString(),
});
}
async getTodayTimeEntries(workspaceId, userId) {
const today = new Date();
today.setHours(0, 0, 0, 0);
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
return this.getTimeEntriesInRange(workspaceId, userId, today, tomorrow);
}
async getWeekTimeEntries(workspaceId, userId) {
const today = new Date();
const dayOfWeek = today.getDay();
const startOfWeek = new Date(today);
startOfWeek.setDate(today.getDate() - dayOfWeek);
startOfWeek.setHours(0, 0, 0, 0);
const endOfWeek = new Date(startOfWeek);
endOfWeek.setDate(startOfWeek.getDate() + 7);
return this.getTimeEntriesInRange(workspaceId, userId, startOfWeek, endOfWeek);
}
async getMonthTimeEntries(workspaceId, userId, year, month) {
const now = new Date();
const targetYear = year || now.getFullYear();
const targetMonth = month !== undefined ? month : now.getMonth();
const startOfMonth = new Date(targetYear, targetMonth, 1);
const endOfMonth = new Date(targetYear, targetMonth + 1, 0, 23, 59, 59, 999);
return this.getTimeEntriesInRange(workspaceId, userId, startOfMonth, endOfMonth);
}
}
//# sourceMappingURL=timeEntry.service.js.map