Adding Our Create Handler

Background

The create handler uses the same route as index but has a different verb. For this handler, we're going to validate two pieces of information - email and password - then pass that data off to a createuser() method in models.userService which will use QB to insert the data into the DB.

Making It Work

Our handler looks like this in handlers.Users

function create( event, rc, prc ){
	var valid = validateOrFail(
		target      = rc,
		constraints = {
			"email"    : { "required" : true, "type" : "email", "size" : "1..256" },
			"password" : { "required" : true, "type" : "string", "size" : "1..256" }
		}
	);

	var created = userService.createUser( valid.email, valid.password );

	prc.response.setData( created ).addMessage( "user created" );
}

The createuser method in models.UserService looks like this:\

To add some Update Logic we added this function to the users entity \

Last updated