2016-05-03 20:29:24 +08:00
|
|
|
import {User, UserRoles} from "../../../common/entities/User";
|
2016-04-22 19:23:44 +08:00
|
|
|
import {IUserManager} from "../IUserManager";
|
2016-05-05 00:36:16 +08:00
|
|
|
import {UserModel} from "./entities/UserModel";
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2016-05-03 20:29:24 +08:00
|
|
|
export class MongoUserManager implements IUserManager {
|
2016-04-22 19:23:44 +08:00
|
|
|
|
|
|
|
|
2016-05-03 20:29:24 +08:00
|
|
|
constructor() {
|
2016-04-22 19:23:44 +08:00
|
|
|
}
|
|
|
|
|
2016-05-03 20:29:24 +08:00
|
|
|
public findOne(filter, cb:(error:any, result:User) => void) {
|
2016-05-05 00:36:16 +08:00
|
|
|
return UserModel.findOne(filter, function (err, result) {
|
2016-04-22 19:23:44 +08:00
|
|
|
return cb(err, result);
|
2016-05-03 20:29:24 +08:00
|
|
|
});
|
2016-04-22 19:23:44 +08:00
|
|
|
}
|
|
|
|
|
2016-05-03 20:29:24 +08:00
|
|
|
public find(filter, cb:(error:any, result:Array<User>) => void) {
|
2016-05-05 00:36:16 +08:00
|
|
|
UserModel.find(filter, function (err, result) {
|
2016-04-22 19:23:44 +08:00
|
|
|
return cb(err, result);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-03 20:29:24 +08:00
|
|
|
public createUser(user, cb:(error:any, result:User) => void) {
|
2016-05-05 00:36:16 +08:00
|
|
|
UserModel.create(user, cb);
|
2016-04-22 19:23:44 +08:00
|
|
|
}
|
|
|
|
|
2016-05-03 20:29:24 +08:00
|
|
|
public deleteUser(id:number, cb:(error:any) => void) {
|
2016-05-05 00:36:16 +08:00
|
|
|
UserModel.remove({id: id}, cb);
|
2016-04-22 19:23:44 +08:00
|
|
|
}
|
2016-05-03 20:29:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
public changeRole(id:number, newRole:UserRoles, cb:(error:any, result:string) => void) {
|
2016-05-05 00:36:16 +08:00
|
|
|
return UserModel.update({id: id}, {role: newRole}, function (err) {
|
2016-05-03 20:29:24 +08:00
|
|
|
if (!err) {
|
|
|
|
return cb(err, "ok")
|
|
|
|
}
|
|
|
|
return cb(err, null);
|
|
|
|
|
|
|
|
});
|
2016-04-22 19:23:44 +08:00
|
|
|
}
|
2016-05-03 20:29:24 +08:00
|
|
|
|
|
|
|
public changePassword(request:any, cb:(error:any, result:string) => void) {
|
2016-04-22 19:23:44 +08:00
|
|
|
throw new Error("not implemented"); //TODO: implement
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|