|
|
|
@ -31,7 +31,20 @@ exports.create = async (req, res, next) => { |
|
|
|
|
ErrorHandler(ex, req, res, next); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}); |
|
|
|
|
// await User.destroy({
|
|
|
|
|
// where : {
|
|
|
|
|
// email: "teststaff@gmail.com"
|
|
|
|
|
// }
|
|
|
|
|
// }).then( rs => {
|
|
|
|
|
// return res.json({
|
|
|
|
|
// ms: "success"
|
|
|
|
|
// });
|
|
|
|
|
// }).catch(ex => {
|
|
|
|
|
// ErrorHandler(ex,req,res,next);
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -44,15 +57,10 @@ exports.create = async (req, res, next) => { |
|
|
|
|
exports.list = async (req, res, next) => { |
|
|
|
|
req.query.services = User.Services.STAFF; |
|
|
|
|
// console.log(req.query)
|
|
|
|
|
await User.findAll( |
|
|
|
|
{ |
|
|
|
|
where : { |
|
|
|
|
is_active: true, |
|
|
|
|
service : "staff" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
await User.list( |
|
|
|
|
req.query |
|
|
|
|
).then(result => { |
|
|
|
|
// console.log(result );
|
|
|
|
|
console.log(result ); |
|
|
|
|
res.json({ |
|
|
|
|
code: 0, |
|
|
|
|
count: req.totalRecords, |
|
|
|
@ -84,12 +92,6 @@ exports.get = async (req, res, next) => res.json({ data: User.transform(req.loca |
|
|
|
|
*/ |
|
|
|
|
exports.update = async (req, res, next) => { |
|
|
|
|
const { user } = req.locals; |
|
|
|
|
if (user.service !== "service") { |
|
|
|
|
return res.status(404).json({ |
|
|
|
|
code: 404, |
|
|
|
|
message : messages.NOT_FOUND |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return User.update( |
|
|
|
|
req.body, |
|
|
|
@ -117,12 +119,6 @@ exports.update = async (req, res, next) => { |
|
|
|
|
*/ |
|
|
|
|
exports.delete = async (req, res, next) => { |
|
|
|
|
const { user } = req.locals; |
|
|
|
|
if (user.service !== "service") { |
|
|
|
|
return res.status(404).json({ |
|
|
|
|
code: 404, |
|
|
|
|
message : messages.NOT_FOUND |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return User.update( |
|
|
|
|
{ |
|
|
|
@ -143,7 +139,6 @@ exports.delete = async (req, res, next) => { |
|
|
|
|
}).catch(ex => { |
|
|
|
|
ErrorHandler(ex, req, res, next); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
exports.getStaffPermission = async (req, res, next) => { |
|
|
|
@ -202,44 +197,3 @@ exports.active = async (req, res, next) => { |
|
|
|
|
ErrorHandler(ex, req, res, next); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
exports.addService = async (req,res,next) => { |
|
|
|
|
const {user} = req.locals; |
|
|
|
|
return User.update({ |
|
|
|
|
service: 'service' |
|
|
|
|
}, { |
|
|
|
|
where: { |
|
|
|
|
id: user.id |
|
|
|
|
} |
|
|
|
|
}).then(() => { |
|
|
|
|
res.json({ |
|
|
|
|
code: 0, |
|
|
|
|
message: messages.UPDATE_SUCCESS |
|
|
|
|
}); |
|
|
|
|
}).catch(ex => { |
|
|
|
|
ErrorHandler(ex, req, res, next); |
|
|
|
|
})
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.changePassword = async(req,res,next) => { |
|
|
|
|
const {current_password, new_password } = req.body; |
|
|
|
|
const {user} = req.locals; |
|
|
|
|
const rounds = 10; |
|
|
|
|
const new_pass = await hash(new_password, rounds);
|
|
|
|
|
return User.update( |
|
|
|
|
{password: new_pass}, |
|
|
|
|
{ |
|
|
|
|
where: { |
|
|
|
|
id: user.id |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
).then( async () => { |
|
|
|
|
res.json({
|
|
|
|
|
code: 0, |
|
|
|
|
message: messages.UPDATE_SUCCESS |
|
|
|
|
}); |
|
|
|
|
}).catch(ex => { |
|
|
|
|
ErrorHandler(ex, req, res, next); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|