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-09 23:04:56 +08:00
|
|
|
export class UserManager implements IUserManager {
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
private users = [new User(1, "developer", "developer", UserRoles.Developer),
|
|
|
|
new User(2, "admin", "admin", UserRoles.Admin),
|
|
|
|
new User(3, "user", "user", UserRoles.User),
|
|
|
|
new User(4, "guest", "guest", UserRoles.Guest)];
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
public findOne(filter, cb:(error:any, result:User) => void) {
|
2016-05-03 20:29:24 +08:00
|
|
|
return cb(null, this.users[1]);
|
2016-04-22 19:23:44 +08:00
|
|
|
}
|
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
public find(filter, cb:(error:any, result:Array<User>) => void) {
|
2016-04-22 19:23:44 +08:00
|
|
|
return cb(null, this.users);
|
|
|
|
}
|
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
public createUser(user, cb:(error:any, result:User) => void) {
|
2016-04-22 19:23:44 +08:00
|
|
|
|
|
|
|
this.users.push(user);
|
|
|
|
return cb(null, user);
|
|
|
|
}
|
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
public deleteUser(id:number, cb:(error:any) => void) {
|
2016-04-22 19:23:44 +08:00
|
|
|
this.users = this.users.filter(u => u.id != id);
|
|
|
|
return cb(null);
|
|
|
|
}
|
2016-05-09 23:04:56 +08:00
|
|
|
|
|
|
|
public changeRole(id:number, newRole:UserRoles, cb:(error:any, result:string) => void) {
|
|
|
|
for (let i = 0; i < this.users.length; i++) {
|
|
|
|
if (this.users[i].id === id) {
|
2016-05-03 20:29:24 +08:00
|
|
|
this.users[i].role = newRole;
|
2016-05-09 23:04:56 +08:00
|
|
|
return cb(null, "ok");
|
2016-05-03 20:29:24 +08:00
|
|
|
}
|
|
|
|
}
|
2016-04-22 19:23:44 +08:00
|
|
|
}
|
2016-05-09 23:04:56 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|