Monday, 15 June 2020

I have two Schema and I am looking to display the list of all the classes created by a school id.

​I have two Schema and I am looking to display the list of all the classes created by a school id.​const Joi = require('joi');const mongoose = require('mongoose');​const schoolSchema = new mongoose.Schema({name: {type: String,required: true,minlength: 3,maxlength: 50,},phone: {type: Number,required: true,minlength: 8,maxlength: 8,},adress: {city: {type: String,required: true,minlength: 3,maxlength: 50,},street: {type: String,required: true,minlength: 3,maxlength: 50,},},});const School = mongoose.model('School', schoolSchema);​function validateSchool(school) {const schema = {name: Joi.string().min(3).max(50).required(),phone: Joi.string().min(8).max(8).required(),adress: Joi.object().keys({city: Joi.string().min(3).max(50).required(),street: Joi.string().min(3).max(50).required(),}),};return Joi.validate(school, schema);}exports.schoolSchema = schoolSchema;exports.School = School;exports.validateSchool = validateSchool;​----------------------------------------------------------------​const Joi = require('joi');const mongoose = require('mongoose');​const classeSchema = new mongoose.Schema({name: {type: String,required: true,minlength: 3,maxlength: 50,},level: {type: Number,required: true,},school: {type: new mongoose.Schema({name: {type: String,required: true,minlength: 3,maxlength: 50,},}),required: true,},});​const Classe = mongoose.model('Classe', classeSchema);​function validateClasse(classe) {const schema = {name: Joi.string().min(3).max(50).required(),level: Joi.number().required(),schoolId: Joi.objectId().required(),};return Joi.validate(classe, schema);}​exports.Classe = Classe;exports.validateClasse = validateClasse;exports.classeSchema = classeSchema;

Submitted June 15, 2020 at 08:43AM by medaligm

No comments:

Post a Comment