Ejemplo n.º 1
0
async def update_service(service: ServiceUpdateInput,
                         user: dict = Depends(UserMixin.authenticate_user)):
    if user["admin"]:
        try:
            service_to_update = ServiceList.get_single_serviceListById(
                service.id)
            if service_to_update:
                service_to_update.update(name=service.name,
                                         price=service.price)
                service_to_update.save(clean=True)
                service_obj = ServiceList.get_single_serviceListById(
                    service.id)
                return Fortauto.response(
                    {
                        "service": service_obj.to_json(),
                        "message": "service updated successfully"
                    },
                    status_code=status.HTTP_200_OK)
            return Fortauto.response({"message": "service not found"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
        except errors.ValidationError:
            return Fortauto.response({"message": "service does  not exist"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
    return Fortauto.response({"message": "Error validating admin credentials"},
                             status_code=status.HTTP_401_UNAUTHORIZED)
Ejemplo n.º 2
0
async def update_service(service: ServiceUpdate,
                         user: dict = Depends(UserMixin.authenticate_user)):
    if user["admin"]:
        try:
            service_to_update = Service.get_single_serviceById(
                service.serviceId)
            if service_to_update:
                service_to_update.update(**service.dict())
                service = service_to_update.save(clean=True)
                return Fortauto.response(
                    {
                        "service": service.to_json(),
                        "message": "service updated successfully"
                    },
                    status_code=status.HTTP_200_OK)
            return Fortauto.response({"message": "service  not found"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
        except errors.ValidationError:
            return Fortauto.response({"message": "service  does  not exist"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
        except Exception.__base__:
            return Fortauto.response(
                {"message": "error updating service type"},
                status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
    return Fortauto.response({"message": "Error validating admin credentials"},
                             status_code=status.HTTP_401_UNAUTHORIZED)
Ejemplo n.º 3
0
async def update_service(category: ServiceCategoryUpdateInput,
                         user: dict = Depends(UserMixin.authenticate_user)):
    if user["admin"]:
        try:
            category_to_update = ServiceCategory.get_single_service_category_ById(
                category.id)
            if category_to_update:
                category_to_update.update(name=category.name)
                category_to_update.save(clean=True)
                category_obj = ServiceCategory.get_single_service_category_ById(
                    category.id)
                return Fortauto.response(
                    {
                        "category": category_obj.to_json(),
                        "message": "Service category updated successfully"
                    },
                    status_code=status.HTTP_200_OK)
            return Fortauto.response(
                {"message": "Service category type not found"},
                status_code=status.HTTP_400_BAD_REQUEST)
        except errors.ValidationError:
            return Fortauto.response(
                {"message": "Service category type does  not exist"},
                status_code=status.HTTP_400_BAD_REQUEST)
    return Fortauto.response({"message": "Error validating admin credentials"},
                             status_code=status.HTTP_401_UNAUTHORIZED)
Ejemplo n.º 4
0
async def get_single_service(serviceId: str):
    try:
        service = ServiceList.get_single_serviceListById(serviceId)
        if service:
            return Fortauto.response({"service": service.to_json()},
                                     status_code=status.HTTP_200_OK)
        return Fortauto.response({"message": "service not found"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except errors.ValidationError:
        return Fortauto.response({"message": "service does  not exist"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 5
0
async def get_user_depositd_balance(user:dict = Depends(UserMixin.authenticate_user)):
    try:
        user_account = Deposit.get_user_account(userId=user["id"])
        if user_account:
            return Fortauto.response({"message": user_account.to_json()},
                                     status_code=status.HTTP_201_CREATED)
        return Fortauto.response({"message":"User does not have any credit account"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
    except Exception.__base__:
        return Fortauto.response({"message": "error getting user credit account"},
                                 status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 6
0
async def get_single_service(categoryId: str):
    try:
        category = ServiceCategory.get_single_service_category_ById(categoryId)
        if categoryId:
            return Fortauto.response({"category": category.to_json()},
                                     status_code=status.HTTP_200_OK)
        return Fortauto.response({"message": "Service category not found"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except errors.ValidationError:
        return Fortauto.response(
            {"message": "Service category does  not exist"},
            status_code=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 7
0
async def get_payments(user:dict = Depends(UserMixin.authenticate_user)):
    try:
        payment = Payment.get_user_payment(userId=user["id"])
        if payment:
            return Fortauto.response({"payments": [payment.to_json() for payment in payment]},
                                     status_code=status.HTTP_200_OK)
        return Fortauto.response({"message": "user does not have any payment"}, status_code=status.HTTP_400_BAD_REQUEST)
    except errors.DoesNotExist:
        return Fortauto.response({"message": "payment does not exist"}, status_code=status.HTTP_400_BAD_REQUEST)
    except Exception.__base__:
        return Fortauto.response({"message": "error getting user payments"},
                                 status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 8
0
async def get_service_type_list():
    try:
        all_service = ServiceList.get_all_serviceList()
        all_list = [service.to_json() for service in all_service]
        return Fortauto.response({"serviceList": all_list},
                                 status_code=status.HTTP_200_OK)
    except errors.ValidationError:
        return Fortauto.response({"message": "service does not exist"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except Exception.__base__:
        return Fortauto.response(
            {"message": "Error getting category type"},
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 9
0
async def get_single_payment( payment_RefNo:str, user: dict = Depends(UserMixin.authenticate_user)):
    try:
        payment = Payment.get_single_payment(payment_RefNo=payment_RefNo, userId=user["id"])
        if payment:
            return Fortauto.response({"payments": payment.to_json()},
                                     status_code=status.HTTP_200_OK)
        return Fortauto.response({"message": "payment not found"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except errors.DoesNotExist:
        return Fortauto.response({"message": "payment does not exist"}, status_code=status.HTTP_400_BAD_REQUEST)
    except Exception.__base__:
        return Fortauto.response({"message": "error getting user payment"},
                                 status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 10
0
async def activate_user(user: UpdateUserInput):
    update_user = User.find_user_with_Id(userId=user.userId)
    if update_user["active"]:
        return Fortauto.response(
            {"message": "Account had already been activated"},
            status_code=status.HTTP_400_BAD_REQUEST)
    if update_user:
        update_user.update(active=True)
        update_user.save(clean=True)
        return Fortauto.response(
            {"message": "Account was activated successfully"},
            status_code=status.HTTP_200_OK)
    return Fortauto.response({"message": "Account does not exist"},
                             status_code=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 11
0
async def create_payment(paymentDetails:UserPayment, user:dict = Depends(UserMixin.authenticate_user)):
    try:
        if paymentDetails.method.lower() == "direct":
            user_credit_account = Deposit.get_user_account(userId=user["id"])
            if user_credit_account:
                if user_credit_account >= paymentDetails.total_amount:
                    current_balance = (user_credit_account.total_amount - paymentDetails.total_amount)
                    user_credit_account.update(total_amount=current_balance, method=paymentDetails.method.lower())
                    user_credit_account.save(clean=True)
                    return Fortauto.response({"message": "new payment saved"}, status_code=status.HTTP_201_CREATED)
                return Fortauto.response({"message": "User does not sufficient balance"},
                                         status_code=status.HTTP_400_BAD_REQUEST)
            return Fortauto.response({"message":"user does not have a credit account"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
        data = {**paymentDetails.dict(), "userId": user["id"]}
        payment = Payment(**data).save(clean=True)
        if payment:
            # MAKE REQUEST TO VERIFY PAYMENT
            return Fortauto.response({"message": "new payment saved"}, status_code=status.HTTP_201_CREATED)
        return Fortauto.response({"message": "error saving new payment"}, status_code=status.HTTP_400_BAD_REQUEST)
    except errors.ValidationError:
        return Fortauto.response({"message": "error saving new payment, please try again!"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except errors.NotUniqueError:
        return Fortauto.response({"message": "payment with this reference number added already"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except Exception.__base__:
        return Fortauto.response({"message": "error saving payment"},
                                 status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 12
0
async def remove_user_deposit_account(user:dict = Depends(UserMixin.authenticate_user)):
    if user["super_admin"]:
        try:
            user_account = Deposit.get_user_account(userId=user["id"])
            if user_account:
                user_account.delete()
                return Fortauto.response({"message": "user credit account was removed"},
                                         status_code=status.HTTP_200_OK)
            return Fortauto.response({"message": "User does not have any credit account"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
        except Exception.__base__:
            return Fortauto.response({"message": "error removing user credit account"},
                                     status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
    return Fortauto.response({"message": "error validating admin"},
                             status_code=status.HTTP_401_UNAUTHORIZED)
Ejemplo n.º 13
0
async def get_service_list(user: dict = Depends(UserMixin.authenticate_user)):
    try:
        all_service = Service.objects.filter(userId=user["id"])
        all_list = [service.to_json() for service in all_service]
        return Fortauto.response({"service": all_list},
                                 status_code=status.HTTP_200_OK)
    except errors.ValidationError:
        return Fortauto.response({"message": "service does not exist"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except errors.DoesNotExist:
        return Fortauto.response({"message": "service does not exist"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except Exception.__base__:
        return Fortauto.response(
            {"message": "Error getting service"},
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 14
0
async def delete_payment(payment_RefNo: str, user: dict = Depends(UserMixin.authenticate_user)):
    if user["super_admin"]:
        try:
            payment = Payment.get_single_payment(payment_RefNo=payment_RefNo)
            if payment:
                payment.delete()
                return Fortauto.response({"message": "payment deleted successfully", "payment":payment_RefNo},
                                         status_code=status.HTTP_200_OK)
            return Fortauto.response({"message": "payment not found"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
        except errors.DoesNotExist:
            return Fortauto.response({"message": "payment does not exist"}, status_code=status.HTTP_400_BAD_REQUEST)
        except Exception.__base__:
            return Fortauto.response({"message": "error deleting payment"},
                                     status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
    return Fortauto.response({"message": "error validating admin"},
                             status_code=status.HTTP_401_UNAUTHORIZED)
Ejemplo n.º 15
0
async def get_all_user_car_details(current_user: dict = Depends(
    UserMixin.authenticate_user)):
    try:
        user = User.find_user_with_Id(current_user["id"])
        if user:
            if user.car_details:
                user_car = [userCar.to_json() for userCar in user.car_details]
                return Fortauto.response({"car_details": user_car},
                                         status_code=status.HTTP_200_OK)
            return Fortauto.response(
                {"message": "User does not have any car details"},
                status_code=status.HTTP_404_NOT_FOUND)
        return Fortauto.response({"message": "user does not exist"},
                                 status_code=status.HTTP_401_UNAUTHORIZED)
    except errors.NotUniqueError:
        return Fortauto.response(
            {"message": "car with this vin number already exists"},
            status_code=status.HTTP_400_BAD_REQUEST)
    except errors.DoesNotExist:
        return Fortauto.response({"message": "car does not exist"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except errors.ValidationError:
        return Fortauto.response({"message": "Error validating user"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except Exception.__base__:
        return Fortauto.response(
            {"message": "Error getting car car, try again"},
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 16
0
async def get_all_user_car_details(carVinNumber: str,
                                   current_user: dict = Depends(
                                       UserMixin.authenticate_user)):
    try:
        user = User.find_user_with_Id(current_user["id"])
        if user:
            user_car = user.car_details.filter(vin_number=carVinNumber).first()
            if user_car:
                user.car_details.remove(user_car)
                user.save()
                return Fortauto.response({"car_details": carVinNumber},
                                         status_code=status.HTTP_200_OK)
            return Fortauto.response(
                {"message": "car with this vin doest not exists"},
                status_code=status.HTTP_400_BAD_REQUEST)
        return Fortauto.response({"message": "user does not exist"},
                                 status_code=status.HTTP_401_UNAUTHORIZED)
    except errors.NotUniqueError:
        return Fortauto.response(
            {"message": "car with this vin number already exists"},
            status_code=status.HTTP_400_BAD_REQUEST)
    except errors.DoesNotExist:
        return Fortauto.response({"message": "car does not exist"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except errors.ValidationError:
        return Fortauto.response({"message": "Error validating user"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except Exception.__base__:
        return Fortauto.response(
            {"message": "Error adding car, try again"},
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 17
0
async def reset_password(user: PasswordResetInput):
    if user.password.strip() == user.confirm_password.strip():
        check_user = User.find_user_with_Id(user.userId)
        if check_user:
            password = UserMixin.hash_password(
                plaintext_password=user.password)
            if password:
                check_user.update(password=password)
                check_user.save(clean=True)
                return Fortauto.response(
                    {"message": "password changed successfully"},
                    status_code=status.HTTP_200_OK)
            return Fortauto.response({"message": "Error updating password"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
        return Fortauto.response({"message": "Account does not exist"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    return Fortauto.response({"message": "Password does not match"},
                             status_code=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 18
0
async def register(user: UserInput, background: BackgroundTasks):
    if User.find_user_with_email(email=user.email):
        return Fortauto.response({"message": "Account already exist"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    if user.password.strip() == user.confirm_password.strip():
        try:
            password = UserMixin.hash_password(
                user.password) if UserMixin.hash_password(
                    user.password) else None
            newUser = User(email=user.email.lower(),
                           first_name=user.first_name.lower(),
                           last_name=user.last_name.lower(),
                           phone_number=user.phone_number,
                           city=user.city.lower(),
                           state=user.state.lower(),
                           address=user.address,
                           password=password)
            newUser.save(clean=True)
            if newUser:
                background.add_task(
                    Fortauto.mailUsr,
                    email_title=f"Account activation",
                    user_email=user.email,
                    email_message=f"Welcome to {WEBSITE_NAME}, "
                    f"kindly click on the link below to activate your "
                    f"account\n\n {user.website_url}/{newUser.id}/activate")
                return Fortauto.response(
                    {
                        "message":
                        "Account created successfully,"
                        " an verification link has been sent to your email"
                    },
                    status_code=status.HTTP_201_CREATED)
            return Fortauto.response({
                "message":
                "Error Creating account, please check your details or try"
            })
        except errors.NotUniqueError:
            return Fortauto.response(
                {"message": "User with email already exist"},
                status_code=status.HTTP_400_BAD_REQUEST)

        except errors.ValidationError:
            return Fortauto.response(
                {
                    "message":
                    "Error validating details, please check your details and try again"
                },
                status_code=status.HTTP_400_BAD_REQUEST)
        except Exception.__base__:
            return Fortauto.response(
                {
                    "message":
                    "Error Creating account, please check your details or try"
                },
                status_code=status.HTTP_400_BAD_REQUEST)
    return Fortauto.response({"message": "Password is does not match"},
                             status_code=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 19
0
def getUserAccount(userId: str,
                   user: dict = Depends(UserMixin.authenticate_user)):
    try:
        if user["super_admin"]:
            user = User.find_user_with_Id(userId)
            if user:
                return userId
            return Fortauto.response({"message": "User does not exist"},
                                     status_code=status.HTTP_401_UNAUTHORIZED)
    except errors.DoesNotExist:
        return Fortauto.response({"message": "User does not exist"},
                                 status_code=status.HTTP_401_UNAUTHORIZED)
    except errors.ValidationError:
        return Fortauto.response({"message": "error removing user"},
                                 status_code=status.HTTP_401_UNAUTHORIZED)
    except Exception.__base__:
        return Fortauto.response(
            {"message": "Error removing user"},
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 20
0
async def get_single_service(serviceId: str,
                             user: dict = Depends(
                                 UserMixin.authenticate_user)):
    try:
        service = Service.get_single_serviceById(serviceId)
        if serviceId:
            return Fortauto.response({"service": service.to_json()},
                                     status_code=status.HTTP_200_OK)
        return Fortauto.response({"message": "service not found"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except errors.ValidationError:
        return Fortauto.response({"message": "service does  not exist"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except errors.DoesNotExist:
        return Fortauto.response({"message": "service does not exist"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except Exception.__base__:
        return Fortauto.response({"message": "service does not exist"},
                                 status_code=status.HTTP_404_NOT_FOUND)
Ejemplo n.º 21
0
async def get_user_account_activation_link(background: BackgroundTasks,
                                           user: GetPasswordResetLink):
    current_user = User.find_user_with_email(email=user.email)
    if current_user:
        background.add_task(
            Fortauto.mailUsr,
            email_title=f"Account activation",
            user_email=user.email,
            email_message=f"Welcome to {WEBSITE_NAME}, "
            f"kindly click on the link below to activate your "
            f"account\n\n {user.website_url}/{current_user.id}/activate")
        return Fortauto.response(
            {
                "message":
                "Account created successfully,"
                "an verification link has been sent to your email"
            },
            status_code=status.HTTP_201_CREATED)
    return Fortauto.response({"message": "Account does not exist"},
                             status_code=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 22
0
async def get_password_reset_link(background: BackgroundTasks,
                                  user: GetPasswordResetLink):
    current_user = User.find_user_with_email(email=user.email)
    if current_user:
        background.add_task(
            Fortauto.mailUsr,
            user_email=user.email,
            email_message=
            f" Good day {current_user.first_name} {current_user.last_name}, You requested for password reset, "
            f"please click\n\n "
            f"on to link below to continue \n\n {user.website_url}/{current_user.id}/password/reset",
            email_title="Password reset link")
        return Fortauto.response(
            {
                "message":
                "password reset link has been sent your email address, click it to continue."
            },
            status_code=status.HTTP_200_OK)
    return Fortauto.response({"message": "Account does not exist"},
                             status_code=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 23
0
async def delete_service(serviceId: str,
                         user: dict = Depends(UserMixin.authenticate_user)):
    if user["super_admin"]:
        try:
            deleted_to_service = Service.get_single_serviceById(serviceId)
            if deleted_to_service:
                deleted_to_service.delete()
                return Fortauto.response(
                    {"message": "service was deleted successfully"},
                    status_code=status.HTTP_200_OK)
            return Fortauto.response({"message": "service not found"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
        except errors.ValidationError:
            return Fortauto.response({"message": "service does not exist"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
        except Exception.__base__:
            return Fortauto.response(
                {"message": "Error deleting service"},
                status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
    return Fortauto.response({"message": "Error validating admin"},
                             status_code=status.HTTP_401_UNAUTHORIZED)
Ejemplo n.º 24
0
async def update_payment( payment_details:UpdatePayment, user: dict = Depends(UserMixin.authenticate_user)):
    if user["admin"] or user["super_admin"]:
        try:
            payment = Payment.get_single_payment(payment_RefNo=payment_details.payment_RefNo)
            if payment:
               if payment_details.total_amount:
                   payment.update(payment_status=payment_details.payment_status, total_amount=payment_details.total_amount)
               payment.update(payment_status=payment_details.payment_status)
               payment.save(clean=True)
               payment = Payment.get_single_payment(payment_RefNo=payment_details.payment_RefNo)
               return Fortauto.response({"payments": payment.to_json(), "message":"payment updated successfully"},
                                         status_code=status.HTTP_200_OK)
            return Fortauto.response({"message": "payment not found"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
        except errors.DoesNotExist:
            return Fortauto.response({"message": "payment does not exist"}, status_code=status.HTTP_400_BAD_REQUEST)
        except Exception.__base__:
            return Fortauto.response({"message": "error updating payment"},
                                     status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
    return Fortauto.response({"message": "error validating admin"},
                             status_code=status.HTTP_401_UNAUTHORIZED)
Ejemplo n.º 25
0
async def create__deposit(deposit_details:UserDeposit, user:dict = Depends(UserMixin.authenticate_user)):
    try:
        ## MAKE A REQUEST TO VERIFY PAYMENT with payment_ref
        user_account = Deposit.get_user_account(userId=user["id"])
        if user_account:
            current_balance = (user_account.total_amount + deposit_details.total_amount)
            user_account.update(total_amount=current_balance)
            user_account.save(clean=True)
            return Fortauto.response({"message": f"You account credited with ₦{deposit_details.total_amount}"},
                                     status_code=status.HTTP_201_CREATED)
        deposit = Deposit(total_amount=deposit_details.total_amount, userId=user["id"]).save(clean=True)
        if deposit:
            return Fortauto.response({"message":f"You account credited with ₦{deposit_details.total_amount}"},
                                     status_code=status.HTTP_201_CREATED)
        return Fortauto.response({"message":"error making deposit"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
    except errors.ValidationError:
        return Fortauto.response({"message": "error validating payment details"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except Exception.__base__:
        return Fortauto.response({"message": "error making depositing"},
                                 status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 26
0
def loginUserAccount(userIn: UserLoginInput, response: Response) -> Response:
    user = User.find_user_with_email(email=userIn.email)
    if user:
        if user.active:
            if UserMixin.check_password(userIn.password, user.password):
                encode_jwt_access, encode_jwt_refresh = UserMixin.JwtEncoder(
                    user=user.to_json())
                if encode_jwt_access and encode_jwt_refresh:
                    response.set_cookie(
                        key="refresh_token",
                        value=encode_jwt_refresh,
                        httponly=True,
                        max_age=172800,
                        expires=172800,
                    )

                    SuccessResponseData = {
                        "user": user.to_json(indent=4),
                        "message": "logged in successfully",
                        "access_token": encode_jwt_access,
                        "access_token_type": "Bearer",
                        "expires": "2 days",
                    }
                    return Fortauto.response(SuccessResponseData,
                                             status_code=status.HTTP_200_OK)
            ErrorResponseData = {"message": "Password does not match"}
            return Fortauto.response(ErrorResponseData,
                                     status_code=status.HTTP_401_UNAUTHORIZED)

        ErrorResponseData = {
            "message": "Email was sent to you, please verify your email"
        }
        return Fortauto.response(ErrorResponseData,
                                 status_code=status.HTTP_401_UNAUTHORIZED)

    ErrorResponseData = {"message": "Account does not exist"}
    return Fortauto.response(ErrorResponseData,
                             status_code=status.HTTP_401_UNAUTHORIZED)
Ejemplo n.º 27
0
async def create_service(newItems: ServiceListInput,
                         user: dict = Depends(UserMixin.authenticate_user)):
    if user["admin"]:
        addToList = ServiceList(**newItems.dict())
        try:
            if addToList:
                addToList.save(clean=True)
                return Fortauto.response({"service": addToList.to_json()},
                                         status_code=status.HTTP_201_CREATED)
        except errors.ValidationError:
            return Fortauto.response(
                {"message": "error validating new category type"},
                status_code=status.HTTP_400_BAD_REQUEST)
        except errors.NotUniqueError:
            return Fortauto.response({"message": "Service already exists"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
        except Exception.__base__:
            return Fortauto.response(
                {"message": "error adding new category, please try again"},
                status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)

    return Fortauto.response({"message": "Error validating admin credentials"},
                             status_code=status.HTTP_401_UNAUTHORIZED)
Ejemplo n.º 28
0
async def create_service(newItems: ServiceInput,
                         user: dict = Depends(UserMixin.authenticate_user)):
    try:
        new_service = Service(userId=user["id"],
                              car_type=newItems.car_type,
                              service_type=newItems.service_type,
                              additional_notes=newItems.additional_notes,
                              quantity=newItems.quantity,
                              priority=newItems.priority,
                              date=newItems.date)
        if new_service:
            new_service.save(clean=True)
            return Fortauto.response({"service": new_service.to_json()},
                                     status_code=status.HTTP_201_CREATED)
    except errors.ValidationError:
        return Fortauto.response({"message": "error validating new service"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except errors.NotUniqueError:
        return Fortauto.response({"message": "Service already exists"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except Exception.__base__:
        return Fortauto.response(
            {"message": "error adding new service, please try again"},
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 29
0
async def add_user_car_details(car: CarDetail,
                               current_user: dict = Depends(
                                   UserMixin.authenticate_user)):
    try:
        user = User.find_user_with_Id(current_user["id"])
        if user:
            if not user.car_details:
                user.car_details.create(**car.dict())
                user.save(clean=True)
                return Fortauto.response(
                    {"message": "car details added successfully"},
                    status_code=status.HTTP_201_CREATED)
            user_car = user.car_details.filter(vin_number=car.vin_number)
            if not user_car:
                user.car_details.create(**car.dict())
                user.save(clean=True)
                return Fortauto.response(
                    {"message": "car details added successfully"},
                    status_code=status.HTTP_201_CREATED)
            return Fortauto.response({"message": "car already exists"},
                                     status_code=status.HTTP_400_BAD_REQUEST)

        return Fortauto.response({"message": "user does not exist"},
                                 status_code=status.HTTP_401_UNAUTHORIZED)
    except errors.NotUniqueError:
        return Fortauto.response(
            {"message": "car with this vin number already exists"},
            status_code=status.HTTP_400_BAD_REQUEST)
    except errors.DoesNotExist:
        return Fortauto.response({"message": "car does not exist"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except errors.ValidationError:
        return Fortauto.response({"message": "Error validating user"},
                                 status_code=status.HTTP_400_BAD_REQUEST)
    except Exception.__base__:
        return Fortauto.response(
            {"message": "Error adding car, try again"},
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 30
0
async def update_user_deposit_account(deposit_details:UpdateDeposit, user:dict = Depends(UserMixin.authenticate_user)):
    if user["super_admin"]:
        try:
            user_account = Deposit.get_user_account(userId=deposit_details.userId)
            if user_account:
                if deposit_details.method.lower() == "credit" and deposit_details.total_amount > 0 :
                    current_balance = (user_account.total_amount + deposit_details.total_amount)
                    user_account.update(total_amount=current_balance)
                    user_account.save(clean=True)
                    return Fortauto.response({"message": f"Your account was credited with ₦{deposit_details.total_amount}"},
                                             status_code=status.HTTP_200_OK)
                elif deposit_details.method.lower() == "debit"  and deposit_details.total_amount > 0:
                    if user_account.total_amount < deposit_details.total_amount:
                        balance = (deposit_details.total_amount - user_account.total_amount)
                        return Fortauto.response({"message":f"user does not have sufficient amount, required ₦{balance} to complete transaction"},
                                                 status_code=status.HTTP_400_BAD_REQUEST)
                    current_balance = (user_account.total_amount - deposit_details.total_amount)
                    user_account.update(total_amount=current_balance)
                    user_account.save(clean=True)
                    return Fortauto.response(
                        {"message": f"Your account was debited with ₦{deposit_details.total_amount}"},
                        status_code=status.HTTP_200_OK)
                if deposit_details.method.lower() != "debit" and deposit_details.method != "credit":
                    return Fortauto.response(
                        {"message": "deposit method not recognized"},
                        status_code=status.HTTP_400_BAD_REQUEST)
                elif deposit_details.total_amount <= 0:
                    return Fortauto.response({"message": "you can only deposit amount greater than ₦100 "},
                                             status_code=status.HTTP_400_BAD_REQUEST)
        except errors.ValidationError:
            return Fortauto.response({"message": "error validating payment details"},
                                     status_code=status.HTTP_400_BAD_REQUEST)
        except Exception.__base__:
            return Fortauto.response({"message": "error updating user credit account"},
                                     status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
    return Fortauto.response(
                        {"message": f"Error validating admin"},
                        status_code=status.HTTP_401_UNAUTHORIZED)