我有一个模式,如下:
如何检查模式中的所有字段是否都已填充?
前端(react.js)有一个入职流程,在该流程中,他们需要首次登录的用户进入入职流程,第二次或多次登录的用户被发送到其他页面。因此,它们需要我提供一个布尔值。如何知道是否所有数据都已填充?
const userSchema = mongoose.Schema({
phoneNumber: { type: String },
role: { type: String, default: 'user' },
userDetails: {
firstName: { type: String },
lastName: { type: String },
userName: { type: String },
password: { type: String },
email: { type: String },
street_1: { type: String },
street_2: { type: String },
landmark: { type: String },
city: { type: String },
state: { type: String },
zipcode: { type: String },
},
kycDetails: {
aadharNumber: { type: String },
aadharFront: {
type: String,
},
aadharBack: {
type: String,
},
panNumber: { type: String },
panImage: {
type: String,
},
},
bankDetails: {
accountNumber: { type: String },
accountName: { type: String },
bankName: { type: String },
ifscCode: { type: String },
},
});发布于 2020-01-29 18:48:20
您可以使用验证包https://ajv.js.org/来检查Json中需要的所有字段
例如
const nSchema = {
type: 'object',
properties: {
phoneNumber: {type: 'string'},
role: {type: 'string', enum:['user']},
},
required: ['phoneNumber', 'role'],
additionalProperties: false
};
const valid = ajv.validate(nSchema, data);
if (!valid) {
}https://stackoverflow.com/questions/59965264
复制相似问题