add Client and Code

parent bdd0e53b
/**
* Created by danilaeremin on 17.06.16.
*/
'use strict';
var dbUtils = require('./dbUtils');
var Client = require('./models/mongoose').Client;
// RefreshToken
exports.saveClient = function(client, secret, redirect, callback) {
dbUtils.dbCreateItem(Client,{ client: client, secret: secret, redirect: redirect }, callback);
};
exports.getClient = function (client, callback) {
dbUtils.dbFindOne(Client, {client: client}, callback);
};
exports.removeClient = function (client, callback) {
dbUtils.dbRemoveItem(Client, {client: client}, callback);
};
/**
* Created by danilaeremin on 17.06.16.
*/
'use strict';
var dbUtils = require('./dbUtils');
var Code = require('./models/mongoose').Code;
exports.saveCode = function(code, userId, scope, clientId, redirect, callback) {
dbUtils.dbCreateItem(Code,{ code: code, user: userId, scope: scope, client: clientId, redirect:redirect }, callback);
};
exports.getCode = function (code, callback) {
dbUtils.dbFindOne(Code, {code: code}, callback);
};
exports.removeCode = function (token, callback) {
dbUtils.dbRemoveItem(Code, {code: code}, callback);
};
......@@ -13,36 +13,26 @@ exports.getUsers = function (callback) {
};
exports.getUsersWithType = function (type, callback) {
dbUtils.dbFind(User, {accountType : type}, function(res) {
callback({status: 'ok', users: res.data});
});
dbUtils.dbFind(User, {accountType : type}, callback);
};
exports.getUserById = function (uId, callback) {
dbUtils.dbFindOne(User, {_id: uId}, function (res) {
callback({status : res.status, user : res.data});
});
dbUtils.dbFindOne(User, {_id: uId}, callback);
};
exports.getUserByLogin = function (login, callback) {
dbUtils.dbFindOne(User, {login: login}, function (res) {
callback({status : res.status, user : res.data});
});
dbUtils.dbFindOne(User, {login: login}, callback);
};
exports.getUserByIds = function (ids, callback) {
dbUtils.dbFind(User, { _id: { $in: ids }}, function(res) {
callback({status : res.status, users : res.data});
});
dbUtils.dbFind(User, { _id: { $in: ids }}, callback);
};
var createUser = function (user_object, callback) {
dbUtils.dbCreateItem(User,user_object, function (res){
callback({status : res.status, user : res.data});
});
dbUtils.dbCreateItem(User, user_object, callback);
};
exports.createUser = function (password, accountType, mail, name, surname, callback) {
exports.createUser = function (password, accountType, mail, name, surname, meta, callback) {
var newUser = {
username : surname + " " + name[0] + ".",
login : mail,
......@@ -51,13 +41,14 @@ exports.createUser = function (password, accountType, mail, name, surname, callb
mail : mail,
name : name,
surname : surname,
meta:meta,
activated : false
};
createUser(newUser,callback);
};
exports.createSocialUser = function (socialId, accountType, mail, name, surname, callback) {
exports.createSocialUser = function (socialId, accountType, mail, name, surname, meta, callback) {
var newUser = {
username : surname + " " + name[0] + ".",
login : socialId,
......@@ -66,6 +57,7 @@ exports.createSocialUser = function (socialId, accountType, mail, name, surname,
mail : mail,
name : name,
surname : surname,
meta:meta,
activated : true,
isSocial : true
};
......@@ -85,30 +77,10 @@ exports.blockUser = function (userId, callback) {
dbUtils.dbFindOneAndUpdate(User, {_id: userId}, {activated: false}, callback);
};
exports.addGroupTag = function (userId, tag, callback) {
dbUtils.dbFindOneAndUpdate(User, {_id : userId}, {$addToSet : {groupTags : tag}}, callback);
};
exports.addWorldTag = function (userId, tag, callback) {
dbUtils.dbFindOneAndUpdate(User, {_id : userId}, {$addToSet : {worldTags : tag}}, callback);
};
exports.deleteGroupTag = function (userId, tag, callback) {
dbUtils.dbFindOneAndUpdate(User, {_id : userId}, {$pull : {groupTags : { $in: [ tag ] }}}, callback);
};
exports.deleteWorldTag = function (userId, tag, callback) {
dbUtils.dbFindOneAndUpdate(User, {_id : userId}, {$pull : {worldTags : { $in: [ tag ] }}}, callback);
};
exports.updateUserLastLogin = function (userId, callback) {
dbUtils.dbFindOneAndUpdate(User, {_id : userId}, {lastLogin : new Date()}, callback);
};
exports.updateUserLastResultView = function (userId, callback) {
dbUtils.dbFindOneAndUpdate(User, {_id : userId}, {lastResultView : new Date()}, callback);
};
exports.updatePassword = function (userId, password, callback) {
dbUtils.dbFindOneAndUpdate(User, {_id : userId}, {password : password}, callback);
};
......@@ -122,7 +94,5 @@ exports.updateUserInfo = function (userId, mail, name, surname, username, login,
login : login
};
dbUtils.dbFindOneAndUpdate(User, {_id : userId}, update, function (data) {
callback({status : data.status, user : data.data});
});
dbUtils.dbFindOneAndUpdate(User, {_id : userId}, update, callback);
};
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment