示例#1
0
class UserToken(BaseModel):
    """
    Token Model for storing JWT tokens
    """
    __tablename__ = 'user_token'
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)
    user_id = db.Column(db.INTEGER, db.ForeignKey('user.id', ondelete='CASCADE'))
    token = db.Column(db.String(1000), unique=True, nullable=False)
    refresh_token = db.Column(db.String(1000), unique=True, nullable=False)
    expired_at = db.Column(db.DateTime, nullable=False)

    def __init__(self, token, refresh_token, user_id: int):
        self.user_id = user_id
        self.token = token
        self.refresh_token = refresh_token
        self.expired_at = datetime.utcnow() + timedelta(days=365)

    def __repr__(self):
        return '<UserToken: token: {}>'.format(self.token)

    @classmethod
    def is_token_valid(cls, auth_token):
        res = cls.query.filter(cls.token == auth_token,
                               cls.expired_at >= datetime.utcnow(),
                               cls.is_deleted.is_(False)).first()
        return res if True else False

    @classmethod
    def delete_token(cls, auth_token):
        user_token = cls.query.filter_by(token=auth_token).first()
        if user_token:
            user_token.is_deleted = True
            user_token.expired_at = datetime.utcnow()
            user_token.update()
示例#2
0
class QuestionModel(BaseModel):
    __tablename__ = 'question'
    title = db.Column(db.String(100), nullable=True)
    question = db.Column(db.String(250), nullable=False)
    question_html = db.Column(db.String(250), nullable=True)
    options = db.relationship(QOptionsModel, uselist=True, lazy=True)
    is_single_choice = db.Column(db.Boolean, default=False)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    @classmethod
    def get_parser_create_new_question(cls):
        parser = reqparse.RequestParser(bundle_errors=True, trim=True)
        parser.add_argument('title', required=False, type=str)
        parser.add_argument('question', required=True, type=str)
        parser.add_argument('question_html', required=False, type=str)
        parser.add_argument('option', required=True, action='append')
        # parser.add_argument('option_icon_name', required=True, action='append')
        parser.add_argument(
            'option_icons',
            required=True,
            type=FileStorage,
            location='files',
            action='append',
            help='''option_icons length should be same as option list''')
        parser.add_argument('is_single_choice',
                            required=True,
                            type=bool,
                            default=False)
        return parser
示例#3
0
class CurrencyModel(db.Model):
    __tablename__ = 'currency'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    country = db.Column(db.String(45), nullable=False)
    currency = db.Column(db.String(45), nullable=False)
    code = db.Column(db.String(45), nullable=False)
    symbol = db.Column(db.String(45), nullable=False)
示例#4
0
class QOptionsModel(BaseModel):
    __tablename__ = 'question_option'
    question_id = db.Column(db.Integer,
                            db.ForeignKey('question.id'),
                            nullable=False)
    option = db.Column(db.String(80), nullable=False)
    option_icon = db.Column(db.String(100), nullable=False)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
示例#5
0
class FavEntityModel(BaseModel):
    __tablename__ = 'fav_entity'
    user_id = db.Column(db.ForeignKey('user.id'), nullable=False, index=True)
    entity_id = db.Column(db.String(45), nullable=False)
    entity_type = db.Column(db.INT, nullable=False, default=0)

    # product = db.relationship('ProductModel')

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
示例#6
0
class NotificaionModel(BaseModel):
    __tablename__ = 'notification'
    title = db.Column(db.String(100), nullable=False)
    body = db.Column(db.String(250), nullable=False)
    user_id = db.Column(db.Integer(),
                        db.ForeignKey('user.id', ondelete='CASCADE'),
                        unique=True)
    # sender_id = db.Column(db.Integer(), db.ForeignKey('user.id', ondelete='CASCADE'), unique=True)
    is_seen = db.Column(db.Boolean, nullable=False, default=0)
    is_viewed = db.Column(db.Boolean, nullable=False, default=0)
    type = db.Column(db.Integer, nullable=False, default=0)
    entity_id = db.Column(db.Integer, nullable=True, default=0)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    @classmethod
    def get_parser_fetch_notification(cls):
        from api.common.base.parsers import base_pagination_parser
        parser = base_pagination_parser.copy()
        return parser
示例#7
0
class IATACodeModel(BaseModel):
    __tablename__ = 'iata_code'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(90), nullable=False)
    city = db.Column(db.String(45), nullable=True)
    country = db.Column(db.String(45), nullable=False)
    iata = db.Column(db.String(4), nullable=False)
    iaco = db.Column(db.String(9), nullable=False)
    latitude = db.Column(db.Float, nullable=False)
    longitude = db.Column(db.Float, nullable=False)
    timezone = db.Column(db.String(45), nullable=False)
    dst = db.Column(db.String(45), nullable=False)

    @classmethod
    def get_parser_search(cls):
        parser = base_pagination_parser.copy()
        return parser
示例#8
0
class BookingModel(BaseModel):
    __tablename__ = 'booking'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    booking_id = db.Column(db.String(45), nullable=False)
    providerConfirmationId = db.Column(
        db.String(45),
        nullable=False)  # GDS Confirmation Number. If you call the
    # Provider, this Reference may be asked
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    # associated_record =

    hotel_name = db.Column(db.String(45), nullable=False)
    checking_date = db.Column(db.DateTime, nullable=False)
    checkout_date = db.Column(db.DateTime, nullable=False)
    number_of_guest = db.Column(db.Integer, nullable=False)
    number_of_room = db.Column(db.Integer, nullable=False)
    city = db.Column(db.String(30), nullable=False)
    address = db.Column(db.String(45), nullable=False)
    booking_status = db.Column(
        db.Integer, nullable=False,
        default=BookingStatus.CONFIRM.value)  # booking_status

    # @classmethod
    # def save_booking_info(cls, data: dict, ):
    #     booking = BookingModel(**data)

    @classmethod
    def _get_parser_hotel_booking_details(cls):
        from flask_restplus import reqparse
        parser = reqparse.RequestParser(bundle_errors=True, trim=True)
        parser.add_argument('hotel_name', type=str, required=True)
        parser.add_argument('checking_date',
                            type=str,
                            required=True,
                            help='Date Of Birth (YYYY-MM-DD)')
        parser.add_argument('checkout_date',
                            type=str,
                            required=True,
                            help='Date Of Birth (YYYY-MM-DD)')
        # parser.add_argument('number_of_guest', type=str, required=True)
        parser.add_argument('number_of_room', type=str, required=True)
        parser.add_argument('city', type=str, required=True)
        parser.add_argument('address', type=str, required=True)
        return parser

    @classmethod
    def get_parser_booking(cls):
        from flask_restplus import reqparse
        parser = BookingModel._get_parser_hotel_booking_details()
        parser.add_argument('offerId', type=str, required=True)
        guests = '''sample - [
                      {
                        "name": {
                          "title": "MR",
                          "firstName": "BOB",
                          "lastName": "SMITH"
                        },
                        "contact": {
                          "phone": "+33679278416",
                          "email": "*****@*****.**"
                        }
                      }
                    ]'''

        parser.add_argument('guests',
                            type=list,
                            required=True,
                            location='json',
                            help=guests)
        payments = '''{ "payments": [
    {
      "method": "creditCard",
      "card": {
        "vendorCode": "VI",
        "cardNumber": "4111111111111111",
        "expiryDate": "2023-01"
      }
    }
  ]}'''
        parser.add_argument('payments',
                            type=list,
                            required=False,
                            location='json',
                            help=payments)

        help = '''offerId, guests, payments and 
        optional rooms for the repartition (when used the rooms array items must match the shopping offer 
        roomQuantity)'''
        return parser