예제 #1
0
    def start_task(cls, authorizer: Authorizer, stage: str, area: str,
                   subline: str, tasks: List[str], description: str):
        from core.services.beneficiaries import BeneficiariesService
        line_, subline_ = subline.split('.')
        objective = ObjectivesService.get(stage, area, int(line_),
                                          int(subline_))

        now = datetime.now(timezone.utc)
        task = Task(created=int(now.timestamp() * 1000),
                    completed=False,
                    objective_key=join_key(stage, area, subline),
                    original_objective=objective,
                    personal_objective=description,
                    tasks=[
                        Subtask(completed=False, description=description)
                        for description in tasks
                    ])

        try:
            BeneficiariesService.update(authorizer,
                                        active_task=task.to_db_dict())
        except BeneficiariesService.exceptions(
        ).ConditionalCheckFailedException:
            return None
        return task
예제 #2
0
def update_beneficiary(event: HTTPEvent):
    if event.authorizer.sub != event.params["sub"]:
        return JSONResponse.generate_error(HTTPError.FORBIDDEN, "You can not access data from this beneficiary")

    result = BeneficiariesService.update(event.authorizer, profile_picture=event.json.get('profile_picture'),
                                         nickname=event.json.get('nickname'))
    if result is None:
        return JSONResponse.generate_error(HTTPError.NOT_FOUND, "This user does not have a beneficiaries assigned")

    return JSONResponse({"message": "Updated successfully"})