Skip to content

Commit

Permalink
Merge pull request #40 from NewcastleRSE/dev
Browse files Browse the repository at this point in the history
add project burn down data to response
  • Loading branch information
markdturner authored Oct 20, 2024
2 parents 0a13e3d + 4c094d4 commit 682557a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
46 changes: 45 additions & 1 deletion src/api/project/services/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
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 }
}
}))
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 682557a

Please sign in to comment.