@@ -49,10 +49,10 @@ async function _createSingleWorkPeriodPayment (workPeriodPayment, createdBy) {
49
49
}
50
50
51
51
/**
52
- * Create single workPeriodPayment
53
- * @param {Object } workPeriodPayment the workPeriodPayment to be created
54
- * @param {String } createdBy the authUser id
55
- * @returns {Object } the created workPeriodPayment
52
+ * update challenge
53
+ * @param {String } challengeId the challenge id
54
+ * @param {Object } data the challenge update data
55
+ * @returns {undefined }
56
56
*/
57
57
async function _updateChallenge ( challengeId , data ) {
58
58
const body = { }
@@ -243,9 +243,10 @@ async function updateWorkPeriodPayment (currentUser, id, data) {
243
243
const oldValue = workPeriodPayment . toJSON ( )
244
244
245
245
if ( oldValue . status === 'in-progress' ) {
246
- _ . each ( _ . pick ( data , [ 'amount' , 'days' , 'memberRate' , 'customerRate' , 'billingAccountId' ] ) , ( value , key ) => {
247
- throw new errors . BadRequestError ( `${ key } cannot be updated when workPeriodPayment status is in-progress` )
248
- } )
246
+ const keys = _ . keys ( _ . pick ( data , [ 'amount' , 'days' , 'memberRate' , 'customerRate' , 'billingAccountId' ] ) )
247
+ if ( keys . length ) {
248
+ throw new errors . BadRequestError ( `${ JSON . stringify ( keys ) } cannot be updated when workPeriodPayment status is in-progress` )
249
+ }
249
250
}
250
251
251
252
if ( data . status === 'cancelled' && oldValue . status === 'in-progress' ) {
@@ -265,13 +266,14 @@ async function updateWorkPeriodPayment (currentUser, id, data) {
265
266
266
267
if ( data . days ) {
267
268
const correspondingWorkPeriod = await helper . ensureWorkPeriodById ( workPeriodPayment . workPeriodId ) // ensure work period exists
268
- const maxPossibleDays = correspondingWorkPeriod . daysWorked - correspondingWorkPeriod . daysPaid
269
+ const maxPossibleDays = correspondingWorkPeriod . daysWorked - correspondingWorkPeriod . daysPaid - oldValue . days
269
270
if ( data . days > maxPossibleDays ) {
270
271
throw new errors . BadRequestError ( `Days cannot be more than not paid days which is ${ maxPossibleDays } ` )
271
272
}
272
273
}
273
274
274
- if ( oldValue . challengeId ) {
275
+ // challengeId exist and skip dummy challenge
276
+ if ( oldValue . challengeId && oldValue . challengeId !== '00000000-0000-0000-0000-000000000000' ) {
275
277
await _updateChallenge ( workPeriodPayment . challengeId , data )
276
278
}
277
279
@@ -299,9 +301,9 @@ partiallyUpdateWorkPeriodPayment.schema = Joi.object().keys({
299
301
status : Joi . workPeriodPaymentUpdateStatus ( ) ,
300
302
amount : Joi . number ( ) . min ( 0 ) ,
301
303
days : Joi . number ( ) . integer ( ) ,
302
- memberRate : Joi . number ( ) . positive ( ) . required ( ) ,
304
+ memberRate : Joi . number ( ) . positive ( ) ,
303
305
customerRate : Joi . number ( ) . positive ( ) . allow ( null ) ,
304
- billingAccountId : Joi . number ( ) . positive ( ) . integer ( ) . required ( )
306
+ billingAccountId : Joi . number ( ) . positive ( ) . integer ( )
305
307
} ) . min ( 1 ) . required ( )
306
308
} ) . required ( )
307
309
0 commit comments