BuildForSDGCohort2 / BuildForSDGCohort2/Team-291-Backend

Validate the Mongoose Schema with Joi Library

Open
#20 1 comment 0 reactions 2 assignees Claimed by @Fahad565 View on GitHub
Dominant language
JavaScript
Stars
0
Forks
3
PR merge metrics
No merged PRs in 30d

Description

`"use strict";

import mongoose from "mongoose";
import Joi from "joi";

const userSchema = mongoose.Schema({
username: { type: String, required: true },
password: { type: String, required: true },
email: { type: String, required: true },
createdAt: { type: Date, default: Date.now }
});

userSchema.methods.joiValidate = function(obj) {
var schema = {
username: Joi.types
.String()
.min(6)
.max(30)
.required(),
password: Joi.types
.String()
.min(8)
.regex(/[a-zA-Z0-9]{3,30}/)
.required(),
email: Joi.types
.String()
.email()
.required(),
createdAt: Joi.types.Date()
};
return Joi.validate(obj, schema);
};

export default mongoose.model("User", userSchema);
`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.