export default async function userInfo({
  pg, user = {},
}) {
  const { uid } = user || {};

  if (!uid) {
    return { message: 'access restricted', status: 403 };
  }

  const data = await pg.query(`select user_name, sur_name, father_name, user_rnokpp, user_type, email, login from admin.users 
  where uid=$1`, [uid]).then((res) => res.rows?.[0] || {});

  const { notifications = 0 } = await pg.query(`select count(*)::int as notifications from crm.notifications 
    where addressee_id=$1 and read is not true`, [uid]).then((res) => res.rows?.[0] || {});
  return { uid, ...data, notifications };

}
