diff --git a/src/api/project/services/project.js b/src/api/project/services/project.js index f1fd972..b5df24f 100644 --- a/src/api/project/services/project.js +++ b/src/api/project/services/project.js @@ -5,5 +5,49 @@ */ const { createCoreService } = require('@strapi/strapi').factories; +const { setupCache } = require('axios-cache-interceptor') +let axios = require('axios') -module.exports = createCoreService('api::project.project'); \ No newline at end of file +const instance = axios.create() +axios = setupCache(instance, { + methods: ['get'] +}) + +const clockifyConfig = { + baseURL: `https://api.clockify.me/api/v1/workspaces/${process.env.CLOCKIFY_WORKSPACE}`, + headers: { + 'X-Api-Key': process.env.CLOCKIFY_KEY, + }, + cache: { + maxAge: 60 * 60 * 1000 + } +} + +module.exports = createCoreService('api::project.project', ({ strapi }) => ({ + async find(...args) { + // Calling the default core service + const { results, pagination } = await super.find(...args) + + const clockifyIDs = results.map(p => p.clockifyID) + + // Calling Clockify + const response = await axios.get('/projects?hydrated=true&page-size=5000', clockifyConfig) + + // Filtering the clockify projects that are in the project list + const clockifyProjects = response.data.filter(p => clockifyIDs.includes(p.id)) + + // some custom logic + results.forEach(result => { + try { + const clockifyProject = clockifyProjects.find(p => p.id === result.clockifyID) + result.estimate = clockifyProject.estimate.estimate + result.spent = clockifyProject.duration + } + catch (e) { + console.log(result) + } + }) + + return { results, pagination } + } +})) \ No newline at end of file diff --git a/src/extensions/documentation/documentation/1.0.0/full_documentation.json b/src/extensions/documentation/documentation/1.0.0/full_documentation.json index 5dbbbc1..7f41ba9 100644 --- a/src/extensions/documentation/documentation/1.0.0/full_documentation.json +++ b/src/extensions/documentation/documentation/1.0.0/full_documentation.json @@ -14,7 +14,7 @@ "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, - "x-generation-date": "2024-10-08T20:36:17.037Z" + "x-generation-date": "2024-10-20T07:23:49.738Z" }, "x-strapi-config": { "path": "/documentation",