I want to check: If my schema.type ==='gas'
then my schema.status
should be good
,
if schema.type = noGas
then my schema.status
should be bad
.
Both fields are mandatory.
I was able to make a field mandatory or not based on another field value.
const bottle: Schema = new Schema({
type: {
type: String,
required: true,
enum: ['gas', 'noGas'],
},
status: {
type: String,
enum: ['good', 'bad']
required(this: IBottle): boolean {
// Check values here. But I could only ensure the field as required or not.
return this.type === 'gas' || this.type === 'noGas';
}
}
});
But what if besides that, I also want to validate the value of the field, not just if it is present.
How could I do that?
I saw this example, which is using Validate()
to validate the value, but i need a little more. I need to also SET the field's value, based on the value of the other field.