|
@@ -84,6 +84,24 @@ const logOut = async (req, res, next) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+const online = async (req, res, next) => {
|
|
|
+ try {
|
|
|
+ const id = req.user.id;
|
|
|
+ const user = await UserModel.findById(id);
|
|
|
+ if (!user)
|
|
|
+ return res.status(401).json({
|
|
|
+ status: 'error',
|
|
|
+ code: 401,
|
|
|
+ data: 'UNAUTHORIZED',
|
|
|
+ message: 'Invalid credentials',
|
|
|
+ });
|
|
|
+ await UserModel.updateUser(id, { online: new Date() });
|
|
|
+ return res.status(204).json({});
|
|
|
+ } catch (e) {
|
|
|
+ next(e);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
const getCurrent = async (req, res, next) => {
|
|
|
try {
|
|
|
const user = req.user;
|
|
@@ -94,6 +112,8 @@ const getCurrent = async (req, res, next) => {
|
|
|
data: 'UNAUTHORIZED',
|
|
|
message: 'Invalid credentials',
|
|
|
});
|
|
|
+ const id = req.user.id;
|
|
|
+ await UserModel.updateUser(id, { online: true });
|
|
|
return res.status(200).json({
|
|
|
status: 'success',
|
|
|
code: 200,
|
|
@@ -154,6 +174,7 @@ module.exports = {
|
|
|
createNewUser,
|
|
|
logIn,
|
|
|
logOut,
|
|
|
+ online,
|
|
|
getCurrent,
|
|
|
updateCredentials,
|
|
|
updateAvatar,
|