1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/backend/model/mongoose/MongoUserManager.ts

52 lines
1.5 KiB
TypeScript
Raw Normal View History

import {User, UserRoles} from "../../../common/entities/User";
2016-04-22 19:23:44 +08:00
import {IUserManager} from "../IUserManager";
import {DatabaseManager} from "./DatabaseManager";
export class MongoUserManager implements IUserManager {
2016-04-22 19:23:44 +08:00
private UserModel;
constructor() {
this.UserModel = DatabaseManager.getInstance().getModel('user', {
name: {type: String, index: {unique: true}},
password: String,
role: Number
2016-04-22 19:23:44 +08:00
});
}
public findOne(filter, cb:(error:any, result:User) => void) {
return this.UserModel.findOne(filter, function (err, result) {
2016-04-22 19:23:44 +08:00
return cb(err, result);
});
2016-04-22 19:23:44 +08:00
}
public find(filter, cb:(error:any, result:Array<User>) => void) {
this.UserModel.find(filter, function (err, result) {
2016-04-22 19:23:44 +08:00
return cb(err, result);
});
}
public createUser(user, cb:(error:any, result:User) => void) {
this.UserModel.create(user, cb);
2016-04-22 19:23:44 +08:00
}
public deleteUser(id:number, cb:(error:any) => void) {
this.UserModel.remove({id: id}, cb);
2016-04-22 19:23:44 +08:00
}
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);
});
2016-04-22 19:23:44 +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
}
}