Exemple #1
0
    def put(self, job_id):
        """ Edit a specific job """
        request_data = Job.parser.parse_args()

        if not JobsModel.find_by_id(job_id):
            return {"message": "A job with that ID does not exist"}, 404

        try:
            # TODO: transaction - also update jobs saved in user's profiles
            # TODO: transaction - also update jobs saved in Job instances
            updated_job = JobsModel.build_job_from_request(request_data)
            mongo.db.jobs.update({"_id": ObjectId(job_id)}, updated_job)

            return strip_objectid(updated_job)

        except ValidationError as error:
            return {"message": error.message}, 400
Exemple #2
0
    def post(self):
        """ Add a new job to the db """
        try:
            request_data = Job.parser.parse_args()
        except Exception as error:
            print(error)
            return {'message': "Malformed input. Check the console"}, 400

        try:
            new_job = JobsModel.build_job_from_request(request_data)

            if JobsModel.find_by_name(new_job['name']):
                return {'message': 'A job with that name already exists'}, 400

            # Generate and add code for post it note design
            new_job['postit_id'] = JobsModel.generate_postit_id()

            result = mongo.db.jobs.insert_one(new_job)
            new_job['_id'] = result.inserted_id

            return strip_objectid(new_job)

        except ValidationError as error:
            return {'message': error.message}, 400