Example #1
0
def create_buy_in():

    body = request.get_json()
    check_params(body, 'flight_id', 'chips', 'table', 'seat')

    id = int(get_jwt()['sub'])

    prof = Profiles.query.get(id)
    if not prof:
        raise APIException('User not found', 404)

    buyin = Buy_ins(user_id=id,
                    flight_id=body['flight_id'],
                    chips=body['chips'],
                    table=body['table'],
                    seat=body['seat'])
    db.session.add(buyin)
    db.session.commit()

    name = prof.nickname if prof.nickname else f'{prof.first_name} {prof.last_name}'

    # Get the latest entry by checking the created_at
    buyin = Buy_ins.query.filter_by(user_id=id,
                                    flight_id=body['flight_id'],
                                    chips=body['chips'],
                                    table=body['table'],
                                    seat=body['seat']).first()

    return jsonify({**buyin.serialize(), "name": name}), 200
Example #2
0
    def create_buy_in(user_id):

        body = request.get_json()
        check_params(body, 'flight_id', 'chips', 'table', 'seat')

        prof = Profiles.query.get(user_id)

        buyin = Buy_ins(user_id=user_id,
                        flight_id=body['flight_id'],
                        chips=body['chips'],
                        table=body['table'],
                        seat=body['seat'])
        db.session.add(buyin)
        db.session.commit()

        name = prof.nickname if prof.nickname else f'{prof.first_name} {prof.last_name}'

        buyin = Buy_ins.query.filter_by(user_id=user_id,
                                        flight_id=body['flight_id'],
                                        chips=body['chips'],
                                        table=body['table'],
                                        seat=body['seat']).order_by(
                                            Buy_ins.id.desc()).first()

        return jsonify({**buyin.serialize(), "name": name}), 200