Exemplo n.º 1
0
    def init():
        staff_obj = {
            'staffId': 'toffs',
            'name': 'Ogungbaigbe Tofunmi',
            'department': 'Procurement',
            'phoneNumber': '08167494821',
            'isSecurityStaff': True,
        }

        StaffDB.new_staff(staff_obj)

        auth_object = {'staffId': 'tofunmi', 'password': '******'}

        AuthorizationDB.new_authorization(auth_object)

        staff_obj = {
            'staffId': 'gbemi',
            'name': 'Gbemi Falade',
            'department': 'Sales',
            'phoneNumber': '08167494821',
            'isSecurityStaff': False,
        }

        StaffDB.new_staff(staff_obj)

        auth_object = {'staffId': 'gbemi', 'password': '******'}

        AuthorizationDB.new_authorization(auth_object)
    def search_all_appointments_visitors_name(visitor_name_keyword):
        try:
            client = MongoClient(Constant.DB_CONNECTION_URL)
            document = client[Constant.DB_NAME][AppointmentDB.COLLECTION_NAME]

            appointments = document.find({})

            appointments_for_staff = []

            for appointment in appointments:
                a = Appointment(str(appointment['_id']),
                                appointment['staffId'],
                                appointment['visitorId'],
                                appointment['subject'],
                                appointment['dateTime'], appointment['status'])

                visitor = VisitorDB.get_visitor_by_id(appointment['visitorId'])
                if visitor_name_keyword.lower() not in visitor.name.lower():
                    continue

                a.set_visitor(visitor)

                staff = StaffDB.get_staff_by_id(appointment['staffId'])
                a.set_staff(staff.serialize)

                appointments_for_staff.append(a)

            client.close()
            return appointments_for_staff

        except Exception as e:
            print('unable to get appointments')
            raise Exception('Could not get appointments')
    def get_appointments_for_status(status):
        try:
            client = MongoClient(Constant.DB_CONNECTION_URL)
            document = client[Constant.DB_NAME][AppointmentDB.COLLECTION_NAME]

            appointments = document.find({'status': status})

            appointments_for_status = []

            for appointment in appointments:
                a = Appointment(str(appointment['_id']),
                                appointment['staffId'],
                                appointment['visitorId'],
                                appointment['subject'],
                                appointment['dateTime'], status)

                visitor = VisitorDB.get_visitor_by_id(appointment['visitorId'])
                a.set_visitor(visitor)

                staff = StaffDB.get_staff_by_id(appointment['staffId'])
                a.set_staff(staff.serialize)

                appointments_for_status.append(a)

            client.close()
            return appointments_for_status

        except Exception as e:
            print('unable to get appointments for staff')
            raise Exception('Could not get appointments for staff')
Exemplo n.º 4
0
    def authorize(request_object):
        staff_id = request_object['userId']
        password = request_object['password']

        if AuthorizationDB.authorize(staff_id, password):
            staff = StaffDB.get_staff_by_id(staff_id)
            return staff

        else:
            raise Exception('Invalid login credentials')
Exemplo n.º 5
0
 def get_staff_details_all():
     return StaffDB.get_staff_details_all()