Skip to content

Commit

Permalink
Merge pull request #27 from NewcastleRSE/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
markdturner authored Nov 13, 2023
2 parents 434f013 + 288e14a commit 1ebf836
Show file tree
Hide file tree
Showing 16 changed files with 4,596 additions and 2,884 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"dependencies": {
"@hubspot/api-client": "^9.0.0",
"@pdf-lib/fontkit": "^1.1.1",
"@strapi/plugin-documentation": "^4.12.0",
"@strapi/plugin-i18n": "^4.12.0",
"@strapi/plugin-sentry": "^4.12.0",
"@strapi/plugin-users-permissions": "^4.12.0",
"@strapi/strapi": "^4.12.0",
"@strapi/plugin-documentation": "^4.13.7",
"@strapi/plugin-i18n": "^4.13.7",
"@strapi/plugin-sentry": "^4.13.7",
"@strapi/plugin-users-permissions": "^4.13.7",
"@strapi/strapi": "^4.13.7",
"axios": "1.4.0",
"camelcase": "5.2.0",
"camelcase-keys": "5.2.0",
Expand All @@ -35,7 +35,7 @@
"uuid": "ca6b733a-92c2-453b-9dbb-89dbf373fb2d"
},
"engines": {
"node": ">=12.x.x <=16.x.x",
"node": ">=16.x.x <=18.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
Expand Down
4 changes: 4 additions & 0 deletions src/api/facility/content-types/facility/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
"min": 0,
"max": 1,
"required": true
},
"incomeTarget": {
"type": "integer",
"required": true
}
}
}
3 changes: 0 additions & 3 deletions src/api/invoice/content-types/invoice/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
"sent": {
"type": "date"
},
"paid": {
"type": "date"
},
"transaction": {
"type": "relation",
"relation": "oneToOne",
Expand Down
11 changes: 8 additions & 3 deletions src/api/invoice/services/invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::invoice.invoice', ({ strapi }) => ({
async create(params) {

const period = {
year: params.data.year,
month: params.data.month
}

const project = await strapi.service("api::project.project").findOne(params.data.project)
const timesheets = await strapi.service("api::timesheet.timesheet").findProject(project.clockifyID, params.data.month)
const timesheets = await strapi.service("api::timesheet.timesheet").findProject(project.clockifyID, period)

const documentNumber = `${project.hubspotId}-${params.data.month.toUpperCase()}-${params.data.year}`

// Convert seconds to hours, then 7.4 hours per day
const days = Math.round((timesheets.data.total / 3600) / 7.4)
// Convert seconds to hours, then 7.24 hours per day
const days = Math.round((timesheets.data.total / 3600) / 7.24)

const invoices = await strapi.entityService.findMany('api::invoice.invoice', {
filters: {
Expand Down
25 changes: 1 addition & 24 deletions src/api/project/services/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,28 +632,5 @@ module.exports = createCoreService("api::project.project", ({ strapi }) => ({
console.error(err);
return null;
});
},

async update(...args) {
// add error handling
const id = args.id;
const status = args.status;

// add check if status is equal to Red, Amber or Green
const prj = {
id: id,
properties: {
status: status,
},
};

await hubspotClient.crm.deals.batchApi
.update({ inputs: [prj] })
.then((results) => {
return { results };
})
.catch((err) => {
console.log(err);
});
},
}
}));
4 changes: 4 additions & 0 deletions src/api/rse/content-types/rse/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
},
"github": {
"type": "string"
},
"username": {
"type": "string",
"required": true
}
}
}
8 changes: 8 additions & 0 deletions src/api/timesheet/controllers/timesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ module.exports = {
console.error(err);
}
},
leave: async (ctx, next) => {
try {
ctx.body = await service.findLeave();
} catch (err) {
ctx.body = err;
console.error(err);
}
},
user: async (ctx, next) => {
try {
let period = ctx.request.headers["period"];
Expand Down
11 changes: 10 additions & 1 deletion src/api/timesheet/routes/timesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ module.exports = {
middlewares: [],
},
},
{
method: "GET",
path: "/timesheets/leave",
handler: "timesheet.leave",
config: {
policies: [],
middlewares: [],
},
},
{
method: "GET",
path: "/timesheets/allocated",
Expand Down Expand Up @@ -45,6 +54,6 @@ module.exports = {
policies: [],
middlewares: [],
},
},
}
],
};
94 changes: 69 additions & 25 deletions src/api/timesheet/services/timesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ const reportConfig = {
},
};

const leaveConfig = {
baseURL: 'https://sageapps.ncl.ac.uk/public/',
headers: {
Authorization: `Bearer ${process.env.LEAVE_API_TOKEN}`
}
}

