Пример #1
0
async def create_user(conn: AsyncIOMotorClient, user: UserInCreate) -> UserInDB:
    dbuser = UserInDB(**user.dict())
    dbuser.change_password(user.password)
    row = await conn[database_name][user_collection_name].insert_one(dbuser.dict())
    # dbuser.created_at = ObjectId(dbuser.id ).generation_time
    # dbuser.updated_at = ObjectId(dbuser.id ).generation_time
    # await conn[database_name][user_collection_name]\
    #     .update_one({"username": dbuser.username}, {'$set': dbuser.dict()})
    return dbuser
Пример #2
0
async def create_user(conn: AsyncIOMotorClient,
                      user: UserInRegister) -> UserInDB:
    dbuser = UserInDB(**user.dict())
    dbuser.change_password(user.password)
    dbuser.created_at = datetime.now()
    dbuser.updated_at = datetime.now()

    inserted_row = await conn[database_name][users_collection_name].insert_one(
        dbuser.dict())
    dbuser.id = str(inserted_row.inserted_id)

    return dbuser