feat: frontend
This commit is contained in:
81
ordr-ui/app/client/controllers/UserController.ts
Normal file
81
ordr-ui/app/client/controllers/UserController.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import axios, { HttpStatusCode } from 'axios'
|
||||
import { UserResponse } from '../response/UserResponse'
|
||||
import { UserTable } from '../queries/UserTableQuery'
|
||||
import { LoginRedirectResponse } from '../response'
|
||||
|
||||
// import { cookies } from 'next/headers'
|
||||
|
||||
export const GetCurrentUser = async (): Promise<UserResponse | undefined> => {
|
||||
console.log(process.env.NEXT_PUBLIC_API_URL + "/user/current")
|
||||
const res = await axios.get(process.env.NEXT_PUBLIC_API_URL + "/user/current", {
|
||||
maxRedirects: 0,
|
||||
validateStatus: (status) => {
|
||||
return status >= 200 && status < 400
|
||||
}});
|
||||
if(res.data.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const GetUserTable = async (page: number): Promise<UserResponse[]> => {
|
||||
const res = await axios.put(process.env.NEXT_PUBLIC_API_URL + `/users?page=${page.toString()}`, {
|
||||
name: "",
|
||||
jobPosition: ""
|
||||
}, {
|
||||
withCredentials: true
|
||||
});
|
||||
if (res.data.Location)
|
||||
window.location.href = res.data.Location
|
||||
return res.data || []
|
||||
}
|
||||
|
||||
export const SetUserName = async (userName: string) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
user_name: userName
|
||||
});
|
||||
await axios.put(process.env.NEXT_PUBLIC_API_URL + `/user/name?${queryParams.toString()}`)
|
||||
}
|
||||
|
||||
export const PromoteUser = async (userId: number) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
user_id: userId.toString()
|
||||
});
|
||||
await axios.put(process.env.NEXT_PUBLIC_API_URL + `/user/promote?${queryParams.toString()}`, {}, {withCredentials: true});
|
||||
}
|
||||
|
||||
export const DemoteUser = async (userId: number) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
user_id: userId.toString()
|
||||
})
|
||||
await axios.put(process.env.NEXT_PUBLIC_API_URL + `/user/demote?${queryParams.toString()}`, {}, {withCredentials: true})
|
||||
}
|
||||
|
||||
export const DeactivateUser = async (userId: number) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
user_id: userId.toString()
|
||||
})
|
||||
await axios.delete(process.env.NEXT_PUBLIC_API_URL + `/user/deactivate?${queryParams.toString()}`, {withCredentials: true})
|
||||
}
|
||||
|
||||
export const ActivateUser = async (userId: number) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
user_id: userId.toString()
|
||||
})
|
||||
await axios.put(process.env.NEXT_PUBLIC_API_URL + `/user/activate?${queryParams.toString()}`, {}, {withCredentials: true})
|
||||
}
|
||||
|
||||
export const CreatePosition = async (positionName: string) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
position_name: positionName
|
||||
})
|
||||
await axios.post(process.env.NEXT_PUBLIC_API_URL + `/position/create?` + queryParams.toString())
|
||||
}
|
||||
|
||||
export const SetUserPosition = async (userId: number, positionName: string) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
user_id: userId.toString(),
|
||||
position: positionName
|
||||
})
|
||||
await axios.put(process.env.NEXT_PUBLIC_API_URL + `/user/position?${queryParams.toString}`)
|
||||
}
|
||||
Reference in New Issue
Block a user