search.actions.ts 881 Bytes
Newer Older
1
import CourseSection from '../../util/CourseSection';
David Haynes's avatar
David Haynes committed
2
import { SET_SEARCH_RESULTS } from './search.action-types';
Andrew Hrdy's avatar
Andrew Hrdy committed
3
4
5

export interface SearchAction {
    type: string;
David Haynes's avatar
David Haynes committed
6
    searchResults: CourseSection[];
Andrew Hrdy's avatar
Andrew Hrdy committed
7
8
}

David Haynes's avatar
David Haynes committed
9
export const searchCourseSections = (crn: string) => async (dispatch: any) => {
Andrew Hrdy's avatar
Andrew Hrdy committed
10
11
12
    const response = await fetch(`http://localhost:3000/api/search?crn=${crn}`);
    const object = await response.json();

David Haynes's avatar
David Haynes committed
13
    const results: CourseSection[] = [
14
15
16
17
18
19
20
21
22
23
24
25
        {
            id: object.id,
            name: object.name,
            title: object.title,
            crn: object.crn,
            instructor: object.instructor,
            location: object.location,
            days: object.days,
            startTime: object.start_time,
            endTime: object.end_time,
        },
    ];
Andrew Hrdy's avatar
Andrew Hrdy committed
26
27

    dispatch({
David Haynes's avatar
David Haynes committed
28
29
        type: SET_SEARCH_RESULTS,
        searchResults: results,
Andrew Hrdy's avatar
Andrew Hrdy committed
30
    });
David Haynes's avatar
David Haynes committed
31
};