def post(self, request): try: company = Company.objects.filter( guid=get_user(request.data["session"]))[0] # Here we filter the employees only within one company: employee = Employee.objects.filter(guid=request.data["employee"], company=company) if not employee: return validate_response( { "status": "error", "reason": "noEmployee" }, res_schema) else: employee = employee[0] employee.delete() company.employees_count -= 1 company.save() return validate_response({"status": "ok"}, res_schema) except: return server_error_response()
def post(self, request): try: employee_data = request.data["employeeData"] initials = employee_data["initials"] tg_username = employee_data["tgUsername"] role = employee_data["role"] company = Company.objects.filter(guid=get_user(request.data["session"]))[0] # Here we check the uniqueness of the tg_username only within one company: if Employee.objects.filter(tg_username=tg_username, company=company): return validate_response({ "status": "error", "reason": "usedTgAccount" }, res_schema) manager = None if role == "worker": attached_manager_guid = employee_data["attachedManager"] if attached_manager_guid is not None: manager = Employee.objects.filter(guid=attached_manager_guid, company=company) if not manager: return validate_response({ "status": "error", "reason": "noEmployee" }, res_schema) manager = manager[0] if manager.role != "manager": return validate_response({ "status": "error", "reason": "wrongRoles" }, res_schema) employee = Employee.objects.create( guid=str(uuid.uuid4()), initials=initials, tg_username=tg_username, role=role, company=company) send_new_employees([employee]) if role == "worker" and manager is not None: ManagerToWorker.objects.create(manager=manager, worker=employee) company.employees_count += 1 company.save() return validate_response({"status": "ok"}, res_schema) except Exception as err: print(err) return server_error_response()
def post(self, request): try: session = request.data["session"] company = Company.objects.filter(guid=get_user(session))[0] return validate_response({ "companyName": company.name, "licenceActive": get_active_licence_pack(company) is not None }, res_schema) except: return server_error_response()
def post(self, request): try: company = Company.objects.filter(guid=get_user(request.data["session"]))[0] # Here we get the employees from the database: employees = [] if request.data.get("employees") is None: employees = Employee.objects.filter(company=company) else: employees_guids = request.data["employees"] for employee_guid in employees_guids: employee = Employee.objects.filter(guid=employee_guid, company=company) if employee: employees.append(employee[0]) # Here we process the database output and pack the employees data: employees_data = [] for employee in employees: attached_manager = None if employee.role == "worker": manager = ManagerToWorker.objects.filter(worker=employee) if manager: attached_manager = manager[0].manager.guid employee_data = { "initials": employee.initials, "tgUsername": employee.tg_username, "role": employee.role } if employee.role == "worker": employee_data.update({"attachedManager": attached_manager}) employees_data.append({ "employee": employee.guid, "employeeData": employee_data }) return validate_response({ "status": "ok", "employeesData": employees_data }, res_schema) except: return server_error_response()
def post(self, request): try: company = Company.objects.filter(guid=get_user(request.data["session"]))[0] employees_guids = Employee.objects.filter(company=company) employees = [] for employee in employees_guids: employees.append(employee.guid) return validate_response({ "status": "ok", "employees": employees }, res_schema) except: return server_error_response()
def post(self, request): try: session = request.data["session"] company = Company.objects.filter(guid=get_user(session))[0] licences_packs = Licence.objects.filter(company=company) active_licence_pack = get_active_licence_pack(company) if active_licence_pack: active_licence_pack = active_licence_pack.guid licence_packs_data = [] for licence_pack in licences_packs: licence_pack_guid = licence_pack.guid start_time = unix_time_millis( datetime.datetime.utcfromtimestamp( licence_pack.start_time.timestamp())) end_time = unix_time_millis( datetime.datetime.utcfromtimestamp( licence_pack.end_time.timestamp())) licence_packs_data.append({ "licencePack": str(licence_pack_guid), "startTime": start_time, "endTime": end_time, "employeesCount": licence_pack.employees_count }) return validate_response( { "serverTime": unix_time_millis(datetime.datetime.utcnow()), "activeLicencePack": active_licence_pack, "licencePacksData": licence_packs_data }, res_schema) except: return server_error_response()
def post(self, request): try: company = Company.objects.filter(guid=get_user(request.data["session"]))[0] return validate_response({"employeesCount": company.employees_count}, res_schema) except: return server_error_response()
def post(self, request): try: employee_guid = request.data["employee"] employee_data = request.data["employeeData"] initials = employee_data["initials"] tg_username = employee_data["tgUsername"] role = employee_data["role"] company = Company.objects.filter(guid=get_user(request.data["session"]))[0] # Here we filter the employees only within one company: employee = Employee.objects.filter(guid=employee_guid, company=company) if not employee: return validate_response({ "status": "error", "reason": "noEmployee" }, res_schema) else: employee = employee[0] employee_with_same_tg_username = \ Employee.objects.filter(tg_username=tg_username, company=company) if employee_with_same_tg_username and employee_with_same_tg_username[0].guid != employee.guid: return validate_response({ "status": "error", "reason": "usedTgAccount" }, res_schema) # processing change employee role: manager -> worker if employee.role == "manager" and role == "worker": attached_workers = ManagerToWorker.objects.filter(manager=employee) if attached_workers: for worker in attached_workers: worker.delete() # processing change employee role: worker -> manager if employee.role == "worker" and role == "manager": attached_managers = ManagerToWorker.objects.filter(worker=employee) # Here we expect only one manager. if attached_managers: for manager in attached_managers: manager.delete() employee.initials = initials employee.tg_username = tg_username employee.role = role # reattaching worker to the manager: if role == "worker": attached_manager_guid = employee_data["attachedManager"] manager = None if attached_manager_guid is not None: manager = Employee.objects.filter(guid=attached_manager_guid) if not manager: return validate_response({ "status": "error", "reason": "noEmployee" }, res_schema) manager = manager[0] if manager.role != "manager": return validate_response({ "status": "error", "reason": "wrongRoles" }, res_schema) attached_managers = ManagerToWorker.objects.filter(worker=employee) for attached_manager in attached_managers: attached_manager.delete() if manager is not None: ManagerToWorker.objects.create(manager=manager, worker=employee) employee.save() send_new_employees([employee]) return validate_response({"status": "ok"}, res_schema) except: return server_error_response()