Drupal 8 - How to create a Page with admin access and create its menu entry in Reports (No Coding)
Introduction I needed a report page, where I wanted to have some information…
May 07, 2020
In this post, I will show how to validate your json schema validation across veriety of use-cases.
Example, you are having 5 fields. And, for three fields you want either of them to be present. Note: Success criteria is to have only one of these three fields, not 2 not 3.
Example schema validation with Joi:
const validationJoi = Joi.object({
field1: Joi.string(),
field2: Joi.string(),
field3: Joi.string(),
field4: Joi.string(),
field5: Joi.string(),
}).xor('field1', 'field2', 'field3')
const obj = {
field1: "value1",
field4: "value4",
};
const isValid = Joi.validate(obj, validationJoi);
//true
const obj2 = {
field4: "value4",
};
const isValid2 = Joi.validate(obj, validationJoi);
//false
Note the xor above.
Note, this validation can also be used in mongoose schema validations.
const Joi = require('joi');
const mySchema = mongoose.Schema({
name: String,
country: String,
email: String,
created: { type: Date, default: Date.now }
});
mySchema.methods.schemaValidate = function(obj) {
const schema = {
name: Joi.types.String().min(6).max(30).required(),
country: Joi.types.String().required(),
email: Joi.types.String().email().required()
created: Joi.types.Date(),
}
return Joi.validate(obj, schema);
}
module.exports = mongoose.model('User', mySchema);
And, in some service code you can call this method schemaValidate on MySchema object.
Introduction I needed a report page, where I wanted to have some information…
Introduction It is very important to introduce few process so that your code and…
Code that I have is: It was: I changed it to: So, I needed to change button type…
This library is ES6, promise compatible. Or, in your package.json file, include…
Introduction Consider a scenario where you are building a docker image on your…
Introduction to problem So, on my mac, I’ev set timezone to my local city i.e…
Introduction In this post we will see following: How to schedule a job on cron…
Introduction There are some cases, where I need another git repository while…
Introduction In this post, we will see how to fetch multiple credentials and…
Introduction I have an automation script, that I want to run on different…
Introduction I had to write a CICD system for one of our project. I had to…
Introduction Java log4j has many ways to initialize and append the desired…