示例#1
0
    def create_skill(cls, skill):
        # import pdb; pdb.set_trace()
        # print(skill)
        if 'name' not in skill:
            raise InvalidData('name is not provided')

        return cls(**skill)
示例#2
0
    def sanitize_company(cls, company):
        error = ''
        if 'name' not in company:
            error += 'name not provided'
        if error:
            raise InvalidData(error)

        return company
示例#3
0
    def sanitize_job(cls, job):
        error = ''
        if 'company_id' not in job:
            error = 'company not provided'
        if 'end_date' not in job:
            error += ' end_date not provided'
        if 'start_date' not in job:
            error = ' start date not provided'

        if error:
            raise InvalidData(error)

        return job
示例#4
0
    def set_job(cls, job={}):
        job = cls.sanitize_job(job)
        job['start_date'] = datetime.fromisoformat(job['start_date'])
        job['end_date'] = datetime.fromisoformat(job['end_date'])

        company = Company.get_company(job.get('company_id'))

        if company:
            new_job = cls(**job)
            db.session.add(new_job)
            db.session.commit()
            return cls.serialize_job(new_job)
        else:
            raise InvalidData('Invalid data')
示例#5
0
    def sanitize_user(cls, user):
        error = ''
        if 'email' not in user:
            error += 'email not provided'
        if 'first_name' not in user:
            error += 'first name is not provided'
        if 'last_name' not in user:
            error += 'last name is not provided'
        if 'password' not in user:
            error += 'password is not provided'

        if error:
            raise InvalidData(error)

        return user
示例#6
0
    def sanitize_accomplishment(cls, accomplishment):
        error = ''
        if 'rank' not in accomplishment:
            error += 'rank not provided'
        if 'job_id' not in accomplishment:
            error += ' job_id not provided'
        if 'skills' not in accomplishment:
            error += ' skills not provided'
        if 'description' not in accomplishment:
            error += ' description not provided'

        if error:
            raise InvalidData(error)

        return accomplishment
示例#7
0
    def create_user(user):
        user = User.sanitize_user(user)
        stored_user = User.query.filter_by(email=user.get('email')).first()
        if stored_user:
            raise InvalidData('User with this email already exists')
        else:
            first_name = user.get('first_name')
            last_name = user.get('last_name')
            email = user.get('email')
            password = user.get('password')

            new_user = User(first_name=first_name,
                            last_name=last_name,
                            email=email)
            new_user.set_password(password)

            db.session.add(new_user)
            db.session.commit()

            serialized_user = User.serialize_user(new_user)
            return serialized_user
示例#8
0
    def create_accomplishment(cls, accomplishment):
        # sanitize accomplishment
        accomplishment = cls.sanitize_accomplishment(accomplishment)
        description = accomplishment.get('description')
        rank = accomplishment.get('rank')
        job_id = accomplishment.get('job_id')
        acc_skills = accomplishment.get('skills')

        job = Job.query.get(job_id)
        if not job:
            raise InvalidData('Invalid job_id provided')

        accomplishment = cls(description=description, rank=rank, job_id=job_id)
        for skill in acc_skills:
            accomplishment.add_skill(skill)

        db.session.add(accomplishment)
        db.session.commit()
        serialized_accomplishment = cls.serialize_accomplishment(
            accomplishment)
        return serialized_accomplishment
        pass