HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
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'));
};