def post(self, request): try: telegram_id = request.data["telegram_id"] company_guid = request.data["company"] employee = Employee.objects.filter(telegram_id=telegram_id, company__guid=company_guid) if not employee: return get_success_response({"status": "no user"}) role = employee[0].role return get_success_response({"role": role}) except: return get_error_response(500)
def post(self, request): try: telegram_id = request.data["telegram_id"] company_guid = request.data["company"] manager = Employee.objects.filter(telegram_id=telegram_id, company__guid=company_guid)[0] subordinates = ManagerToWorker.objects.filter(manager=manager, worker__company=manager.company) data = {"users": []} for subordinate in subordinates: last_data = HealthData.objects.filter(employee=subordinate.worker) if not last_data: data["users"].append({"initials": subordinate.worker.initials, "last_temp": None }) else: last_data = last_data.last() data["users"].append({ "initials": subordinate.worker.initials, "last_temp": last_data.temperature, "date": last_data.date.timestamp() }) return get_success_response(data) except: return server_error_response()
def post(self, request): try: telegram_id = request.data["telegram_id"] company_guid = request.data["company"] temperature = float(request.data["temperature"]) employee = Employee.objects.filter(telegram_id=telegram_id, company__guid=company_guid)[0] HealthData.objects.create(employee=employee, date=datetime.now(), temperature=temperature) return get_success_response({"status": "ok"}) except: return get_error_response(500)
def post(self, request): try: telegram_id = request.data["telegram_id"] users = Employee.objects.filter(telegram_id=telegram_id) companies = [] for user in users: companies.append({ "guid": user.company.guid, "name": user.company.name }) return get_success_response({"companies": companies}) except: return server_error_response()
def post(self, request): try: data = request.data employees = data["employees"] guid_list = list(employees.keys()) employees_bd = Employee.objects.filter(guid__in=guid_list) for employee in employees_bd: employee.telegram_id = employees[employee.guid] employee.save() return get_success_response() except: return server_error_response()
def post(self, request): try: data = request.data password = data["password"] username = data["username"] secret_key = data["secret_key"] if secret_key != config["Admin"]["secret_key"]: return server_error_response() admin = User.objects.create_superuser(password=password, username=username) admin.save() return get_success_response() except Exception as er: print(er) return server_error_response()
def post(self, request): try: telegram_id = request.data["telegram_id"] company_guid = request.data["company"] manager = Employee.objects.filter(telegram_id=telegram_id, company__guid=company_guid)[0] subordinates = ManagerToWorker.objects.filter( manager=manager, worker__company=manager.company) data = {"users": []} for subordinate in subordinates: data["users"].append({ "initials": subordinate.worker.initials, "tg_username": subordinate.worker.tg_username, "telegram_id": subordinate.worker.telegram_id }) return get_success_response(data) except: return server_error_response()
def get(self, request): try: synchronize_data() return get_success_response() except: return server_error_response()