def add_manager(employee_id: str, manager_id: str) -> wrappers.Response: try: authClaims = checkPermission(request) manager = Manager(authClaims["uid"]) except Exception: return failure(code=401) managerAdded = manager.assignOtherManager(employee_uid=employee_id, manager_uid=manager_id) return success(code=200) if managerAdded is True else failure(code=400)
def sign_user() -> wrappers.Response: """ User SIGN in token verification and cookie creation """ payload = request.json idToken = payload["idToken"] try: authClaims = auth.verify_id_token(idToken) except Exception: return failure(code=401) expiry = timedelta(days=7) timeLimitedAuthToken = auth.create_session_cookie(idToken, expires_in=expiry) userDetails = { "access_token": timeLimitedAuthToken, "email": authClaims["email"] } response = success("user_details", userDetails, 200) response.set_cookie('accessToken', timeLimitedAuthToken, secure=True, domain="awesome-erp.github.io", httponly=True, samesite="Strict") return response
def self_remove_manager(user_id: str) -> wrappers.Response: try: authClaims = checkPermission(request) manager = Manager(authClaims["uid"]) except Exception: return failure(code=401) manager.removeSelfAsManager(employee_uid=user_id) return success(code=200)
def get_jr_managers() -> wrappers.Response: try: authClaims = checkPermission(request) manager = Manager(authClaims["uid"]) except Exception: return failure(code=401) managers = manager.getAllJrManagers() return success("managers", managers, 200)
def get_unassigned_employees() -> wrappers.Response: try: authClaims = checkPermission(request) manager = Manager(authClaims["uid"]) except Exception: return failure(code=401) employees = manager.getUnassignedEmployees() return success("employees", employees, 200)
def filters() -> wrappers.Response: payload = request.json try: authClaims = checkPermission(request) manager = Manager(authClaims["uid"]) except Exception: return failure(code=401) employees = manager.filters(**payload) return success("employees", employees, code=200)
def transaction(userId: str) -> wrappers.Response: payload = request.json try: authClaims = checkPermission(request) manager = Manager(authClaims["uid"]) except Exception: return failure(code=401) manager.markTransaction(userID=userId, transaction=payload) return success(code=200)
def mark_request() -> wrappers.Response: payload = request.json try: authClaims = checkPermission(request) manager = Manager(authClaims["uid"]) except Exception: return failure(code=401) manager.markRequest(reqID=payload["reqID"], marked=payload["marked"]) return success(code=200)
def info() -> wrappers.Response: """ Get User Info """ try: authClaims = checkPermission(request) except Exception: return failure(code=401) user = User(authClaims["uid"]) userData = user.getData() return success("user_data", userData, 200)
def update_data() -> wrappers.Response: """ Update the data that is only accessable to user """ payload = request.json try: authClaims = checkPermission(request) except Exception: return failure(code=401) user = User(authClaims["uid"]) user.updateEditableData(payload) return success(code=200)
def get_request(requestType: str, markedAs: str) -> wrappers.Response: try: authClaims = checkPermission(request) manager = Manager(authClaims["uid"]) except Exception: return failure(code=401) reqs = [] if markedAs == "pending": reqs = manager.getPendingRequests(reqType=requestType) else: reqs = manager.getMarkedRequests(reqType=requestType, markedAs=markedAs) return success(requestType, reqs, 200)
def set_user_data() -> wrappers.Response: """ Route to set user data for 1st time """ payload = request.json try: authClaims = checkPermission(request) except Exception: return failure(code=401) user = User(authClaims["uid"]) payload["email"] = authClaims["email"] user.setData(payload) return success("user_id", user.uid, 200)
def create_leave() -> wrappers.Response: """ Allows User to request for leaves Input Expected(All Compulsory) ------------------------------ { "leave_start": "yyyy-mm-dd", "leave_end": "yyyy-mm-dd", "created": "yyyy-mm-dd", "description": "Some Random reason" } """ payload = request.json try: authClaims = checkPermission(request) except Exception: return failure(code=401) user = User(authClaims["uid"]) try: user.createLeaveRequest(payload) except Exception as e: return failure("error", str(e), code=400) return success(code=200)
def get_request(reqType: str, markedAs: str) -> wrappers.Response: """ Get the details of the request URL_PARAMS ---------- reqType: str can be one of "leave"|"loan"|"raise" markedAs: str can be one of "pending"|"accept"|"reject" """ try: authClaims = checkPermission(request) except Exception: return failure(code=401) user = User(authClaims["uid"]) req = user.getRequests(reqType=reqType, markedAs=markedAs) return success(reqType, req, 200)
def create_loan_raise_request() -> wrappers.Response: """ Allows User to request for loan or raise Input Expected(All Compulsory) ------------------------------ { "type": "loan/raise", "amount": 100.10, "created": "yyyy-mm-dd", "description": "Some Random reason" } """ payload = request.json try: authClaims = checkPermission(request) except Exception: return failure(code=401) user = User(authClaims["uid"]) user.createLoanRaiseRequest(payload) return success(code=200)
def update_employee_data() -> wrappers.Response: """ Update the data that is only accessable to manager Input Expected(All Optional) ---------------------------- { "name": "Name Name", "dob": "yyyy-mm-dd", "phone": "+100 1001001001", "email": "*****@*****.**", "personal_email": "*****@*****.**" } """ payload = request.json try: authClaims = checkPermission(request) manager = Manager(authClaims["uid"]) except Exception: return failure(code=401) manager.updateEmployeeData(userID=payload["user_id"], data=payload) return success(code=200)