I'll eventually add something here.
diegohaz / bodymen Goto Github PK
View Code? Open in Web Editor NEWBody parser middleware for MongoDB, Express and Nodejs (MEN)
License: Other
Body parser middleware for MongoDB, Express and Nodejs (MEN)
License: Other
You mention in readme that body-parser is needed, but you dont use it in your rest-generator project, how is that? Thanks!
I want to create validation for phoneNumber
phoneNumber:{ type: String, validate: /\(?([0-9]{3})\)?([ .-]?)([0-9]{3})\2([0-9]{4})/ }
or to choose validate that value equals only one of provided
productType: { type: String, validate: ['bread', 'milk'] }
Hi there! A have a question about mongoose
and pre validate.
Is it possible to pre validate the request using Mongoose and bodymen and schema.tree
with reference other collection as a field?
.
I need to validate the "user" and "location" fields.
import { Router } from 'express';
import { middleware as body } from 'bodymen';
import { token } from '../../services/passport';
import { create } from './controller';
import Company, { schema } from './model';
const router = new Router();
const {
user,
social_name,
...
location,
...
} = schema.tree;
router.post('/',
token({ required: true }),
body({
user,
...
location,
...
}),
create);
export default router;
The company model:
import mongoose, { Schema } from 'mongoose';
import mongooseKeywords from 'mongoose-keywords';
const statusList = ['a', 'd'];
const CompanySchema = new Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'User',
required: true,
},
social_name: {
type: String,
trim: true,
default: null,
},
fantasy_name: {
type: String,
trim: true,
...
location: {
type: Schema.Types.ObjectId,
ref: 'Location',
required: true,
},
...
}
In the location
field, if I POST a JSON object, it process like that:
{
"formatted_address": "RN143, Mendoza, Argentina",
"id": "5ba416cb667...",
"name": "Ruta Nacional 143",
"place_id": "C_EhlSTjE0MywgTWVuZ..."
}
And shows me an error as below:
ValidationError: location: Cast to ObjectID failed for value "[object Object]" at path "location", user: Path `user` is required.
I have the following field being send to node app (created off your generator btw)
links: [{'icon':'path to icon'}]
but once it gets to the controller, it fails due to its converted to '[object Object]'. Confirmed that the array of object is correct if I remove the
body({ links })
Suggestions or bug? Thanks
Most of the time the Required statement is only applicable for creating the documents. After creation I cannot force the user to fill these fields again. Is there any option to bypass this?
I am copying the schema tree
const schemaTree = schema.tree
delete schemaTree._id;
delete schemaTree.updatedAt;
delete schemaTree.createdAt;
delete schemaTree.__v;
router.put('/:id',
body( schemaTree ),
update)
Reproduction:
Using a basic express prototype:
router.post(
'/',
bodymen.middleware({
fieldA: { type: String, required: true },
fieldB: { type: String, required: "randomstring" },
fieldC: { type: String, required: () => { return false } }
}),
(req, res, next) => {
res.end("done")
}
)
All the 3 fields fieldA .. C
becomes a required = true case. Calling it will return that all fields are required. I was hoping that atleast 'fieldC' should work as expected.
Did I miss anything?
how to make conditional validation using bodymen? for example only validate if some flag is enabled.
Is there any such feature in it?
Hi, I'm trying to use bodymen with nested properties like this:
{
'Name': 'Marc',
'Address' : {
'Street' : 'My Street',
'City' : 'My City'
}
}
But I have an error in the middleware:
ValidationError: Address: Cast to Object failed for value "[object Object]" at path "Address"
Any ideas? Thanks.
Hey there!
I'd like to report a security issue but cannot find contact instructions on your repository.
If not a hassle, might you kindly add a SECURITY.md
file with an email, or another contact method? GitHub recommends this best practice to ensure security issues are responsibly disclosed, and it would serve as a simple instruction for security researchers in the future.
Thank you for your consideration, and I look forward to hearing from you!
(cc @huntr-helper)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.