(userId, collection, state)
| 361 | */ |
| 362 | |
| 363 | const createUserStatusWithState = async (userId, collection, state) => { |
| 364 | const currentTimeStamp = new Date().getTime(); |
| 365 | try { |
| 366 | const payload = { |
| 367 | userId, |
| 368 | currentStatus: { |
| 369 | state, |
| 370 | message: "", |
| 371 | from: currentTimeStamp, |
| 372 | until: "", |
| 373 | updatedAt: currentTimeStamp, |
| 374 | }, |
| 375 | }; |
| 376 | if (state === userState.IDLE) { |
| 377 | payload.idleFrom = currentTimeStamp; |
| 378 | } |
| 379 | await collection.add(payload); |
| 380 | } catch (err) { |
| 381 | logger.error(`error creating the current status for user id ${userId} - ${err.message}`); |
| 382 | throw new Error("Status Creation Failed."); |
| 383 | } |
| 384 | return { |
| 385 | status: "success", |
| 386 | message: `UserStatus Document did not previously exist, New UserStatus Document created and updated to an ${state} status.`, |
| 387 | data: { |
| 388 | currentStatus: state, |
| 389 | }, |
| 390 | }; |
| 391 | }; |
| 392 | |
| 393 | /** |
| 394 | * Retrieves the user ID based on the given username. |
no outgoing calls
no test coverage detected