예제 #1
0
    def post(cls):
        data = req.get_json()
        store = StoreSchema().load(data, partial=('storeId', ))
        try:
            isExist = StoreModel.findByStoreName(data['storeName'])
            user = UserModel.findById(data['userId'])
            islimit = StoreModel.isLimit(data['userId'])
        except:
            return gettex('SOMETHING_WRONG'), 500

        if bool(isExist):
            return gettex('EXIST'), 422

        if not bool(user):
            return gettex('NOT_EXIST'), 404

        if islimit:
            return gettex('LIMITED'), 422

        try:
            storeId = f"ST_{store.findSerial() + 1}_{int(time())}_{user.userId}"
            store.storeId = storeId
            store.insert()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return StoreSchema().dump(store)
예제 #2
0
    def post(cls,userid:int):
        user = UserModel.findById(userid)
        if user is not None:
            confrimate = ConfirmationModel(user.userId)
            confrimate.insert()
            user.sendMsg() 
            return gettext('emailSent').format(user.email)

        return log.ISNOTEXIST()
예제 #3
0
 def put(self, userid):
     value = request.get_json()
     user = UserModel.findById(userid)
     if user is not None:
         user.name = value['name']
         user.email = value['email']
         user.insert()
         return userschema.dump(user)
     return log.ISNOTEXIST(), 404
예제 #4
0
    def delete(self, userid):
        user = UserModel.findById(userid)
        if user is None:
            return gettex('NOT_FOUND'), 400
        try:
            user.delete()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return UserSchema().dump(user)
예제 #5
0
    def put(self):
        userid = get_jwt_claims()['userId']
        value = req.get_json()
        user = UserModel.findById(userid)
        if not bool(user):
            return gettex('NOT_FOUND'), 400

        try:
            user.name = value['name']
            user.insert()
        except:
            return gettex('SOMETHING_WRONG'), 500

        return UserSchema().dump(user)
예제 #6
0
 def delete(self, userid):
     user = UserModel.findById(userid)
     if user is not None:
         user.delete()
         return userschema.dump(user)
     return log.ISNOTEXIST(), 404
예제 #7
0
    def get(self, userid):
        user = UserModel.findById(userid)
        if user is None:
            return gettex('NOT_FOUND'), 400

        return UserSchema().dump(user)