Example #1
0
    def post(self, user_id):
        user_id = get_jwt_identity()['id']
        user = User().where('id', user_id).first()
        if user.exists() is True:
            Comment().where('user_id', user_id).get().delete()
            GradeDistribution().where('user_id', user_id).get().delete()
            Lecturer().where('user_id', user_id).get().delete()
            Note().where('user_id', user_id).get().delete()
            user.delete()
            return response({'message': 'User deleted with success'}, 200)

        return response({'errors': ['User could not found!']}, 401)
Example #2
0
 def post(self, user_id):
     user = User().where('id', '=', user_id).first()
     print(user_id, file=sys.stderr)
     if user.exists():
         Comment().where('user_id', user_id).get().delete()
         Event().where('user_id', user_id).get().delete()
         GradeDistribution().where('user_id', user_id).get().delete()
         lecturers = Lecturer().where('user_id', user_id).get()
         for lecturer in lecturers.data():
             Comment().where([['type', '=', 'lecturers'], ['type_id', '=', lecturer['id']]]).get().delete()
             GradeDistribution().where('lecturer_id', '=', lecturer['id']).get().delete()
         lecturers.delete()
         notes = Note().where('user_id', user_id).get()
         for note in notes.data():
             Comment().where([['type', '=', 'notes'], ['type_id', '=', note['id']]]).get().delete()
         notes.delete()
         user.delete()
         return response({
             'message': 'User deleted successfully'
         }, 202)
     return response({
         'message': 'User does not exist'
     }, 404)