-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add services for handling request to API
TODO: The endpoints for getting list of items needs to be updated after RSN-57. Addtionally, the structures for events endpoints should also be uploaded to be compliant with current state.
- Loading branch information
Showing
10 changed files
with
492 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { sendRequest, HttpMethod } from "@/lib/request"; | ||
import { | ||
TokenPayload, | ||
TokenPayloadMapper, | ||
} from "@reasn/common/src/schemas/TokenPayload"; | ||
import { LoginRequest } from "@reasn/common/src/schemas/LoginRequest"; | ||
import { RegisterRequest } from "@reasn/common/src/schemas/RegisterRequest"; | ||
import { UserDto, UserDtoMapper } from "@reasn/common/src/schemas/UserDto"; | ||
|
||
const baseUrl = `${process.env.REASN_API_URL}/api/v1/auth`; | ||
|
||
export const login = async ( | ||
loginRequest: LoginRequest, | ||
): Promise<TokenPayload> => { | ||
const url = new URL(`${baseUrl}/login`); | ||
|
||
const response = await sendRequest<TokenPayload>(url, { | ||
method: HttpMethod.POST, | ||
body: loginRequest, | ||
}); | ||
return TokenPayloadMapper.fromObject(response); | ||
}; | ||
|
||
export const register = async ( | ||
registerRequest: RegisterRequest, | ||
): Promise<UserDto> => { | ||
const url = new URL(`${baseUrl}/register`); | ||
|
||
const response = await sendRequest<UserDto>(url, { | ||
method: HttpMethod.POST, | ||
body: registerRequest, | ||
}); | ||
return UserDtoMapper.fromObject(response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import { sendRequest, HttpMethod } from "@/lib/request"; | ||
|
||
const baseUrl = `${process.env.REASN_API_URL}/api/v1/events`; | ||
|
||
export const getEvents = async ( | ||
params: Record<string, string> = {}, | ||
): Promise<any> => { | ||
const url = new URL(baseUrl); | ||
url.search = new URLSearchParams(params).toString(); | ||
|
||
const response = await sendRequest<any>(url, { method: HttpMethod.GET }); | ||
return response; | ||
}; | ||
|
||
export const createEvent = async (event: any): Promise<any> => { | ||
const url = new URL(baseUrl); | ||
|
||
const response = await sendRequest<any>(url, { | ||
method: HttpMethod.POST, | ||
body: event, | ||
authRequired: true, | ||
}); | ||
return response; | ||
}; | ||
|
||
export const getEventBySlug = async (slug: string): Promise<any> => { | ||
const url = new URL(`${baseUrl}/${slug}`); | ||
|
||
const response = await sendRequest<any>(url, { method: HttpMethod.GET }); | ||
return response; | ||
}; | ||
|
||
export const updateEvent = async (slug: string, event: any): Promise<any> => { | ||
const url = new URL(`${baseUrl}/${slug}`); | ||
|
||
const response = await sendRequest<any>(url, { | ||
method: HttpMethod.PUT, | ||
body: event, | ||
authRequired: true, | ||
}); | ||
return response; | ||
}; | ||
|
||
export const getEventsRequests = async (): Promise<any> => { | ||
const url = new URL(`${baseUrl}/requests`); | ||
|
||
const response = await sendRequest<any>(url, { | ||
method: HttpMethod.GET, | ||
authRequired: true, | ||
}); | ||
return response; | ||
}; | ||
|
||
export const approveEventRequest = async (slug: string): Promise<any> => { | ||
const url = new URL(`${baseUrl}/requests/${slug}`); | ||
|
||
const response = await sendRequest<any>(url, { | ||
method: HttpMethod.POST, | ||
authRequired: true, | ||
}); | ||
return response; | ||
}; | ||
|
||
export const addEventImage = async ( | ||
slug: string, | ||
images: Blob[], | ||
): Promise<any> => { | ||
const url = new URL(`${baseUrl}/${slug}/images`); | ||
|
||
const formData = new FormData(); | ||
images.forEach((image) => { | ||
formData.append("images", image); | ||
}); | ||
|
||
const response = await sendRequest<any>(url, { | ||
method: HttpMethod.POST, | ||
body: formData, | ||
authRequired: true, | ||
}); | ||
return response; | ||
}; | ||
|
||
export const updateEventImage = async ( | ||
slug: string, | ||
images: Blob[], | ||
): Promise<any> => { | ||
const url = new URL(`${baseUrl}/${slug}/images`); | ||
|
||
const formData = new FormData(); | ||
images.forEach((image) => { | ||
formData.append("images", image); | ||
}); | ||
|
||
const response = await sendRequest<any>(url, { | ||
method: HttpMethod.PUT, | ||
body: formData, | ||
authRequired: true, | ||
}); | ||
return response; | ||
}; | ||
|
||
export const getEventImages = async (slug: string): Promise<any> => { | ||
const url = new URL(`${baseUrl}/${slug}/images`); | ||
|
||
const response = await sendRequest<any>(url, { method: HttpMethod.GET }); | ||
return response; | ||
}; | ||
|
||
export const getEventParticipants = async (slug: string): Promise<any> => { | ||
const url = new URL(`${baseUrl}/${slug}/participants`); | ||
|
||
const response = await sendRequest<any>(url, { method: HttpMethod.GET }); | ||
return response; | ||
}; | ||
|
||
export const getEventComments = async (slug: string): Promise<any> => { | ||
const url = new URL(`${baseUrl}/${slug}/comments`); | ||
|
||
const response = await sendRequest<any>(url, { method: HttpMethod.GET }); | ||
return response; | ||
}; | ||
|
||
export const addEventComment = async ( | ||
slug: string, | ||
comment: any, | ||
): Promise<any> => { | ||
const url = new URL(`${baseUrl}/${slug}/comments`); | ||
|
||
const response = await sendRequest<any>(url, { | ||
method: HttpMethod.POST, | ||
body: comment, | ||
authRequired: true, | ||
}); | ||
return response; | ||
}; | ||
|
||
export const getEventsParameters = async (): Promise<any> => { | ||
const url = new URL(`${baseUrl}/parameters`); | ||
|
||
const response = await sendRequest<any>(url, { | ||
method: HttpMethod.GET, | ||
authRequired: true, | ||
}); | ||
return response; | ||
}; | ||
|
||
export const getEventsTags = async (): Promise<any> => { | ||
const url = new URL(`${baseUrl}/tags`); | ||
|
||
const response = await sendRequest<any>(url, { | ||
method: HttpMethod.GET, | ||
authRequired: true, | ||
}); | ||
return response; | ||
}; | ||
|
||
export const deleteEventsTag = async (tagId: number): Promise<any> => { | ||
const url = new URL(`${baseUrl}/tags/${tagId}`); | ||
|
||
const response = await sendRequest<any>(url, { | ||
method: HttpMethod.DELETE, | ||
authRequired: true, | ||
}); | ||
return response; | ||
}; |
Oops, something went wrong.