예제 #1
0
    def post(self, level_name):
        db.create_all()
        db.session.commit()
        if UserLevelModel.find_by_name(level_name):
            return {
                'message':
                "An Record with name '{}' already exists.".format(level_name)
            }, 400

        data = self.parser.parse_args()

        userlevel = UserLevelModel(
            level_name,
            **data,
        )
        userlevel.created_by = 1
        userlevel.created_on = datetime.now()
        userlevel.modified_by = 0
        userlevel.deleted_by = 0
        try:
            userlevel.save_to_db()
        except Exception as e:
            return {
                "message":
                "An error occurred while inserting the Record.'{}'".format(e)
            }

        return userlevel.json(), 201
예제 #2
0
    def put(self, token):
        try:
            data = self.parser.parse_args()
            validateObj = UserLevelModel.validateData(data, request)
            if type(validateObj) is dict:
                return {"success": False, "errors": validateObj}, 400

            userlevel_id = decodeID(token)
            userlevel = UserLevelModel.find_by_id(userlevel_id)
            if not userlevel or userlevel.token != token:
                return {"success": False, 'message': 'Record Not Found'}, 404

            userlevel.level_name = data['level_name']
            userlevel.user_type_id = data['user_type_id']
            userlevel.modified_on = datetime.now()
            userlevel.modified_by = 1
            name = data['level_name']
            if name.strip():
                userlevel.save_to_db()
            else:
                return {
                    "success": False,
                    "message": "String Should not be empty"
                }

            return {
                "success": True,
                "message": "Record updated successfully."
            }, 200
        except Exception as e:
            return {"success": False, "message": str(e)}
예제 #3
0
 def get(self, level_name):
     userlevel = UserLevelModel.find_by_name(level_name)
     try:
         if userlevel:
             return userlevel.json()
     except Exception as e:
         return {"message": "Record not found'{}'".format(e)}, 404
예제 #4
0
 def get(cls, token):
     try:
         userlevel_id = decodeID(token)
         userlevel = UserLevelModel.find_by_id(userlevel_id)
         if not userlevel or userlevel.token != token:
             return {"success": False, 'message': 'Record Not Found'}, 404
         return userlevel.json(), 200
     except Exception as e:
         return {"success": False, "message": str(e)}
예제 #5
0
    def delete(cls, level_name):
        userlevel = UserLevelModel.find_by_name(level_name)
        if userlevel:
            userlevel.deleted_by = 1
            userlevel.deleted_on = datetime.now()
            userlevel.save_to_db()

            return {'message': 'Record deleted'}

        else:
            return {"Message": "Record Not FOUND"}
예제 #6
0
    def put(self, level_name):
        data = self.parser.parse_args()
        userlevel = UserLevelModel.find_by_name(level_name)
        if userlevel:
            userlevel.modified_on = datetime.now()
            userlevel.modified_by = 1
            userlevel.user_type_id = data['user_type_id']
            userlevel.save_to_db()

        else:
            return {"Message": "Record Not FOUND"}
        return userlevel.json()
예제 #7
0
    def delete(cls, token):
        try:
            userlevel_id = decodeID(token)
            userlevel = UserLevelModel.find_by_id(userlevel_id)
            if not userlevel or userlevel.token != token:
                return {"success": False, 'message': 'Record Not Found'}, 404

            userlevel.deleted_by = 1
            userlevel.deleted_on = datetime.now()
            userlevel.save_to_db()
            #userlevel.delete_from_db()
            return {"success": True, 'message': 'Record deleted.'}, 200
        except Exception as e:
            return {"success": False, "message": str(e)}
예제 #8
0
    def post(self):
        data = self.parser.parse_args()
        userlevel = UserLevelModel(**data)
        userlevel.created_by = 1
        userlevel.created_on = datetime.now()
        userlevel.modified_by = 0
        userlevel.deleted_by = 0
        userlevel.modified_on = None
        userlevel.deleted_on = None

        try:
            validateObj = UserLevelModel.validateData(data, request)

            if type(validateObj) is dict:
                return {"success": False, "errors": validateObj}, 400

            if UserLevelModel.find_by_name(data['level_name']):
                return {
                    "success": False,
                    "message":
                    "A userlevel with that Record Name already exists"
                }, 400
            name = data['level_name']
            if name.strip():
                userlevel.save_to_db()
                userlevel.token = encodeID(userlevel.userlevel_id)
                userlevel.save_to_db()
            else:
                return {
                    "success": False,
                    "message": "String Should not be empty"
                }
        except Exception as e:
            return {
                "message":
                "An error occurred creating the Record.'{}'".format(e)
            }, 500
        return userlevel.json(), 201