diff --git a/client/package.json b/client/package.json index 7c354ece5569314b108c67617fecf9e0f9d637e0..8733d1d45b7c2e4c2349167573e7411aa66afd45 100644 --- a/client/package.json +++ b/client/package.json @@ -96,5 +96,5 @@ "html" ] }, - "proxy": "http://localhost:5000/api/" + "proxy": "http://localhost:5000/" } diff --git a/client/src/actions/cities.ts b/client/src/actions/cities.ts index 9226aee57b2f477d85d9d5fa781174d097773afc..594a43c43355f1c63d9248a2f98d28b4c243c820 100644 --- a/client/src/actions/cities.ts +++ b/client/src/actions/cities.ts @@ -4,7 +4,7 @@ import Types from './types' export const getCities = () => async (dispatch: AppDispatch) => { await axios - .get('/misc/cities') + .get('/api/misc/cities') .then((res) => { dispatch({ type: Types.SET_CITIES, diff --git a/client/src/actions/competitions.ts b/client/src/actions/competitions.ts index 7d248e46c05df64e948b483c5092616c4a828f35..1a9d789c09d6646657b622de1d4c43d0c9be1dbd 100644 --- a/client/src/actions/competitions.ts +++ b/client/src/actions/competitions.ts @@ -15,7 +15,7 @@ export const getCompetitions = () => async (dispatch: AppDispatch, getState: () year: currentParams.year, } await axios - .get('/competitions/search', { params }) + .get('/api/competitions/search', { params }) .then((res) => { dispatch({ type: Types.SET_COMPETITIONS, diff --git a/client/src/actions/editor.ts b/client/src/actions/editor.ts index 903dfa7bda973511d3eb5b13e31ac02a8f7bc2ee..45fbce986abae8df3da0c987be6faa4212cac2bf 100644 --- a/client/src/actions/editor.ts +++ b/client/src/actions/editor.ts @@ -4,7 +4,7 @@ import Types from './types' export const getEditorCompetition = (id: string) => async (dispatch: AppDispatch, getState: () => RootState) => { await axios - .get(`/competitions/${id}`) + .get(`/api/competitions/${id}`) .then((res) => { dispatch({ type: Types.SET_EDITOR_COMPETITION, diff --git a/client/src/actions/presentation.ts b/client/src/actions/presentation.ts index c967131f903809ac8af8e11c0218fb614de75227..97c611dfb27015f37fa33693ee90c6f8a1159ef3 100644 --- a/client/src/actions/presentation.ts +++ b/client/src/actions/presentation.ts @@ -6,7 +6,7 @@ import Types from './types' export const getPresentationCompetition = (id: string) => async (dispatch: AppDispatch) => { await axios - .get(`/competitions/${id}`) + .get(`/api/competitions/${id}`) .then((res) => { dispatch({ type: Types.SET_PRESENTATION_COMPETITION, @@ -20,7 +20,7 @@ export const getPresentationCompetition = (id: string) => async (dispatch: AppDi export const getPresentationTeams = (id: string) => async (dispatch: AppDispatch) => { await axios - .get(`/competitions/${id}/teams`) + .get(`/api/competitions/${id}/teams`) .then((res) => { dispatch({ type: Types.SET_PRESENTATION_TEAMS, diff --git a/client/src/actions/roles.ts b/client/src/actions/roles.ts index 0160353b184755b33f003592ad127880af2803d7..19a148c7a01d9dc4ccd6552f06dbf954509f16dc 100644 --- a/client/src/actions/roles.ts +++ b/client/src/actions/roles.ts @@ -4,7 +4,7 @@ import Types from './types' export const getRoles = () => async (dispatch: AppDispatch) => { await axios - .get('/misc/roles') + .get('/api/misc/roles') .then((res) => { dispatch({ type: Types.SET_ROLES, diff --git a/client/src/actions/searchUser.ts b/client/src/actions/searchUser.ts index c6211056bda8250f1b5c849450d018ef4bd42819..a3ea55c7ce7ef5afc1468de7cc1d350303b3674a 100644 --- a/client/src/actions/searchUser.ts +++ b/client/src/actions/searchUser.ts @@ -15,7 +15,7 @@ export const getSearchUsers = () => async (dispatch: AppDispatch, getState: () = email: currentParams.email, } await axios - .get('/users/search', { params }) + .get('/api/users/search', { params }) .then((res) => { dispatch({ type: Types.SET_SEARCH_USERS, diff --git a/client/src/actions/typesAction.ts b/client/src/actions/typesAction.ts index 4fcde4f55ee72cb9f72f6d79f0e5f1db6995fa4b..32a212b0c5fc270d62dd6528efbea51824acdb8e 100644 --- a/client/src/actions/typesAction.ts +++ b/client/src/actions/typesAction.ts @@ -4,7 +4,7 @@ import Types from './types' export const getTypes = () => async (dispatch: AppDispatch) => { await axios - .get('/misc/types') + .get('/api/misc/types') .then((res) => { dispatch({ type: Types.SET_TYPES, diff --git a/client/src/actions/user.ts b/client/src/actions/user.ts index 371dcaeb6b9426c4235e9fc837257f5bbc6625f9..e2ad88acf776490ee49189236f2f921297c33d5c 100644 --- a/client/src/actions/user.ts +++ b/client/src/actions/user.ts @@ -7,7 +7,7 @@ import Types from './types' export const loginUser = (userData: AccountLoginModel, history: History) => async (dispatch: AppDispatch) => { dispatch({ type: Types.LOADING_UI }) await axios - .post('/auth/login', userData) + .post('/api/auth/login', userData) .then((res) => { const token = `Bearer ${res.data.access_token}` localStorage.setItem('token', token) //setting token to local storage @@ -28,7 +28,7 @@ export const loginUser = (userData: AccountLoginModel, history: History) => asyn export const getUserData = () => async (dispatch: AppDispatch) => { dispatch({ type: Types.LOADING_USER }) await axios - .get('/users') + .get('/api/users') .then((res) => { dispatch({ type: Types.SET_USER, @@ -42,7 +42,7 @@ export const getUserData = () => async (dispatch: AppDispatch) => { export const logoutUser = () => async (dispatch: AppDispatch) => { localStorage.removeItem('token') - await axios.post('/auth/logout').then(() => { + await axios.post('/api/auth/logout').then(() => { delete axios.defaults.headers.common['Authorization'] dispatch({ type: Types.SET_UNAUTHENTICATED, diff --git a/client/src/pages/admin/competitions/AddCompetition.tsx b/client/src/pages/admin/competitions/AddCompetition.tsx index 0ce9a6ffa4601cf543383e7efa3bdf55eee259f8..6053f2f8de9c3d13cde3403ec1a62317e477d047 100644 --- a/client/src/pages/admin/competitions/AddCompetition.tsx +++ b/client/src/pages/admin/competitions/AddCompetition.tsx @@ -63,7 +63,7 @@ const AddCompetition: React.FC = (props: any) => { } await axios - .post('/competitions', params) // send to database + .post('/api/competitions', params) // send to database .then(() => { actions.resetForm() // reset the form setAnchorEl(null) diff --git a/client/src/pages/admin/competitions/CompetitionManager.tsx b/client/src/pages/admin/competitions/CompetitionManager.tsx index 929d3145d33fedd061f426af6e85461c1a355b77..83f399b95a0c083727333c2f842a1c61a8eca2d0 100644 --- a/client/src/pages/admin/competitions/CompetitionManager.tsx +++ b/client/src/pages/admin/competitions/CompetitionManager.tsx @@ -82,7 +82,7 @@ const CompetitionManager: React.FC = (props: any) => { const handleDeleteCompetition = async () => { if (activeId) { await axios - .delete(`/competitions/${activeId}`) + .delete(`/api/competitions/${activeId}`) .then(() => { setAnchorEl(null) dispatch(getCompetitions()) // refresh the competition list @@ -101,7 +101,7 @@ const CompetitionManager: React.FC = (props: any) => { const handleDuplicateCompetition = async () => { if (activeId) { await axios - .post(`/competitions/${activeId}/copy`) + .post(`/api/competitions/${activeId}/copy`) .then(() => { setAnchorEl(null) dispatch(getCompetitions()) diff --git a/client/src/pages/admin/regions/AddRegion.tsx b/client/src/pages/admin/regions/AddRegion.tsx index c8ae412e680bda652327193af44cb728e36c1621..b00961384f73246365e60023af04ed7567adf311 100644 --- a/client/src/pages/admin/regions/AddRegion.tsx +++ b/client/src/pages/admin/regions/AddRegion.tsx @@ -51,7 +51,7 @@ const AddRegion: React.FC = (props: any) => { name: values.model.name, } await axios - .post('/misc/cities', params) + .post('/api/misc/cities', params) .then(() => { actions.resetForm() dispatch(getCities()) diff --git a/client/src/pages/admin/regions/Regions.tsx b/client/src/pages/admin/regions/Regions.tsx index eb79575ea7857658742f30f02d5f96a5e87e7f6d..436da6f69429ca6711452d7babf477f8da593eee 100644 --- a/client/src/pages/admin/regions/Regions.tsx +++ b/client/src/pages/admin/regions/Regions.tsx @@ -45,7 +45,7 @@ const RegionManager: React.FC = (props: any) => { const handleDeleteCity = async () => { if (activeId) { await axios - .delete(`/misc/cities/${activeId}`) + .delete(`/api/misc/cities/${activeId}`) .then(() => { setAnchorEl(null) dispatch(getCities()) @@ -63,7 +63,7 @@ const RegionManager: React.FC = (props: any) => { const handleAddCity = async () => { await axios - .post(`/misc/cities`, { name: newCity }) + .post(`/api/misc/cities`, { name: newCity }) .then(() => { setAnchorEl(null) dispatch(getCities()) diff --git a/client/src/pages/admin/users/AddUser.tsx b/client/src/pages/admin/users/AddUser.tsx index d58a5d5dc153463618015e9c4195958f5160bbcb..9f1511eac460c661ebd35dc995f6606e66080359 100644 --- a/client/src/pages/admin/users/AddUser.tsx +++ b/client/src/pages/admin/users/AddUser.tsx @@ -59,7 +59,7 @@ const AddUser: React.FC = (props: any) => { role_id: selectedRole?.id as number, } await axios - .post('/auth/signup', params) + .post('/api/auth/signup', params) .then(() => { actions.resetForm() setAnchorEl(null) diff --git a/client/src/pages/admin/users/EditUser.tsx b/client/src/pages/admin/users/EditUser.tsx index 7db5aeecd2be0c3f3f94c22a0c459a71cbc47aa4..9b4a5d1bd6aecd92a03f44221c2cb40d40e2ab70 100644 --- a/client/src/pages/admin/users/EditUser.tsx +++ b/client/src/pages/admin/users/EditUser.tsx @@ -110,7 +110,7 @@ const EditUser = ({ user }: UserIdProps) => { const handleDeleteUsers = async () => { setOpen(false) await axios - .delete(`/auth/delete/${user.id}`) + .delete(`/api/auth/delete/${user.id}`) .then(() => { setAnchorEl(null) dispatch(getSearchUsers()) @@ -141,7 +141,7 @@ const EditUser = ({ user }: UserIdProps) => { req['role_id'] = params.role_id } await axios - .put('/users/' + user.id, req) + .put('/api/users/' + user.id, req) .then((res) => { setAnchorEl(null) dispatch(getSearchUsers()) diff --git a/client/src/pages/presentationEditor/PresentationEditorPage.test.tsx b/client/src/pages/presentationEditor/PresentationEditorPage.test.tsx index 956d0b7212baf5a3eed212c86e9946550b66e72f..c645724e3c7fabda69a2ad2434f4bd7b587c8c2e 100644 --- a/client/src/pages/presentationEditor/PresentationEditorPage.test.tsx +++ b/client/src/pages/presentationEditor/PresentationEditorPage.test.tsx @@ -28,7 +28,7 @@ it('renders presentation editor', () => { }, } ;(mockedAxios.get as jest.Mock).mockImplementation((path: string, params?: any) => { - if (path.startsWith('/competitions')) return Promise.resolve(competitionRes) + if (path.startsWith('/api/competitions')) return Promise.resolve(competitionRes) return Promise.resolve(citiesRes) }) render( diff --git a/client/src/pages/presentationEditor/PresentationEditorPage.tsx b/client/src/pages/presentationEditor/PresentationEditorPage.tsx index 4087d6c798d17522dbaffe3f8c7041b57795338f..da18cd52fd6222b4a37c7a88bc111f0c4974ecc9 100644 --- a/client/src/pages/presentationEditor/PresentationEditorPage.tsx +++ b/client/src/pages/presentationEditor/PresentationEditorPage.tsx @@ -104,7 +104,7 @@ const PresentationEditorPage: React.FC = () => { } const createNewSlide = async () => { - await axios.post(`/competitions/${id}/slides`, { title: 'new slide' }) + await axios.post(`/api/competitions/${id}/slides`, { title: 'new slide' }) dispatch(getEditorCompetition(id)) } @@ -128,13 +128,13 @@ const PresentationEditorPage: React.FC = () => { } const handleRemoveSlide = async () => { - await axios.delete(`/competitions/${id}/slides/${contextState.slideId}`) + await axios.delete(`/api/competitions/${id}/slides/${contextState.slideId}`) dispatch(getEditorCompetition(id)) setContextState(initialState) } const handleDuplicateSlide = async () => { - await axios.post(`/competitions/${id}/slides/${contextState.slideId}/copy`) + await axios.post(`/api/competitions/${id}/slides/${contextState.slideId}/copy`) dispatch(getEditorCompetition(id)) setContextState(initialState) } diff --git a/client/src/pages/presentationEditor/components/CompetitionSettings.tsx b/client/src/pages/presentationEditor/components/CompetitionSettings.tsx index 75d418403d7ec51e13563adf3c9afcf2ef15152f..53c2ecdb4dd23cc81df0140bd2bede66dfe18b88 100644 --- a/client/src/pages/presentationEditor/components/CompetitionSettings.tsx +++ b/client/src/pages/presentationEditor/components/CompetitionSettings.tsx @@ -77,7 +77,7 @@ const CompetitionSettings: React.FC = () => { const competition = useAppSelector((state) => state.editor.competition) const updateCompetitionName = async (event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => { await axios - .put(`/competitions/${id}`, { name: event.target.value }) + .put(`/api/competitions/${id}`, { name: event.target.value }) .then(() => { dispatch(getEditorCompetition(id)) }) @@ -87,7 +87,7 @@ const CompetitionSettings: React.FC = () => { const cities = useAppSelector((state) => state.cities.cities) const updateCompetitionCity = async (city: City) => { await axios - .put(`/competitions/${id}`, { city_id: city.id }) + .put(`/api/competitions/${id}`, { city_id: city.id }) .then(() => { dispatch(getEditorCompetition(id)) }) @@ -104,7 +104,7 @@ const CompetitionSettings: React.FC = () => { const removeTeam = async (tid: number) => { await axios - .delete(`/competitions/${id}/teams/${tid}`) + .delete(`/api/competitions/${id}/teams/${tid}`) .then(() => { dispatch(getEditorCompetition(id)) }) @@ -113,7 +113,7 @@ const CompetitionSettings: React.FC = () => { const addTeam = async () => { setAddTeamOpen(false) await axios - .post(`/competitions/${id}/teams`, { name: selectedTeamName }) + .post(`/api/competitions/${id}/teams`, { name: selectedTeamName }) .then(() => { dispatch(getEditorCompetition(id)) }) diff --git a/client/src/pages/presentationEditor/components/RndComponent.tsx b/client/src/pages/presentationEditor/components/RndComponent.tsx index 890e51601ec20901e66ad76b199719478d6c53e3..6302d3fcf50c68fcb232693aa0a3590999cc660f 100644 --- a/client/src/pages/presentationEditor/components/RndComponent.tsx +++ b/client/src/pages/presentationEditor/components/RndComponent.tsx @@ -20,13 +20,13 @@ const RndComponent = ({ component }: ImageComponentProps) => { const competitionId = useAppSelector((state) => state.editor.competition.id) const slideId = useAppSelector((state) => state.editor.activeSlideId) const handleUpdatePos = (pos: Position) => { - axios.put(`/competitions/${competitionId}/slides/${slideId}/components/${component.id}`, { + axios.put(`/api/competitions/${competitionId}/slides/${slideId}/components/${component.id}`, { x: pos.x, y: pos.y, }) } const handleUpdateSize = (size: Size) => { - axios.put(`/competitions/${competitionId}/slides/${slideId}/components/${component.id}`, { + axios.put(`/api/competitions/${competitionId}/slides/${slideId}/components/${component.id}`, { w: size.w, h: size.h, }) diff --git a/client/src/pages/presentationEditor/components/SlideSettings.tsx b/client/src/pages/presentationEditor/components/SlideSettings.tsx index 7cc78b34330cf571d0270093c70b811e276a0dd0..85fe3cc08419333f9bb94fc4b9fbc1094c1ec7f7 100644 --- a/client/src/pages/presentationEditor/components/SlideSettings.tsx +++ b/client/src/pages/presentationEditor/components/SlideSettings.tsx @@ -133,7 +133,7 @@ const SlideSettings: React.FC = () => { if (selectedSlideType === 0) { // Change slide type from a question type to information await axios - .delete(`/competitions/${id}/slides/${activeSlide.id}/questions/${activeSlide.questions[0].id}`) + .delete(`/api/competitions/${id}/slides/${activeSlide.id}/questions/${activeSlide.questions[0].id}`) .then(() => { dispatch(getEditorCompetition(id)) }) @@ -141,10 +141,10 @@ const SlideSettings: React.FC = () => { } else { // Change slide type from question type to another question type await axios - .delete(`/competitions/${id}/slides/${activeSlide.id}/questions/${activeSlide.questions[0].id}`) + .delete(`/api/competitions/${id}/slides/${activeSlide.id}/questions/${activeSlide.questions[0].id}`) .catch(console.log) await axios - .post(`/competitions/${id}/slides/${activeSlide.id}/questions`, { + .post(`/api/competitions/${id}/slides/${activeSlide.id}/questions`, { name: 'Ny fråga', total_score: 0, type_id: selectedSlideType, @@ -158,7 +158,7 @@ const SlideSettings: React.FC = () => { } else if (selectedSlideType !== 0) { // Change slide type from information to a question type await axios - .post(`/competitions/${id}/slides/${activeSlide.id}/questions`, { + .post(`/api/competitions/${id}/slides/${activeSlide.id}/questions`, { name: 'Ny fråga', total_score: 0, type_id: selectedSlideType, @@ -208,10 +208,13 @@ const SlideSettings: React.FC = () => { const addAlternative = async () => { if (activeSlide && activeSlide.questions[0]) { await axios - .post(`/competitions/${id}/slides/${activeSlide?.id}/questions/${activeSlide?.questions[0].id}/alternatives`, { - text: '', - value: 0, - }) + .post( + `/api/competitions/${id}/slides/${activeSlide?.id}/questions/${activeSlide?.questions[0].id}/alternatives`, + { + text: '', + value: 0, + } + ) .then(() => { dispatch(getEditorCompetition(id)) }) @@ -237,7 +240,7 @@ const SlideSettings: React.FC = () => { const handleAddText = async () => { if (activeSlide) { - await axios.post(`/competitions/${id}/slides/${activeSlide?.id}/components`, { + await axios.post(`/api/competitions/${id}/slides/${activeSlide?.id}/components`, { type_id: 1, data: { text: 'Ny text' }, w: 315, @@ -261,7 +264,7 @@ const SlideSettings: React.FC = () => { setTimer(+event.target.value) if (activeSlide) { await axios - .put(`/competitions/${id}/slides/${activeSlide.id}`, { timer: event.target.value }) + .put(`/api/competitions/${id}/slides/${activeSlide.id}`, { timer: event.target.value }) .then(() => { dispatch(getEditorCompetition(id)) }) diff --git a/client/src/pages/presentationEditor/components/TextComponentEdit.tsx b/client/src/pages/presentationEditor/components/TextComponentEdit.tsx index e0f0d5b475b87f2db7f71337c1c4978716fdb5e1..c347bd5b6845c0413251907d514b31e825bd1e68 100644 --- a/client/src/pages/presentationEditor/components/TextComponentEdit.tsx +++ b/client/src/pages/presentationEditor/components/TextComponentEdit.tsx @@ -37,7 +37,7 @@ const TextComponentEdit = ({ component }: ImageComponentProps) => { setTimerHandle( window.setTimeout(async () => { console.log('Content was updated on server. id: ', component.id) - await axios.put(`/competitions/${competitionId}/slides/${activeSlideId}/components/${component.id}`, { + await axios.put(`/api/competitions/${competitionId}/slides/${activeSlideId}/components/${component.id}`, { data: { ...component.data, text: a }, }) dispatch(getEditorCompetition(id)) @@ -46,7 +46,7 @@ const TextComponentEdit = ({ component }: ImageComponentProps) => { } const handleDeleteText = async (componentId: number) => { - await axios.delete(`/competitions/${id}/slides/${activeSlideId}/components/${componentId}`) + await axios.delete(`/api/competitions/${id}/slides/${activeSlideId}/components/${componentId}`) dispatch(getEditorCompetition(id)) } diff --git a/client/src/utils/checkAuthentication.ts b/client/src/utils/checkAuthentication.ts index a782ea10f79a65998ed7d1a9e091361aa6a48982..9225aa29858d2f9ea58f8ac118dd2feed01d1cc5 100644 --- a/client/src/utils/checkAuthentication.ts +++ b/client/src/utils/checkAuthentication.ts @@ -16,7 +16,7 @@ export const CheckAuthentication = async () => { axios.defaults.headers.common['Authorization'] = authToken store.dispatch({ type: Types.LOADING_USER }) await axios - .get('/users') + .get('/api/users') .then((res) => { store.dispatch({ type: Types.SET_AUTHENTICATED }) store.dispatch({