EN-80: Fixing public endpoints
EN-83: Removing company_type from register process
This commit is contained in:
@@ -19,7 +19,6 @@ const create_account_schema = {
|
||||
email : { type : 'string' , maxLength : 256 },
|
||||
password : { type : 'string', maxLength : 256},
|
||||
otp : { type : 'string', maxLength : 6 },
|
||||
company_type : { type : 'string', enum : ["Shipper" , "Carrier"] },
|
||||
checksum : { type : 'string', maxLength : 32 }
|
||||
},
|
||||
required : [ 'email', 'password' ]
|
||||
@@ -28,7 +27,7 @@ const create_account_schema = {
|
||||
const confirm_account_schema = {
|
||||
type : 'object',
|
||||
properties : create_account_schema.properties,//Same properties
|
||||
required : [ 'email', 'password', 'otp', 'company_type', 'checksum' ]//Different requirements
|
||||
required : [ 'email', 'password', 'otp', 'checksum' ]//Different requirements
|
||||
};
|
||||
|
||||
const login_account_schema = {
|
||||
@@ -168,7 +167,7 @@ const TryCreateAccount = async(req, res) => {
|
||||
const ConfirmAccount = async(req, res) => {
|
||||
try{
|
||||
if( validator.validate( req.body , confirm_account_schema ).valid ){
|
||||
const { email, password, otp, company_type, checksum } = req.body;
|
||||
const { email, password, otp, checksum } = req.body;
|
||||
|
||||
const it_exists = await already_exists( email );
|
||||
if( it_exists ){
|
||||
@@ -181,7 +180,7 @@ const ConfirmAccount = async(req, res) => {
|
||||
return res.status(400).send({ error : "Wrong OTP" });
|
||||
}
|
||||
|
||||
await create_account( email, password, company_type );
|
||||
await create_account( email, password );
|
||||
|
||||
const content = { user_name : email };
|
||||
const receiver = email;
|
||||
|
||||
@@ -6,18 +6,11 @@ const UserModel = require( `${ROOT_PATH}/${MODELS_PATH}/users.model.js` );
|
||||
|
||||
const pwd_secret = apiConfig.authentication.pwdSecret;
|
||||
|
||||
async function create_account( email, password, company_type ){
|
||||
let permissions;
|
||||
if( company_type === "Shipper"){
|
||||
permissions = "role_shipper";
|
||||
}else{
|
||||
permissions = "role_carrier";
|
||||
}
|
||||
async function create_account( email, password ){
|
||||
let safe_password = toSha256( password + pwd_secret );
|
||||
const user = new UserModel({
|
||||
email,
|
||||
password : safe_password,
|
||||
permissions
|
||||
password : safe_password
|
||||
});
|
||||
await user.save();
|
||||
}
|
||||
|
||||
@@ -27,4 +27,51 @@ function genKey( len = 6 , key="" ){
|
||||
return complete_string.substr(0 , len );
|
||||
}
|
||||
|
||||
module.exports = { genKey , toSha256 };
|
||||
function getPagination( query ){
|
||||
let limit = {
|
||||
page : 0,
|
||||
elements : 10
|
||||
};
|
||||
|
||||
if( query.page ){
|
||||
limit.page = parseInt( query.page ) || 0;
|
||||
if( limit.page < 0 ){
|
||||
limit.page = 0;
|
||||
}
|
||||
}
|
||||
if( query.elements ){
|
||||
limit.elements = parseInt( query.elements ) || 10;
|
||||
/** Safe pagination limit */
|
||||
if( limit.elements > 1000 ){
|
||||
limit.elements = 1000;
|
||||
}
|
||||
else if( limit.elements < 0 ){
|
||||
limit.elements = 10;
|
||||
}
|
||||
}
|
||||
return limit;
|
||||
}
|
||||
|
||||
async function getPage( page, elements, model, filter=null, projection=null){
|
||||
const skip = elements * page;
|
||||
const total = await model.count( filter );
|
||||
const list = await model.find( filter , projection, { skip : skip , limit : elements } );
|
||||
return {
|
||||
total : total,
|
||||
limit : elements,
|
||||
skip : skip,
|
||||
data : list
|
||||
}
|
||||
}
|
||||
|
||||
async function queryPage(page, elements, model, filter=null, projection=null){
|
||||
const skip = elements * page;
|
||||
const total = await model.count( filter );
|
||||
return {
|
||||
query : model.find( filter , projection, { skip : skip , limit : elements } ),
|
||||
total : total,
|
||||
skip : skip
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { genKey , toSha256, getPagination, getPage, queryPage };
|
||||
@@ -21,7 +21,7 @@ const schema = new Schema({
|
||||
password: { type: String , maxLength : 256 },
|
||||
phone: { type: String },
|
||||
phone2: { type: String },
|
||||
permissions: [{ type: String, default: 'role_admin', enum : ['role_admin', 'role_shipper', 'role_carrier', 'role_driver' ] }],
|
||||
permissions: [{ type: String, default: 'role_admin', enum : [ 'admin', 'role_admin', 'role_shipper', 'role_carrier', 'role_driver' ] }],
|
||||
gender: { type: String },
|
||||
address: { type: String },
|
||||
dob: { type: String },
|
||||
|
||||
Reference in New Issue
Block a user