Skip to content

Instantly share code, notes, and snippets.

@ats1999
Last active September 11, 2021 07:25
Show Gist options
  • Save ats1999/32e3f0aa868d742c8ae3c0ea9d9c2d32 to your computer and use it in GitHub Desktop.
Save ats1999/32e3f0aa868d742c8ae3c0ea9d9c2d32 to your computer and use it in GitHub Desktop.

Live users

requirement

  • a user can be part of multiple org
  • a user can be logged on the multiple dashboard at the same time
  • a user can be logged on the multiple dashboard of different org at the same time

REST

return all users, who are logged in the given dashboard,who belongs to the given org.

Schema

const LiveUserSchema = new mongoose.Schema({
  users: {
    type: [{
        name:String,
        email:String // this should be unique in this array
    }],
    default: []
  }
})

Initially

Initially i have the data

{
    users:[
        {name:"..",email:"123"},
        {name:"..",email:"789"}
    ]
}

Now, i would like to push a user with email 012, he should be pushed into the array because, it's not there already.

Then new data will looks like

{
    users:[
        {name:"..",email:"123"},
        {name:"..",email:"789"},
        {name:"..",email:"012"}
    ]
}

Now, i would like to push a user with email 123, he should not be pushed into the array because, it's already there.

new data

// no change
{
    users:[
        {name:"..",email:"123"},
        {name:"..",email:"789"},
        {name:"..",email:"012"}
    ]
}
@ats1999
Copy link
Author

ats1999 commented Sep 10, 2021

Schema - 1

[
    {
        orgId:"...",
        users:[
            email:"..", // unique
            dashboards:["operation","ground station","..."]
        ]
    }
]
  • add support, if the org already dose't exist inside the collection

  • add support, if the user is not persent inside users array

  • remove the dashboard from dashboards when user disconnects

  • add dashboard into dashboards when user connects

@ats1999
Copy link
Author

ats1999 commented Sep 10, 2021

Schema - 2

[
    {
        email:"...",
        orgId:"...",
        packageId:"..."
        // ...
    }
]
  • use combined value of email, orgId and dashboardName
  • add when user connects
  • remove when user disconnects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment