MCPcopy Create free account
hub / github.com/async-labs/async / changeOnlineStatusForTeam

Method changeOnlineStatusForTeam

api/server/models/User.ts:1583–1618  ·  view source on GitHub ↗
({ userId, status, teamId })

Source from the content-addressed store, hash-verified

1581 // markMessageAsReadForUserAfterMessageIsDeletedByUser
1582
1583 public static async changeOnlineStatusForTeam({ userId, status, teamId }) {
1584 if (!userId) {
1585 throw new Error('Bad data.');
1586 }
1587
1588 const user = await this.findOne({ _id: userId }).setOptions({
1589 lean: true,
1590 });
1591
1592 const team =
1593 (user.onlineStatusByTeam.length > 0 &&
1594 user.onlineStatusByTeam.find((t) => t.teamId === teamId)) ||
1595 null;
1596
1597 if (team) {
1598 await this.findOneAndUpdate(
1599 { _id: userId, 'onlineStatusByTeam.teamId': teamId },
1600 {
1601 $set: {
1602 'onlineStatusByTeam.$.status': status,
1603 },
1604 },
1605 { runValidators: true, new: true },
1606 );
1607 } else {
1608 await this.findOneAndUpdate(
1609 { _id: userId },
1610 {
1611 $push: {
1612 onlineStatusByTeam: { teamId, status },
1613 },
1614 },
1615 { runValidators: true, new: true },
1616 ).setOptions({ lean: true });
1617 }
1618 }
1619
1620 public static async deleteTeam({ teamId, userId }) {
1621 if (!userId || !teamId) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected