|
2 | 2 | from flask_jwt_extended import current_user |
3 | 3 | from sqlalchemy import asc, distinct, func, or_ |
4 | 4 |
|
5 | | -from app.api.helpers.errors import ForbiddenError, UnprocessableEntityError |
| 5 | +from app.api.helpers.errors import ForbiddenError, NotFoundError, UnprocessableEntityError |
6 | 6 | from app.api.helpers.mail import send_email |
7 | 7 | from app.api.helpers.permissions import is_coorganizer, jwt_required, to_event_id |
8 | 8 | from app.api.helpers.system_mails import MAILS, MailType |
| 9 | +from app.api.helpers.user import get_user_id_from_token, virtual_event_check_in |
9 | 10 | from app.api.helpers.utilities import group_by, strip_tags |
10 | 11 | from app.api.schema.exhibitors import ExhibitorReorderSchema |
11 | 12 | from app.api.schema.speakers import SpeakerReorderSchema |
| 13 | +from app.api.schema.virtual_check_in import VirtualCheckInSchema |
12 | 14 | from app.models import db |
13 | 15 | from app.models.discount_code import DiscountCode |
14 | 16 | from app.models.event import Event |
15 | 17 | from app.models.exhibitor import Exhibitor |
| 18 | +from app.models.microlocation import Microlocation |
| 19 | +from app.models.order import Order |
16 | 20 | from app.models.session import Session |
17 | 21 | from app.models.speaker import Speaker |
18 | 22 | from app.models.ticket_holder import TicketHolder |
@@ -216,6 +220,53 @@ def search_attendees(event_id): |
216 | 220 | return jsonify({'attendees': attendees}) |
217 | 221 |
|
218 | 222 |
|
| 223 | +@events_routes.route('/<string:event_identifier>/virtual/check-in', methods=['POST']) |
| 224 | +@jwt_required |
| 225 | +def virtual_check_in(event_identifier): |
| 226 | + """Search attendees by name or email.""" |
| 227 | + event = db.session.query(Event).filter_by(identifier=event_identifier).first() |
| 228 | + if event is None: |
| 229 | + raise NotFoundError({'source': ''}, 'event can not be found') |
| 230 | + data, errors = VirtualCheckInSchema().load(request.get_json()) |
| 231 | + if errors: |
| 232 | + raise UnprocessableEntityError( |
| 233 | + {'pointer': '/data', 'errors': errors}, 'Data in incorrect format' |
| 234 | + ) |
| 235 | + token = None |
| 236 | + if "Authorization" in request.headers: |
| 237 | + token = request.headers["Authorization"].split(" ")[1] |
| 238 | + if not token: |
| 239 | + return { |
| 240 | + "message": "Authentication Token is missing!", |
| 241 | + "data": None, |
| 242 | + "error": "Unauthorized", |
| 243 | + }, 401 |
| 244 | + user_id = get_user_id_from_token(token) |
| 245 | + if user_id is None: |
| 246 | + return {"message": "Can't get user id!", "data": None}, 404 |
| 247 | + |
| 248 | + if data.get('microlocation_id') is not None: |
| 249 | + microlocation = Microlocation.query.filter( |
| 250 | + Microlocation.id == data.get('microlocation_id') |
| 251 | + ).first() |
| 252 | + if microlocation is None: |
| 253 | + raise NotFoundError({'source': ''}, 'microlocation can not be found') |
| 254 | + |
| 255 | + orders = Order.query.filter( |
| 256 | + Order.user_id == user_id, Order.event_id == event.id |
| 257 | + ).all() |
| 258 | + |
| 259 | + orders_id = [order.id for order in orders] |
| 260 | + |
| 261 | + attendees = TicketHolder.query.filter(TicketHolder.order_id.in_(orders_id)).all() |
| 262 | + |
| 263 | + attendees_ids = [attendee.id for attendee in attendees] |
| 264 | + |
| 265 | + virtual_event_check_in(data, attendees_ids, event.id) |
| 266 | + |
| 267 | + return jsonify({'message': 'Attendee check in/out success'}) |
| 268 | + |
| 269 | + |
219 | 270 | @events_routes.route('/<string:event_identifier>/sessions/languages', methods=['GET']) |
220 | 271 | @to_event_id |
221 | 272 | def get_languages(event_id): |
|
0 commit comments