db - minor fixes
This commit is contained in:
parent
7b02cdbaf8
commit
d48aca05bc
@ -153,7 +153,7 @@ methods.getUsers = async () => {
|
|||||||
* @return {Object} async(reply, err)
|
* @return {Object} async(reply, err)
|
||||||
*/
|
*/
|
||||||
methods.getUser = async (haystack) => {
|
methods.getUser = async (haystack) => {
|
||||||
if(typeof haystack !== 'string' && typeof haystack !== 'object') return {err: new TypeError('email or nickname is not a string|object::database.getUser('+haystack+')', module.filename)};
|
if(typeof haystack !== 'string' && typeof haystack !== 'object') return {err: new TypeError('haystack is not a string|object::database.getUser('+haystack+')', module.filename)};
|
||||||
|
|
||||||
let userModel = models.user;
|
let userModel = models.user;
|
||||||
|
|
||||||
@ -200,14 +200,14 @@ methods.getUser = async (haystack) => {
|
|||||||
* @return {Object} async(reply, err)
|
* @return {Object} async(reply, err)
|
||||||
*/
|
*/
|
||||||
methods.updateUser = async (id, obj) => {
|
methods.updateUser = async (id, obj) => {
|
||||||
if(typeof id !== 'string') return {err: new TypeError('id is not a string::database.updateUser('+id+','+JSON.stringify(obj)+')', module.filename)};
|
if(!(typeof id === 'string' || id instanceof mongoose.Types.ObjectId)) return {err: new TypeError('id is not a string::database.updateUser('+id+','+JSON.stringify(obj)+')', module.filename)};
|
||||||
if(typeof obj !== 'object') return {err: new TypeError('obj is not an object::database.updateUser('+id+','+JSON.stringify(obj)+')', module.filename)};
|
if(typeof obj !== 'object') return {err: new TypeError('obj is not an object::database.updateUser('+id+','+JSON.stringify(obj)+')', module.filename)};
|
||||||
|
|
||||||
let userModel = models.user;
|
let userModel = models.user;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = await userModel.findByIdAndUpdate(id, obj).exec();
|
data = await userModel.findByIdAndUpdate(id, obj).exec();
|
||||||
return {data: data};
|
return {reply: data};
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
return {err: err};
|
return {err: err};
|
||||||
}
|
}
|
||||||
@ -225,7 +225,7 @@ methods.updateUser = async (id, obj) => {
|
|||||||
* @return {Object} async({date => 'Login Date', token => 'RememberMe Cookie Token'}, err)
|
* @return {Object} async({date => 'Login Date', token => 'RememberMe Cookie Token'}, err)
|
||||||
*/
|
*/
|
||||||
methods.addActivity = async (id, data) => {
|
methods.addActivity = async (id, data) => {
|
||||||
if(typeof id !== 'string') return {err: new TypeError('id is not a string::database.updateNewAction('+id+','+JSON.stringify(options)+')', module.filename)};
|
if(!(typeof id === 'string' || id instanceof mongoose.Types.ObjectId)) return {err: new TypeError('id is not a string::database.updateNewAction('+id+','+JSON.stringify(options)+')', module.filename)};
|
||||||
if(typeof options !== 'object' && options !== null) return {err: new TypeError('obj is not an object::database.updateUserProfile('+id+','+JSON.stringify(obj)+')', module.filename)};
|
if(typeof options !== 'object' && options !== null) return {err: new TypeError('obj is not an object::database.updateUserProfile('+id+','+JSON.stringify(obj)+')', module.filename)};
|
||||||
|
|
||||||
let date = new Date().toISOString();
|
let date = new Date().toISOString();
|
||||||
@ -345,12 +345,12 @@ methods.getGroup = async (haystack) => {
|
|||||||
*/
|
*/
|
||||||
methods.addGroup = async (name, roles) => {
|
methods.addGroup = async (name, roles) => {
|
||||||
if(typeof name !== 'string') return {err: new TypeError('name is not a string::database.addGroup('+name+','+roles+')', module.filename)};
|
if(typeof name !== 'string') return {err: new TypeError('name is not a string::database.addGroup('+name+','+roles+')', module.filename)};
|
||||||
if(typeof roles !== 'string') return {err: new TypeError('name is not a string::database.addGroup('+name+','+roles+')', module.filename)};
|
if(typeof roles !== 'string') return {err: new TypeError('roles is not a string::database.addGroup('+name+','+roles+')', module.filename)};
|
||||||
|
|
||||||
let groupModel = models.group;
|
let groupModel = models.group;
|
||||||
|
|
||||||
let group = new groupModel();
|
let group = new groupModel();
|
||||||
|
|
||||||
// sanitize input
|
// sanitize input
|
||||||
group.name = sanitize(nick);
|
group.name = sanitize(nick);
|
||||||
group.roles = sanitize(email);
|
group.roles = sanitize(email);
|
||||||
@ -372,14 +372,14 @@ methods.addGroup = async (name, roles) => {
|
|||||||
* @return {Object} async(reply, err)
|
* @return {Object} async(reply, err)
|
||||||
*/
|
*/
|
||||||
methods.updateGroup = async (id, obj) => {
|
methods.updateGroup = async (id, obj) => {
|
||||||
if(typeof id !== 'string') return {err: new TypeError('id is not a string::database.updateGroup('+id+','+JSON.stringify(obj)+')', module.filename)};
|
if(!(typeof id === 'string' || id instanceof mongoose.Types.ObjectId)) return {err: new TypeError('id is not a string::database.updateGroup('+id+','+JSON.stringify(obj)+')', module.filename)};
|
||||||
if(typeof obj !== 'object') return {err: new TypeError('obj is not an object::database.updateGroup('+id+','+JSON.stringify(obj)+')', module.filename)};
|
if(typeof obj !== 'object') return {err: new TypeError('obj is not an object::database.updateGroup('+id+','+JSON.stringify(obj)+')', module.filename)};
|
||||||
|
|
||||||
let groupModel = models.group;
|
let groupModel = models.group;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = await groupModel.findByIdAndUpdate(id, obj).exec();
|
data = await groupModel.findByIdAndUpdate(id, obj).exec();
|
||||||
return {data: data};
|
return {reply: data};
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
return {err: err};
|
return {err: err};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user