(collection, latestStatusData, newState)
| 313 | * @throws {Error} If there is an error while updating the status |
| 314 | */ |
| 315 | const updateFutureStatusToState = async (collection, latestStatusData, newState) => { |
| 316 | const { |
| 317 | id, |
| 318 | data: { futureStatus, ...docData }, |
| 319 | } = latestStatusData; |
| 320 | const { |
| 321 | currentStatus: { state, until }, |
| 322 | } = docData; |
| 323 | const currentTimeStamp = new Date().getTime(); |
| 324 | const updatedStatusData = { |
| 325 | ...docData, |
| 326 | futureStatus: { |
| 327 | state: newState, |
| 328 | message: "", |
| 329 | from: until, |
| 330 | until: "", |
| 331 | updatedAt: currentTimeStamp, |
| 332 | }, |
| 333 | }; |
| 334 | try { |
| 335 | await collection.doc(id).update(updatedStatusData); |
| 336 | } catch (err) { |
| 337 | logger.error(`error updating the future status for user id ${docData.userId} - ${err.message}`); |
| 338 | throw new Error(`error updating the future status.`); |
| 339 | } |
| 340 | return { |
| 341 | status: "success", |
| 342 | message: `As the user is currently ${state}, the future status has been updated to ${newState}.`, |
| 343 | data: { |
| 344 | currentStatus: state, |
| 345 | futureStatus: newState, |
| 346 | }, |
| 347 | }; |
| 348 | }; |
| 349 | |
| 350 | /** |
| 351 | * Returns the Response for the New User Status Creation Document |
no outgoing calls
no test coverage detected