def set_users_score(self, user: User, score: int):
     if user.get() is None:
         raise ValueError(err.USER_NOT_FOUND.value)
     return session_coll.update_one(
         {
             '$and': [{
                 primary_key: ObjectId(self.id)
             }, {
                 'users.user': user.id
             }]
         }, {'$set': {
             'users.$.score': score
         }})
示例#2
0
def upsert(event, context):
    post = json.loads(event['body'])
    if "user" not in post:
        raise Exception('user object required in post')

    user = User(event)

    for (key, val) in post['user'].items():
        user.setItem(key, val)

    user.save()

    return {
        "statusCode":
        200,
        "body":
        json.dumps({
            "success": True,
            "user": user.get()
        }, cls=DecimalEncoder)
    }