D
D
deadkEEper12016-02-23 19:38:43
MongoDB
deadkEEper1, 2016-02-23 19:38:43

What is the right way to allow users to make friends on Backbone)?

And so, there is a mongo user model

var userSchema = new Schema({

    name:{
        required: true,
        type: String
    },
    email:{
        unique: true,
        required: true,
        type: String

    },
    password:{
        required: true,
        type: String
    },

    admin: {
        type: Boolean,
        default: false
    }

});

Now I want to give users the opportunity to be friends with each other. There is such an idea, but I'm not sure how correct it is to do so.
I plan to do so. Extend mongo model with friends array
var userSchema = new Schema({

    name:{
        required: true,
        type: String
    },
    email:{
        unique: true,
        required: true,
        type: String

    },
    password:{
        required: true,
        type: String
    },

    admin: {
        type: Boolean,
        default: false
    },

    friends: []
});

The array will be pushed by objects with id and status properties. Below is an example of filling the friends array when Vasya sent a request to Petya (Peter and Vasya are instances of the Backbone model)
vasya.friends
    {
  id: '56cc82a5244575d800d1acab', // пети _id 
  status: outcomeRequest
  }
  
  petya.friends
    {
  id: '76cc8d5fbf31sf8ac06cffc5a',  // васи _id
  status: incomeRequest
  }

If Petya accepts the request, the status changes for both to status (status: friend), if not, the object is deleted.
Would it be right to do so?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question