1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-07-17 01:32:29 +02:00

implementing user listing and role changing

This commit is contained in:
Braun Patrik
2016-05-03 14:29:24 +02:00
parent 67d4d2be71
commit 11be4e3e87
15 changed files with 160 additions and 56 deletions

View File

@ -1,44 +1,51 @@
import {User} from "../../../common/entities/User";
import {User, UserRoles} from "../../../common/entities/User";
import {IUserManager} from "../IUserManager";
import {DatabaseManager} from "./DatabaseManager";
export class MongoUserManager implements IUserManager{
export class MongoUserManager implements IUserManager {
private UserModel;
constructor(){
this.UserModel = DatabaseManager.getInstance().getModel('user',{
name:String,
email:{ type: String, index: { unique: true }},
password:String,
role:Number
constructor() {
this.UserModel = DatabaseManager.getInstance().getModel('user', {
name: {type: String, index: {unique: true}},
password: String,
role: Number
});
}
public findOne(filter,cb:(error: any,result:User) => void){
return this.UserModel.findOne(filter,function (err, result) {
return cb(err, result);
});
}
public find(filter,cb:(error: any,result:Array<User>) => void){
this.UserModel.find(filter,function (err, result) {
public findOne(filter, cb:(error:any, result:User) => void) {
return this.UserModel.findOne(filter, function (err, result) {
return cb(err, result);
});
}
public createUser(user,cb:(error: any,result:User) => void){
this.UserModel.create(user,cb);
public find(filter, cb:(error:any, result:Array<User>) => void) {
this.UserModel.find(filter, function (err, result) {
return cb(err, result);
});
}
public deleteUser(id:number,cb:(error: any) => void){
this.UserModel.remove({id:id},cb);
public createUser(user, cb:(error:any, result:User) => void) {
this.UserModel.create(user, cb);
}
public changeRole(request:any,cb:(error: any,result:string) => void){
throw new Error("not implemented"); //TODO: implement
public deleteUser(id:number, cb:(error:any) => void) {
this.UserModel.remove({id: id}, cb);
}
public changePassword(request:any,cb:(error: any,result:string) => void){
public changeRole(id:number, newRole:UserRoles, cb:(error:any, result:string) => void) {
return this.UserModel.update({id: id}, {role: newRole}, function (err) {
if (!err) {
return cb(err, "ok")
}
return cb(err, null);
});
}
public changePassword(request:any, cb:(error:any, result:string) => void) {
throw new Error("not implemented"); //TODO: implement
}