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)
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()
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
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)
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)
def delete(self, userid): user = UserModel.findById(userid) if user is not None: user.delete() return userschema.dump(user) return log.ISNOTEXIST(), 404
def get(self, userid): user = UserModel.findById(userid) if user is None: return gettex('NOT_FOUND'), 400 return UserSchema().dump(user)