Beispiel #1
0
def save_new_customer(data):
    customer = Customer.query.filter(
        or_(Customer.fuid_email == data["fuid_email"],
            Customer.fuid_phone == data["fuid_phone"])).first()
    if not customer:
        new_customer = Customer(name=data['name'],
                                fuid_email=data['fuid_email'],
                                fuid_phone=data['fuid_phone'],
                                contact=data['contact'],
                                address=data['address'],
                                longitude=data['longitude'],
                                latitude=data['latitude'],
                                url=data['url'],
                                geo='POINT({} {})'.format(
                                    data['longitude'], data['latitude']),
                                location=data['location'])

        save_changes(new_customer)
        return new_customer
    else:
        response_object = {
            'status': 'fail',
            'message': 'Customer already exists. Please Log in.',
        }
        return response_object, 409
def save_new_customer(data):
    response = validate(data)
    if response:
        return response  # not validated

    customer = Customer.query.filter_by(name=data['name']).first()
    if not customer:
        new_customer = Customer(name=data['name'],
                                email=data['email'],
                                phone=data['phone'],
                                street=data['street'],
                                city=data['city'],
                                country=data['country'],
                                province=data['province'],
                                postal_code=data['postal_code'],
                                point_of_contact=data['point_of_contact'])
        save_changes(new_customer)
        db.session.refresh(new_customer)
        data['id'] = new_customer.id  #get id of newly added data

        return data, 201
    else:
        response_object = {
            'status':
            'fail',
            'message':
            'Customer with the same name already exists. Please update current customer profile.',
        }
        return response_object, 409
Beispiel #3
0
def save_new_customer(data):
    user_account = UserAccount.query.filter_by(
        UserName=data['username']).first()
    if not user_account:
        try:
            password = '******'
            user_account_id = UserAccountService.save_user_account(
                UserAccount(UserName=data['username'], password=password))
            payment_account_id = PaymentAccountService.save_payment_account(
                PaymentAccount(
                    Amount=0,  # init amount = 0,
                    NumberPaymentAccount=randint(1000000000, 9999999999)))
            if user_account_id and payment_account_id:
                role = {
                    "customer":
                    'customer' in data['role'] and data['role']['customer']
                    or False,
                    'employee':
                    'employee' in data['role'] and data['role']['employee']
                    or False,
                    'admin':
                    'admin' in data['role'] and data['role']['admin'] or False,
                    'any':
                    True
                }
                new_customer = Customer(CustomerName=data['customername'],
                                        UserAccountId=user_account_id,
                                        PaymentAccount=payment_account_id,
                                        Nickname=data['nickname'],
                                        Phone=data['phone'],
                                        Email=data['email'],
                                        Address=data['address'],
                                        Gender=data["gender"],
                                        Role=json.JSONEncoder().encode(role))
                save_changes(new_customer)
                # response_object = {
                #     'status' : 'success',
                #     'message': 'Success create customer'
                # }
                return ResponseService().response('success', 200, data), 201
            else:
                response_object = {
                    'status':
                    'fail',
                    'message':
                    'Create payment_account and user_account fail. Please try again'
                }
                return response_object, 409
        except:
            db.session.rollback()

        finally:
            db.session.close()
    else:
        response_object = {
            'status': 'fail',
            'message': 'Customer already exists. Please login'
        }
        return response_object, 409
Beispiel #4
0
 def test_encode_auth_token(self):
     customer = Customer(customer_id='1',
                         username='******',
                         password='******',
                         firstname='johnny',
                         lastname='solomon',
                         contact_number='09123456789',
                         gender='gay')
     db.session.add(customer)
     db.session.commit()
     auth_token = customer.encode_auth_token(customer.customer_id)
     self.assertTrue(isinstance(auth_token, bytes))
Beispiel #5
0
def setup_customer(db):
    # customer
    customer = Customer(name='test name',
                        email='*****@*****.**',
                        phone='test',
                        street="test",
                        city="test",
                        country="test",
                        province="test",
                        postal_code="test",
                        point_of_contact="test")
    db.session.add(customer)
    db.session.commit()
def save_new_customer(data):
    customer = Customer.query.filter_by(email=data['email']).first()
    if not customer:
        new_customer = Customer(email=data['email'],
                                phone_number=data['phone_number'],
                                password=data['password'],
                                customer_name=data['customer_name'],
                                registered_on=datetime.datetime.utcnow())
        save_changes(new_customer)
        response_object = {
            'status': 'success',
            'message': 'Successfully registered.'
        }
        return generate_token(new_customer)
    else:
        response_object = {
            'status': 'fail',
            'message': 'Email already exists. Please Log in.',
        }
        return response_object, 409
Beispiel #7
0
def upsert_customer(data):
    customer = None

    if 'id' in data and data['id'] != '00000000-0000-0000-0000-000000000000':
        customer = Customer.query.filter_by(id=data['id']).first()

    if not customer:
        new_customer = Customer(contact=data['contact'],
                                name=data['name'],
                                description=data['description'],
                                created_date=datetime.datetime.utcnow(),
                                status=data['status'][0].lower() +
                                data['status'][1:])
        save_changes(new_customer)
        return new_customer, 201
    else:
        customer.contact = data['contact']
        customer.name = data['name']
        customer.description = data['description']
        customer.status = data['status'][0].lower() + data['status'][1:]
        save_changes(customer)
        return customer, 200