back-end/app/controllers/admin_user_controller.rb
# fetch stats for admin's dashboard
fetch stats for admin's dashboard
fetch stats for admin ' s dashboard
def fetch_statistics
    user = AdminUser.find(get_logged_in_user_id)
    if user.designation == "supervisor"
      new_complaints = ComplaintStatus.where(admin_user_id: user.id, status: "pending").count
      pending_complaints = 0
      completed_complaints = ComplaintStatus.where(admin_user_id: user.id, status: "completed").count
    elsif user.designation == "ward officer"
      ward = WardOffice.find(user.municipal_id)
      new_complaints = ComplaintStatus.where(admin_user_id: user.id).count
      pending_complaints = ComplaintStatus.where(district_office_id: ward.district_office_id, ward_office_id: user.municipal_id,
                                                 category: user.designation, status: "pending").count
      completed_complaints = ComplaintStatus.where(district_office_id: ward.district_office_id, ward_office_id: user.municipal_id,
                                                   category: user.designation, status: "completed").count
    elsif user.designation == "district officer"
      new_complaints = ComplaintStatus.where(admin_user_id: user.id, status: "new").count
      pending_complaints = ComplaintStatus.where(district_office_id: user.municipal_id, status: "pending").count
      completed_complaints = ComplaintStatus.where(district_office_id: user.municipal_id, status: "completed").count
    end
    render json: {new_complaint: new_complaints, pending_complaint: pending_complaints, completed_complaint: completed_complaints}
  end
def fetch_statistics user = AdminUser . find ( get_logged_in_user_id ) if user . designation == "supervisor" new_complaints = ComplaintStatus . where ( admin_user_id : user . id , status : "pending" ) . count pending_complaints = 0 completed_complaints = ComplaintStatus . where ( admin_user_id : user . id , status : "completed" ) . count elsif user . designation == "ward officer" ward = WardOffice . find ( user . municipal_id ) new_complaints = ComplaintStatus . where ( admin_user_id : user . id ) . count pending_complaints = ComplaintStatus . where ( district_office_id : ward . district_office_id , ward_office_id : user . municipal_id , category : user . designation , status : "pending" ) . count completed_complaints = ComplaintStatus . where ( district_office_id : ward . district_office_id , ward_office_id : user . municipal_id , category : user . designation , status : "completed" ) . count elsif user . designation == "district officer" new_complaints = ComplaintStatus . where ( admin_user_id : user . id , status : "new" ) . count pending_complaints = ComplaintStatus . where ( district_office_id : user . municipal_id , status : "pending" ) . count completed_complaints = ComplaintStatus . where ( district_office_id : user . municipal_id , status : "completed" ) . count end render json : { new_complaint : new_complaints , pending_complaint : pending_complaints , completed_complaint : completed_complaints } end
fetch stats for admin's dashboard
fetch stats for admin ' s dashboard