示例#1
0
async def update(id: str,
                 seq: int = Body(...),
                 wb_seq: int = Body(...),
                 element: str = Body(...),
                 statement: str = Body(...),
                 db: DBClient = client):
    rs = await crud.update(db, id, seq, wb_seq, element, statement)
    if not rs:
        return utils.create_500_response("GPQ update-start failed")
    return {"response": rs}
示例#2
0
async def create_company(
    data: CompanyCreate,
    db: DBClient=client,
    current_user: UserInDB=Depends(get_current_user)):
    """Create new company"""
    logging.info(f">>> {__name__}:{create_company.__name__}")
    context = current_user['context']
    data.created_by = context
    # print(data)
    company = await crud.create(db, data)
    if company:
        return utils.create_aliased_response(CompanyResponse(response=company))
    return utils.create_500_response("Company creation failed")
示例#3
0
async def create_license(data: UserCreate, db: DBClient = client):
    """Required fields: `fullname`, `username`, `email`, `password`."""
    logging.info(">>> " + __name__ + ":" + create_license.__name__)
    data = data.dict()
    data['type'] = config.USERTYPE_LICENSE
    data = UserCreate(**data)

    msg = await crud.check_free_email_username(db, data.username, data.email)
    if msg:
        return utils.error_400_response(msg)

    user = await crud.create(db, data)
    if user:
        return utils.create_aliased_response(UserResponse(response=user))

    return utils.create_500_response("User creation failed")
示例#4
0
async def create_persona(prj_id: str,
                         data: PersonaCreate,
                         db: DBClient = client):
    """Create new persona"""
    logging.info(f">>> {__name__}:{create_persona.__name__}")
    project = await get_project(db, prj_id)
    if not project:
        return utils.create_422_response("Could not find the referred project")

    hashed_pwd = get_password_hash(data.password)
    _dict = data.dict()
    _dict["prj_id"] = prj_id
    _dict["hashed_password"] = hashed_pwd
    logging.info(">>> ================")
    model = PersonaInDB(**_dict)
    logging.info(">>> ================")
    persona = await crud.create(db, model)
    if persona:
        return utils.create_aliased_response(PersonaResponse(response=persona))
    return utils.create_500_response("Persona creation failed")
示例#5
0
async def create(prj_id: str = Body(...),
                 username: str = Body(...),
                 rows: int = Body(GPQ_TOTAL_ITEMS),
                 db: DBClient = client):

    logging.info(f">>> {__name__}:{create.__name__}")
    collection = get_collection(db, DOCTYPE_PERSONA)
    persona = await get_by_dict(collection, {
        "prj_id": ObjectId(prj_id),
        "username": username
    })
    if not persona:
        return utils.create_422_response(
            "Coul not verify project and/or persona")

    if not rows or rows == 0:
        rows = GPQ_TOTAL_ITEMS

    fullname = persona["fullname"]
    rs = await crud.create_template(db, prj_id, username, fullname, rows)
    if not rs:
        return utils.create_500_response("GPQ template creation failed")
    return utils.create_aliased_response(GPQEvidenceResponse(response=rs))
示例#6
0
async def start(id: str, db: DBClient = client):
    rs = await crud.start(db, id)
    if not rs:
        return utils.create_500_response("GPQ update-start failed")
    return {"response": rs}