Example #1
0
    def post(self, us_employer_id):

        if CompanyModel.find_by_us_employer_id(us_employer_id):
            return {
                "message":
                "A company already exists with the same employer ID, use a different one!"
            }, 400

        data = Company.parser.parse_args()
        is_valid, error_message = CompanyModel.check_if_data_has_valid_format(
            us_employer_id, **data)

        if is_valid:
            new_company = CompanyModel(us_employer_id, **data)
            try:
                format_company_to_json(new_company)
                new_company.save_to_db()
                return format_company_to_json(new_company), 201
            except:
                return {
                    "message": "An error occurred while creating the user!"
                }, 500
        else:
            return {"message": error_message}, 400