Skip to content

Commit

Permalink
🐛 fixed a bug in the Siwapp interface after async migration
Browse files Browse the repository at this point in the history
  • Loading branch information
faburem authored Aug 1, 2024
1 parent c8ccf40 commit 0dbb6a4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 3 additions & 3 deletions imports/api/timecards/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Tasks from '../../tasks/tasks.js'
import Projects from '../../projects/projects.js'
import { t } from '../../../utils/i18n.js'
import { emojify } from '../../../utils/frontend_helpers'
import { timeInUserUnit } from '../../../utils/periodHelpers.js'
import { timeInUserUnitAsync } from '../../../utils/periodHelpers.js'
import {
authenticationMixin,
transactionLogMixin,
Expand Down Expand Up @@ -441,11 +441,11 @@ const sendToSiwapp = new ValidatedMethod({
for await (const [project, resources] of projectMap.entries()) {
const projectElement = await Projects.findOneAsync({ _id: project })
if (resources.size > 0) {
for (const [resource, hours] of resources) {
for (const [resource, hours] of resourcses) {
invoiceJSON.data.relationships.items.data.push({
attributes: {
description: `${projectElement.name} (${resource})`,
quantity: timeInUserUnit(hours, meteorUser),
quantity: await timeInUserUnitAsync(hours, meteorUser),
unitary_cost: 0,
},
})
Expand Down
20 changes: 18 additions & 2 deletions imports/utils/periodHelpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import isoWeek from 'dayjs/plugin/isoWeek'
import { getGlobalSetting, getUserSetting } from './frontend_helpers'
import { getGlobalSetting, getGlobalSettingAsync, getUserSetting } from './frontend_helpers'
import { getUserSettingAsync } from './server_method_helpers'

async function periodToDates(period) {
Expand Down Expand Up @@ -66,4 +66,20 @@ function timeInUserUnit(time, meteorUser) {
}
return Number(time).toFixed(precision)
}
export { periodToDates, timeInUserUnit }
async function timeInUserUnitAsync(time, meteorUser) {
const precision = meteorUser?.profile?.precision ? meteorUser.profile.precision : await getGlobalSettingAsync('precision')
if (meteorUser?.profile?.timeunit === 'd') {
let hoursToDays = await getGlobalSettingAsync('hoursToDays')
if (meteorUser?.profile?.hoursToDays) {
hoursToDays = meteorUser.profile.hoursToDays
}
const convertedTime = Number(time / hoursToDays).toFixed(precision)
return convertedTime !== Number(0).toFixed(precision) ? convertedTime : undefined
}
if (meteorUser?.profile?.timeunit === 'm') {
const convertedTime = Number(time * 60).toFixed(precision)
return convertedTime !== Number(0).toFixed(precision) ? convertedTime : undefined
}
return Number(time).toFixed(precision)
}
export { periodToDates, timeInUserUnit, timeInUserUnitAsyncs }
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "titra",
"version": "0.99.4",
"version": "0.99.5",
"private": true,
"scripts": {
"start": "meteor run"
Expand Down

0 comments on commit 0dbb6a4

Please sign in to comment.