File: //home/arjun/projects/good-life-be/api/User/controller.js
import { failedResponse, goodResponse } from '../../helper/response.js';
import {
changePassService,
listAllUsers,
profile,
profileImageRemove,
profileUpdate,
userStatusUpdate,
} from './service.js';
export const changePassword = async (req, res) => {
await changePassService(req.body, req.user.id);
return res.json(goodResponse({}, 'Password changed successfully'));
};
export const getProfile = async (req, res) => {
const user = await profile(req.user.id);
if (!user) {
res.json(
failedResponse('User not found, please check the id', 404, 'Not found')
);
}
return res.json(goodResponse({ data: user }, 'Profile fetched successfully'));
};
export const editProfile = async (req, res) => {
await profileUpdate(req.body, req?.files?.image, req.user.id);
return res.json(goodResponse({}, 'Profile updated successfully'));
};
export const removeProfileImage = async (req, res) => {
await profileImageRemove(req.user.id);
return res.json(goodResponse({}, 'Profile image removed successfully'));
};
export const statusUpdate = async (req, res) => {
const data = await userStatusUpdate(req.params.id, req.query);
return res.json(goodResponse({}, data.message));
};
export const getAllUsers = async (req, res) => {
const data = await listAllUsers(req.query);
res.json(goodResponse({ data }, 'All users fetched successfully'));
};