Ejemplo n.º 1
0
def getProjectModel(user_email="",
                    enterprise_id: uuid.UUID = uuid.uuid4(),
                    project_id: uuid.UUID = uuid.uuid4(),
                    user: UserModel = None,
                    enterprise: EnterpriseModel = None):
    try:
        if not user: user = getUser(user_email)
        if not enterprise:
            enterprise = getEnterpriseModel(user=user,
                                            enterprise_id=enterprise_id)
            if enterprise["error"]: return enterprise
            enterprise = enterprise["message"]

        if project_id in enterprise.projects:
            project = ProjectModel.objects(id=project_id).first()
            return {"message": project, "error": False}

    except Exception as error:
        return {"message": f"Some error has happend: {error}", "error": True}
Ejemplo n.º 2
0
def getProjects(user_email="",
                enterprise_id: uuid.UUID = uuid.uuid4(),
                user: UserModel = None):
    try:
        if not user: user = getUser(user_email)

        enterprise = getEnterpriseModel(user=user, enterprise_id=enterprise_id)
        if enterprise["error"]: return enterprise
        enterprise = enterprise["message"]

        projects = ProjectModel.objects(id__in=enterprise.projects).aggregate({
            "$project": {
                "id": "$id.uuid",
                "name": 1,
                "created_at": 1,
                "image_src": 1
            }
        })

        return {"message": list(projects), "error": False}

    except Exception as error:
        return {"message": f"Some error has happend: {error}", "error": True}