Rameshwar Bhaskar
07/25/2023, 7:48 AM/**
* I model a API/User
*/
component table="users" persistent="true" extends="cborm.models.ActiveEntity" transientCache="false"
delegates="Validatable@cbvalidation,Population@cbDelegates,Auth@cbSecurity,Authorizable@cbSecurity,JwtSubject@cbSecurity"{
// get reference
property name="validationManager" inject="ValidationManager@cbvalidation";
// Properties
property name="id" column="id" fieldType="id" generator="uuid";
property name="username" ormtype="string";
property name="email" ormtype="string";
property name="mobile" ormtype="string";
property name="firstname" ormtype="string";
property name="lastname" ormtype="string";
property name="country" ormtype="string";
property name="password" ormtype="string";
property name="is_email_verify" ormtype="BOOLEAN";
property name="is_phone_verify" ormtype="BOOLEAN";
property name="is_seller_verify" ormtype="BOOLEAN";
property name="role" cfc="wallpaper_id" fieldtype="one-to-one" fkcolumn="users_wall" lazy="true" notnull="false";
property name="profile_photo" ormtype="string";
property name="profile_banner" ormtype="string";
property name="role" cfc="subscription_id" fieldtype="one-to-one" fkcolumn="user_subsc_id" lazy="true" notnull="false";
property name="created_at" ormtype="TIMESTAMP";
property name="active" ormtype="BOOLEAN";
property name="otp" ormtype="string";
// Validation Constraints
this.constraints = {
username = { required=true},
email = { required=true, type="email" },
mobile = { required=true, size="5..10" },
firstname = { required=true, size="5..10" },
lastname = { required=true },
// password = { required=true, min="8" max="24" type="string" };
};
// Constraint Profiles
this.constraintProfiles = {
// "update" : {}
};
// Population Control
this.population = {
include : ['*'],
exclude : [ "password" ]
};
// Mementifier
this.memento = {
// An array of the properties/relationships to include by default
defaultIncludes = [ "*" ],
// An array of properties/relationships to exclude by default
defaultExcludes = [],
// An array of properties/relationships to NEVER include
neverInclude = [],
// A struct of defaults for properties/relationships if they are null
defaults = {},
// A struct of mapping functions for properties/relationships that can transform them
mappers = { }
};
/**
* Constructor
*/
User function init(){
super.init( useQueryCaching="false" );
return this;
}
/**
* Verify if the model has been loaded from the database
*/
function isLoaded(){
return ( !isNull( variables.id ) && len( variables.id ) );
}
}
and the handler code is here
/**
* I am a new handler
* Implicit Functions: preHandler, postHandler, aroundHandler, onMissingAction, onError, onInvalidHTTPMethod
*/
component extends="coldbox.system.RestHandler"{
this.prehandler_only = "";
this.prehandler_except = "";
this.posthandler_only = "";
this.posthandler_except = "";
this.aroundHandler_only = "";
this.aroundHandler_except = "";
this.allowedMethods = {};
property name="userService" inject="API.User";
property name="bCrypt" inject="BCrypt@BCrypt";
property name="queryBuilder" inject="QueryBuilder@qb";
/**
* Display a listing of the resource
*/
function register( event, rc, prc ){
var userData = {
id: createUUID(),
username : rc.username ,
email : rc.email,
mobile : rc.mobile,
firstname : rc.firstname,
lastname : rc.lastname,
country : rc.country,
password : bCrypt.hashPassword(rc.password),
is_email_verify : 0,
is_phone_verify : 0,
is_seller_verify : 0,
wallpaper_id : "",
profile_photo : "",
profile_banner : "",
subscription_id: 1,
otp : '1234',
created_at : now(),
active : 1
};
prc.user = userService
.new(userData);
prc.newUser = userService
.save( prc.user )
.getMemento(excludes="[password,otp]" );
event.getResponse()
.setData( prc.user )
.addMessage(
"user registration completed...!"
);
}
}
when i'am calling register method iam getting bellow error says An exception ocurred: Can't cast Component [ValidationManager] to String
{
"data": {
"environment": {
"currentRoutedUrl": "api/register/",
"timestamp": "2023-07-25T07:40:06Z",
"currentRoute": "api/register/",
"currentEvent": "API.Auth.register"
},
"exception": {
"stack": [
"E:\\LiveProjects\\Coldfusion\\Stackur\\StackurApi\\modules\\cborm\\models\\BaseORMService.cfc:1540",
"E:\\LiveProjects\\Coldfusion\\Stackur\\StackurApi\\modules\\cborm\\models\\BaseORMService.cfc:1977",
"E:\\LiveProjects\\Coldfusion\\Stackur\\StackurApi\\modules\\cborm\\models\\BaseORMService.cfc:1555",
"E:\\LiveProjects\\Coldfusion\\Stackur\\StackurApi\\modules\\cborm\\models\\ActiveEntity.cfc:85",
"E:\\LiveProjects\\Coldfusion\\Stackur\\StackurApi\\handlers\\API\\Auth.cfc:48",
"E:\\LiveProjects\\Coldfusion\\Stackur\\StackurApi\\coldbox\\system\\RestHandler.cfc:58",
"E:\\LiveProjects\\Coldfusion\\Stackur\\StackurApi\\coldbox\\system\\web\\Controller.cfc:998",
"E:\\LiveProjects\\Coldfusion\\Stackur\\StackurApi\\coldbox\\system\\web\\Controller.cfc:713",
"E:\\LiveProjects\\Coldfusion\\Stackur\\StackurApi\\coldbox\\system\\Bootstrap.cfc:290",
"E:\\LiveProjects\\Coldfusion\\Stackur\\StackurApi\\coldbox\\system\\Bootstrap.cfc:506",
"E:\\LiveProjects\\Coldfusion\\Stackur\\StackurApi\\Application.cfc:115"
],
"detail": "",
"type": "expression",
"extendedInfo": ""
}
},
"error": true,
"pagination": {
"totalPages": 1,
"maxRows": 0,
"offset": 0,
"page": 1,
"totalRecords": 0
},
"messages": "An exception ocurred: Can't cast Component [ValidationManager] to String"
}aliaspooryorik
.getMemento(excludes="[password,otp]" ); That should either be an array...
.getMemento(excludes=["password","otp"] );
or a list...
.getMemento(excludes="password,otp" );
you seem to have invalid mix of both data typesaliaspooryorik
Rameshwar Bhaskar
07/25/2023, 8:07 AMAn exception ocurred: Can't cast Component [ValidationManager] to String on the mesage key and when i dump prc.user = userService.new(userData);
writeDump(prc.user); i seen the property and on the property i found ValidationManager as a component
so i don't think this error comes with that if that then it will return a syntax error
but now i changed getMemento as array as you said, after taht this gives me the same erroraliaspooryorik
validationManager - why would you want that in your memento?Rameshwar Bhaskar
07/25/2023, 8:43 AMprc.newUser = userService
.save( prc.user )
.getMemento(excludes="password,otp" );
writeDump(prc.newUser) the error comes when i want to save the data using model.aliaspooryorik
Rameshwar Bhaskar
07/25/2023, 9:34 AMRameshwar Bhaskar
07/25/2023, 9:36 AMaliaspooryorik
Rameshwar Bhaskar
07/25/2023, 9:37 AMaliaspooryorik
Rameshwar Bhaskar
07/25/2023, 9:43 AM