MCPcopy Create free account
hub / github.com/RealDevSquad/website-backend / createUserStatusWithState

Function createUserStatusWithState

utils/userStatus.js:363–391  ·  view source on GitHub ↗
(userId, collection, state)

Source from the content-addressed store, hash-verified

361 */
362
363const 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.

Calls

no outgoing calls

Tested by

no test coverage detected