Skip to content

Commit 73c1efc

Browse files
committed
fix: WP update endpoint fixes
1 parent 2d2a3b8 commit 73c1efc

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/services/WorkPeriodPaymentService.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ async function updateWorkPeriodPayment (currentUser, id, data) {
203203

204204
const workPeriodPayment = await WorkPeriodPayment.findById(id)
205205
const oldValue = workPeriodPayment.toJSON()
206-
if (oldValue.status === data.status) {
207-
return oldValue
208-
}
209206
if (data.status === 'cancelled' && oldValue.status === 'in-progress') {
210207
throw new errors.BadRequestError('You cannot cancel a WorkPeriodPayment which is in-progress')
211208
}

src/services/WorkPeriodService.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ async function updateWorkPeriod (currentUser, id, data) {
261261

262262
const workPeriod = await WorkPeriod.findById(id, { withPayments: true })
263263
const oldValue = workPeriod.toJSON()
264-
if (oldValue.daysWorked === data.daysWorked) {
265-
return oldValue
266-
}
267264
if (data.daysWorked < oldValue.daysPaid) {
268265
throw new errors.BadRequestError(`Cannot update daysWorked (${data.daysWorked}) to the value less than daysPaid (${oldValue.daysPaid})`)
269266
}
@@ -282,8 +279,10 @@ async function updateWorkPeriod (currentUser, id, data) {
282279
data.paymentStatus = helper.calculateWorkPeriodPaymentStatus(_.assign({}, oldValue, data))
283280
data.updatedBy = await helper.getUserId(currentUser.userId)
284281
const updated = await workPeriod.update(data)
285-
await helper.postEvent(config.TAAS_WORK_PERIOD_UPDATE_TOPIC, updated.toJSON(), { oldValue: oldValue, key: `resourceBooking.id:${updated.resourceBookingId}` })
286-
return updated.dataValues
282+
const updatedDataWithoutPayments = _.omit(updated.toJSON(), ['payments'])
283+
const oldValueWithoutPayments = _.omit(oldValue, ['payments'])
284+
await helper.postEvent(config.TAAS_WORK_PERIOD_UPDATE_TOPIC, updatedDataWithoutPayments, { oldValue: oldValueWithoutPayments, key: `resourceBooking.id:${updated.resourceBookingId}` })
285+
return updatedDataWithoutPayments
287286
}
288287

289288
/**

0 commit comments

Comments
 (0)