const getTotalAllocatedDays = (data) => {
return data;
};
Expand Down Expand Up @@ -371,39 +378,64 @@ module.exports = {
}
},

// Can look through by userID and check if a user is working on two projects as much as the other.
// Creates and returns a report for a specified user in the workspace.
async findOne(userID) {

const currentDate = DateTime.utc()

let startDate = DateTime.utc(currentDate.year, 8),
endDate = startDate.plus({ year: 1 })

if(currentDate.month < 8) {
startDate = startDate.minus({ year: 1 }),
endDate = endDate.minus({ year: 1 })
}

const payload = {
// Generates a report from the last 30 days.
dateRangeStart: DateTime.utc().startOf("day").minus({ days: 30 }).toISO(),
dateRangeEnd: DateTime.utc().endOf("day").toISO(),
dateRangeStart: startDate.toISO(),
dateRangeEnd: endDate.toISO(),
detailedFilter: {
page: 1,
pageSize: 100,
pageSize: 1000,
},
users: {
ids: [userID],
contains: "CONTAINS",
status: "ALL",
},
};
}

try {
const response = await axios.post(`/detailed`, payload, reportConfig);
const response = await axios.post(`/detailed`, payload, reportConfig)

const data = {
totals: response.data.totals,
dates: {}
}

response.data.timeentries.forEach(entry => {

const key = DateTime.fromISO(entry.timeInterval.start).toISODate()

if(!(key in data.dates)) {
data.dates[key] = []
}

data.dates[key].push(entry)
})

return {
data: response.data,
data: data,
meta: {
pagination: {
page: 1,
pageSize: 100,
pageSize: 1000,
pageCount: 1,
total: response.data.timeentries.length,
},
},
};
}
} catch (error) {
console.error(error);
console.error(error)
}
},

Expand All @@ -425,15 +457,13 @@ module.exports = {
// Will return a list of all users that have worked on a project as specified by the project id passed in. Will show their time spent in hours, minutes and seconds
async findProject(id, period) {

const dateRange = getDateRanges(period)

let dateRangeStart = dateRange.dateRangeStart;
let dateRangeEnd = dateRange.dateRangeEnd;
console.log(period)
const date = DateTime.fromFormat(`${period.month} ${period.year}`, 'LLLL yyyy')

// This time range gets the entire fiscal annum
const payload = {
dateRangeStart: dateRangeStart,
dateRangeEnd: dateRangeEnd,
dateRangeStart: date.startOf('month').toISO({ includeOffset: false }) + 'Z',
dateRangeEnd: date.endOf('month').toISO({ includeOffset: false }) + 'Z',
// This will filter by User, then by their projects, then by each task in each project. Clockify will show time spent by each user, time spent on each project and time spent on each task in each project. A task in a project could be a meeting or a task.
projects: {
contains: "CONTAINS",
Expand All @@ -442,10 +472,12 @@ module.exports = {
summaryFilter: {
groups: ["USER"],
},
};
}

let response = null

try {
const response = await axios.post(`/summary`, payload, reportConfig);
response = await axios.post(`/summary`, payload, reportConfig);

const rses = []

Expand All @@ -457,16 +489,18 @@ module.exports = {
})
})

const totals = response.data.totals[0] ? response.data.totals[0] : { totalTime: 0, totalBillableTime: 0}

return {
data: {
total: response.data.totals[0].totalTime,
totalBillable: response.data.totals[0].totalBillableTime,
total: totals.totalTime,
totalBillable: totals.totalBillableTime,
rses: rses
},
meta: {
period: {
start: dateRangeStart.slice(0, dateRangeStart.indexOf("T")),
end: dateRangeEnd.slice(0, dateRangeStart.indexOf("T")),
start: date.startOf('month').toISO({ includeOffset: false }) + 'Z',
end: date.endOf('month').toISO({ includeOffset: false }) + 'Z',
entriesCount: response.data.totals[0].entriesCount
},
pagination: {
Expand All @@ -478,7 +512,7 @@ module.exports = {
},
};
} catch (error) {
console.error(error);
console.error(error)
}
},

Expand Down Expand Up @@ -529,6 +563,16 @@ module.exports = {
}
},

async findLeave() {
try {
let response = await axios.get(`/turner`, leaveConfig)
return { data: response.data }
}
catch(ex) {
console.error(ex)
}
},

async findAllocatedTime(period) {
let dateRangeStart = getDateRanges(period).dateRangeStart;
let dateRangeEnd = getDateRanges(period).dateRangeEnd;
Expand Down
3 changes: 3 additions & 0 deletions src/api/transaction/content-types/transaction/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
"fiscalPeriod": {
"type": "integer",
"required": true
},
"internalCategory": {
"type": "string"
}
}
}
Loading

0 comments on commit 1ebf836

Please sign in to comment.