mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
extracting models (Usermodel)
This commit is contained in:
parent
69489b8cb7
commit
67af4e5ed9
@ -1,42 +1,36 @@
|
||||
import {User, UserRoles} from "../../../common/entities/User";
|
||||
import {IUserManager} from "../IUserManager";
|
||||
import {DatabaseManager} from "./DatabaseManager";
|
||||
import {UserModel} from "./entities/UserModel";
|
||||
|
||||
export class MongoUserManager implements IUserManager {
|
||||
|
||||
private UserModel;
|
||||
|
||||
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 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) {
|
||||
UserModel.find(filter, function (err, result) {
|
||||
return cb(err, result);
|
||||
});
|
||||
}
|
||||
|
||||
public createUser(user, cb:(error:any, result:User) => void) {
|
||||
this.UserModel.create(user, cb);
|
||||
UserModel.create(user, cb);
|
||||
}
|
||||
|
||||
public deleteUser(id:number, cb:(error:any) => void) {
|
||||
this.UserModel.remove({id: id}, cb);
|
||||
UserModel.remove({id: id}, cb);
|
||||
}
|
||||
|
||||
|
||||
public changeRole(id:number, newRole:UserRoles, cb:(error:any, result:string) => void) {
|
||||
return this.UserModel.update({id: id}, {role: newRole}, function (err) {
|
||||
return UserModel.update({id: id}, {role: newRole}, function (err) {
|
||||
if (!err) {
|
||||
return cb(err, "ok")
|
||||
}
|
||||
|
6
backend/model/mongoose/entities/UserModel.ts
Normal file
6
backend/model/mongoose/entities/UserModel.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import {DatabaseManager} from "../DatabaseManager";
|
||||
export var UserModel = DatabaseManager.getInstance().getModel('user', {
|
||||
name: {type: String, index: {unique: true}},
|
||||
password: String,
|
||||
role: Number
|
||||
});
|
Loading…
Reference in New Issue
Block a user