Ejemplo n.º 1
0
    def post(self, team_id):
        current_user = get_jwt_identity()
        data = task_parser.parse_args()
        if TaskModel.find_by_title(data['title']):
            return {
                'message': 'Task {} already exists'.format(data['title'])
            }, 409

        user = UserModel.query.get(current_user)
        new_task = TaskModel(data['title'], data['status'], data["priority"])
        new_task.reporter_id = user.id
        if data['description']:
            new_task.description = data['description']
        if data['assigne_id']:
            new_task.assigne_id = data['assigne_id']
        if data['planneddate']:
            new_task.planneddate = data['planneddate']
        new_task.team_id = team_id

        try:
            new_task.save_to_db()
            resp = jsonify({
                'message':
                'Task {} was created'.format(data['title']),
                'id':
                new_task.id
            })
            resp.status_code = 200
            return resp
        except:
            return {'message': 'Something went wrong'}, 500
Ejemplo n.º 2
0
    def put(self, task_id):
        task = TaskModel.query.get(task_id)
        args = task_put_parser.parse_args()
        if args['title']:
            if TaskModel.find_by_title(args['title']):
                return {
                    'message':
                    'Task with Name {} already exists'.format(args['name'])
                }, 409
            task.title = args['title']

        if args['description']:
            task.description = args['description']

        if args['status']:
            task.status = args['status']

        if args['priority']:
            task.priority = args['priority']

        if args['assigne_id']:
            task.assigne_id = args['assigne_id']

        if args['reporter_id']:
            task.reporter_id = args['reporter_id']

        if args['planneddate']:
            task.planneddate = args['planneddate']

        try:
            task.update_db()
            return {'message': 'User Details Updated'}, 200
        except:
            return {'message': 'Something went wrong'}, 500