Match user Schema with Client Schema on mongoose

0

good I am new working with node, and I am creating a user schema but I also have a client schema, and administrator, in the client schema (I leave the code below) I have the basic data like name, surname .. etc, and in the user's I have the email and its password, the idea is that the administrator generates a client from a form and through a contract number that is created at the time of registering the client the latter can register on the platform by means of a simple registration form that only asks for the contract number to be able to know which is the client that is registering when sending the form and the password, the question now which is the best way to relate the user that it is generated when the client registers with the client already registered by the administrator, he was thinking of assigning the user the client's _id (previously registered by the client) but I do not know if there is a better way to do it.

Client Schema

 const clientSchema = new Schema({
  contracts_id: [{ type: Schema.Types.ObjectId, ref: 'Contract' }],
  firstname: { type: String, require: true },
  lastname: { type: String, require: true },
  status: {
    type: String,
    enum: ['Active', 'Inactive'],
    default: 'Active',
    require: true
  },
  ci: { type: Number, require: true },
  phone: { type: Number },
  sendInvoince: { type: Boolean, require: true, default: true }
});

User's Schema

const UserSchema = new Schema(
  {
    type: { type: String, enum:['Admin','Client'], default: 'Admin', require: true },
    email: { type: String, unique: true },
    password: String,
    salt: String
  });
    
asked by Carlos Puente 02.01.2019 в 18:42
source

0 answers