Update eslint to type check
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { Account } from "@/interface/Account";
|
||||
import { AccountTutorialStatus } from "@/interface/AccountTutorialStatus";
|
||||
import { Counter } from "@/interface/Counters";
|
||||
import { RaidGroupPermissionType } from "@/interface/RaidGroup";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import api from "@/util/AxiosUtil";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
|
||||
export function useGetAccounts(page: number, pageSize: number, searchTerm?: string){
|
||||
@@ -17,23 +17,9 @@ export function useGetAccounts(page: number, pageSize: number, searchTerm?: stri
|
||||
params.append("searchTerm", searchTerm ?? "");
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.get(`/account?${params}`);
|
||||
const response = await api.get(`/account?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as Account[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as Account[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -49,23 +35,9 @@ export function useGetAccountsByRaidGroup(raidGroupId: string, page: number, pag
|
||||
params.append("searchTerm", searchTerm ?? "");
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.get(`/account/raidGroup/${raidGroupId}?${params}`);
|
||||
const response = await api.get(`/account/raidGroup/${raidGroupId}?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as Account[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as Account[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -74,23 +46,9 @@ export function useGetRaidGroupPermissionsForAccount(raidGroupId?: string, accou
|
||||
return useQuery({
|
||||
queryKey: ["accounts", "raidGroup", raidGroupId, "account", accountId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/account/${accountId}/raidGroup/${raidGroupId}/permission`);
|
||||
const response = await api.get(`/account/${accountId}/raidGroup/${raidGroupId}/permission`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.permission as RaidGroupPermissionType;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as {permission: RaidGroupPermissionType;}).permission;
|
||||
},
|
||||
enabled: !!raidGroupId && !!accountId
|
||||
});
|
||||
@@ -107,23 +65,9 @@ export function useGetAccountsCount(searchTerm?: string){
|
||||
return useQuery({
|
||||
queryKey: [ "accounts", "count", searchTerm],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/account/count?${searchParams}`);
|
||||
const response = await api.get(`/account/count?${searchParams}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Counter).count;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -138,23 +82,9 @@ export function useGetAccountsByRaidGroupCount(raidGroupId: string, searchTerm?:
|
||||
return useQuery({
|
||||
queryKey: [ "accounts", "raidGroup", raidGroupId, "count", searchTerm],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/account/raidGroup/${raidGroupId}/count?${searchParams}`);
|
||||
const response = await api.get(`/account/raidGroup/${raidGroupId}/count?${searchParams}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Counter).count;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -163,23 +93,9 @@ export function useGetTutorialsStatus(accountId: string | null){
|
||||
return useQuery({
|
||||
queryKey: ["tutorials", "account", accountId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/account/tutorial`);
|
||||
const response = await api.get(`/account/tutorial`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as AccountTutorialStatus;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as AccountTutorialStatus;
|
||||
},
|
||||
enabled: !!accountId
|
||||
});
|
||||
@@ -189,21 +105,7 @@ export function useUpdateTutorialsStatus(){
|
||||
return useMutation({
|
||||
mutationKey: ["tutorials", "accounts"],
|
||||
mutationFn: async (tutorials: AccountTutorialStatus) => {
|
||||
try{
|
||||
const response = await api.put(`/account/tutorial`, tutorials);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/account/tutorial`, tutorials);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -212,20 +114,10 @@ export function useUpdatePassword(){
|
||||
return useMutation({
|
||||
mutationKey: ["updatePassword"],
|
||||
mutationFn: async ({currentPassword, newPassword}:{currentPassword: string; newPassword: string;}) => {
|
||||
try{
|
||||
await api.post("/auth/resetPassword", {
|
||||
currentPassword,
|
||||
newPassword
|
||||
});
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post("/auth/resetPassword", {
|
||||
currentPassword,
|
||||
newPassword
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -239,24 +131,10 @@ export function useForcePasswordReset(accountId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["forcePasswordReset", accountId],
|
||||
mutationFn: async () => {
|
||||
try{
|
||||
const response = await api.put(`/account/${accountId}/forcePasswordReset`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/account/${accountId}/forcePasswordReset`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -268,26 +146,12 @@ export function useResetPassword(accountId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["resetPassword", accountId],
|
||||
mutationFn: async (password: string) => {
|
||||
try{
|
||||
const response = await api.put(`/account/${accountId}/resetPassword`, {
|
||||
password
|
||||
});
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/account/${accountId}/resetPassword`, {
|
||||
password
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -299,24 +163,10 @@ export function useRevokeRefreshToken(accountId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["revokeRefreshToken", accountId],
|
||||
mutationFn: async () => {
|
||||
try{
|
||||
const response = await api.put(`/account/${accountId}/revokeRefreshToken`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/account/${accountId}/revokeRefreshToken`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -328,24 +178,10 @@ export function useCreateAccount(){
|
||||
return useMutation({
|
||||
mutationKey: ["createAccount"],
|
||||
mutationFn: async (account: Account) => {
|
||||
try{
|
||||
const response = await api.post("/account", account);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post("/account", account);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -357,24 +193,10 @@ export function useUpdateAccount(){
|
||||
return useMutation({
|
||||
mutationKey: ["updateAccount"],
|
||||
mutationFn: async (account: Account) => {
|
||||
try{
|
||||
const response = await api.put(`/account/${account.accountId}`, account);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/account/${account.accountId}`, account);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -386,26 +208,12 @@ export function useUpdateRaidGroupPermissionsForAccount(raidGroupId?: string, ac
|
||||
return useMutation({
|
||||
mutationKey: ["updateRaidGroupPermissionsForAccount", raidGroupId, accountId],
|
||||
mutationFn: async (permission: RaidGroupPermissionType) => {
|
||||
try{
|
||||
const response = await api.put(`/account/${accountId}/raidGroup/${raidGroupId}/permission`, {
|
||||
permission
|
||||
});
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/account/${accountId}/raidGroup/${raidGroupId}/permission`, {
|
||||
permission
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -417,24 +225,10 @@ export function useDeleteAccount(accountId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["deleteAccount", accountId],
|
||||
mutationFn: async () => {
|
||||
try{
|
||||
const response = await api.delete(`/account/${accountId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.delete(`/account/${accountId}`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -447,24 +241,10 @@ export function useRemoveAccountFromRaidGroup(raidGroupId?: string, accountId?:
|
||||
return useMutation({
|
||||
mutationKey: ["removeAccountFromRaidGroup", raidGroupId, accountId],
|
||||
mutationFn: async () => {
|
||||
try{
|
||||
const response = await api.delete(`/account/${accountId}/raidGroup/${raidGroupId}/permission`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.delete(`/account/${accountId}/raidGroup/${raidGroupId}/permission`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["accounts"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,28 +1,13 @@
|
||||
import { Account } from "@/interface/Account";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import api from "@/util/AxiosUtil";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
|
||||
export function useSignup(){
|
||||
return useMutation({
|
||||
mutationKey: ["signup"],
|
||||
mutationFn: async (account: Account) => {
|
||||
try{
|
||||
const response = await api.post("/auth/signup", account);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post("/auth/signup", account);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -32,21 +17,7 @@ export function useConfirm(){
|
||||
return useMutation({
|
||||
mutationKey: ["confirm"],
|
||||
mutationFn: async (confirmToken: string) => {
|
||||
try{
|
||||
const response = await api.post(`/auth/confirm/${confirmToken}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post(`/auth/confirm/${confirmToken}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -59,21 +30,7 @@ export function useForgotPassword(){
|
||||
params.append("username", username);
|
||||
|
||||
|
||||
try{
|
||||
const response = await api.post(`/auth/forgot?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post(`/auth/forgot?${params}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -82,21 +39,7 @@ export function useForgotResetPassword(forgotToken: string){
|
||||
return useMutation({
|
||||
mutationKey: ["forgotResetPassword"],
|
||||
mutationFn: async (password: string) => {
|
||||
try{
|
||||
const response = await api.post(`/auth/forgot/${forgotToken}`, {password});
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post(`/auth/forgot/${forgotToken}`, {password});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,30 +1,15 @@
|
||||
import { CalendarEvent } from "@/interface/Calendar";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import api from "@/util/AxiosUtil";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
|
||||
export function useGetGameCalendar(gameId: string){
|
||||
return useQuery({
|
||||
queryKey: ["gameCalendar", gameId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/calendar/game/${gameId}`);
|
||||
const response = await api.get(`/calendar/game/${gameId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as CalendarEvent[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as CalendarEvent[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -33,23 +18,9 @@ export function useGetRaidGroupCalendar(raidGroupId: string){
|
||||
return useQuery({
|
||||
queryKey: ["raidGroupCalendar", raidGroupId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/calendar/raidGroup/${raidGroupId}`);
|
||||
const response = await api.get(`/calendar/raidGroup/${raidGroupId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as CalendarEvent[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as CalendarEvent[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -61,24 +32,10 @@ export function useCreateGameCalendarEvent(gameId: string){
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (calendarEvent: CalendarEvent) => {
|
||||
try{
|
||||
const response = await api.post(`/calendar/game/${gameId}`, {...calendarEvent, gameCalendarEventId: calendarEvent.calendarEventId, calendarEventId: undefined});
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post(`/calendar/game/${gameId}`, {...calendarEvent, gameCalendarEventId: calendarEvent.calendarEventId, calendarEventId: undefined});
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["gameCalendar"]})
|
||||
void queryClient.invalidateQueries({ queryKey: ["gameCalendar"]})
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -89,29 +46,15 @@ export function useUpdateGameCalendarEvent(gameId: string){
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (calendarEvent: CalendarEvent) => {
|
||||
try{
|
||||
const response = await api.put(`/calendar/game/${gameId}`,
|
||||
{
|
||||
...calendarEvent,
|
||||
gameCalendarEventId: calendarEvent.calendarEventId,
|
||||
calendarEventId: undefined
|
||||
});
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/calendar/game/${gameId}`,
|
||||
{
|
||||
...calendarEvent,
|
||||
gameCalendarEventId: calendarEvent.calendarEventId,
|
||||
calendarEventId: undefined
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["gameCalendar"]})
|
||||
void queryClient.invalidateQueries({ queryKey: ["gameCalendar"]})
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -122,24 +65,10 @@ export function useDeleteGameCalendarEvent(gameId: string){
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (calendarEvent: CalendarEvent) => {
|
||||
try{
|
||||
const response = await api.delete(`/calendar/game/${gameId}/${calendarEvent.calendarEventId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.delete(`/calendar/game/${gameId}/${calendarEvent.calendarEventId}`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["gameCalendar"]})
|
||||
void queryClient.invalidateQueries({ queryKey: ["gameCalendar"]})
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -150,29 +79,15 @@ export function useCreateRaidGroupCalendarEvent(raidGroupId: string){
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (calendarEvent: CalendarEvent) => {
|
||||
try{
|
||||
const response = await api.post(`/calendar/raidGroup/${raidGroupId}`,
|
||||
{
|
||||
...calendarEvent,
|
||||
raidGroupCalendarEventId: calendarEvent.calendarEventId,
|
||||
calendarEventId: undefined
|
||||
});
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post(`/calendar/raidGroup/${raidGroupId}`,
|
||||
{
|
||||
...calendarEvent,
|
||||
raidGroupCalendarEventId: calendarEvent.calendarEventId,
|
||||
calendarEventId: undefined
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidGroupCalendar"]})
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidGroupCalendar"]})
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -183,24 +98,10 @@ export function useUpdateRaidGroupCalendarEvent(raidGroupId: string){
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (calendarEvent: CalendarEvent) => {
|
||||
try{
|
||||
const response = await api.put(`/calendar/raidGroup/${raidGroupId}`, {...calendarEvent, raidGroupCalendarEventId: calendarEvent.calendarEventId, calendarEventId: undefined});
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/calendar/raidGroup/${raidGroupId}`, {...calendarEvent, raidGroupCalendarEventId: calendarEvent.calendarEventId, calendarEventId: undefined});
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidGroupCalendar"]})
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidGroupCalendar"]})
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -211,24 +112,10 @@ export function useDeleteRaidGroupCalendarEvent(raidGroupId: string){
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (calendarEvent: CalendarEvent) => {
|
||||
try{
|
||||
const response = await api.delete(`/calendar/raidGroup/${raidGroupId}/${calendarEvent.calendarEventId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.delete(`/calendar/raidGroup/${raidGroupId}/${calendarEvent.calendarEventId}`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidGroupCalendar"]})
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidGroupCalendar"]})
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -237,23 +124,9 @@ export function useGetRaidInstanceCalendarEvents(raidGroupId?: string){
|
||||
return useQuery({
|
||||
queryKey: ["raidInstanceCalendarEvents", raidGroupId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/calendar/raidGroup/${raidGroupId}/raidInstance`);
|
||||
const response = await api.get(`/calendar/raidGroup/${raidGroupId}/raidInstance`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as CalendarEvent[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as CalendarEvent[];
|
||||
},
|
||||
enabled: !!raidGroupId && raidGroupId !== ""
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ClassGroup } from "@/interface/ClassGroup";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import { Counter } from "@/interface/Counters";
|
||||
import api from "@/util/AxiosUtil";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
|
||||
export function useGetClassGroups(raidGroupId: string, page: number, pageSize: number, searchTerm?: string){
|
||||
@@ -15,23 +15,9 @@ export function useGetClassGroups(raidGroupId: string, page: number, pageSize: n
|
||||
params.append("searchTerm", searchTerm);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/classGroup?${params}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/classGroup?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as ClassGroup[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as ClassGroup[];
|
||||
},
|
||||
enabled: !!raidGroupId
|
||||
});
|
||||
@@ -47,23 +33,9 @@ export function useGetClassGroupsCount(raidGroupId: string, searchTerm?: string)
|
||||
return useQuery({
|
||||
queryKey: ["classGroups", "count", searchTerm],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/classGroup/count?${searchParams}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/classGroup/count?${searchParams}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Counter).count;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -72,23 +44,9 @@ export function useGetClassGroupsByRaidLayout(raidGroupId: string, raidLayoutId:
|
||||
return useQuery({
|
||||
queryKey: ["classGroups", "raidLayout", raidLayoutId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/classGroup/raidLayout/${raidLayoutId}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/classGroup/raidLayout/${raidLayoutId}`);
|
||||
|
||||
if(response.data.error){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as (ClassGroup | null)[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as (ClassGroup | null)[];
|
||||
},
|
||||
enabled: !!raidGroupId && !!raidLayoutId
|
||||
})
|
||||
@@ -102,31 +60,17 @@ export function useCreateClassGroup(raidGroupId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["createClassGroup"],
|
||||
mutationFn: async ({classGroupName, gameClassIds}:{classGroupName: string; gameClassIds: string[];}) => {
|
||||
try{
|
||||
const response = await api.post(`/raidGroup/${raidGroupId}/classGroup`,
|
||||
{
|
||||
classGroup: {
|
||||
classGroupName: classGroupName,
|
||||
raidGroupId: raidGroupId
|
||||
},
|
||||
gameClassIds
|
||||
});
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post(`/raidGroup/${raidGroupId}/classGroup`,
|
||||
{
|
||||
classGroup: {
|
||||
classGroupName: classGroupName,
|
||||
raidGroupId: raidGroupId
|
||||
},
|
||||
gameClassIds
|
||||
});
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({queryKey: ["classGroups"]});
|
||||
void queryClient.invalidateQueries({queryKey: ["classGroups"]});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -138,30 +82,16 @@ export function useUpdateClassGroup(raidGroupId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["updateClassGroup"],
|
||||
mutationFn: async ({classGroup, gameClassIds}:{classGroup: ClassGroup; gameClassIds: string[];}) => {
|
||||
try{
|
||||
const response = await api.put(`/raidGroup/${raidGroupId}/classGroup/${classGroup.classGroupId}`,
|
||||
{
|
||||
classGroup,
|
||||
gameClassIds
|
||||
}
|
||||
);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
await api.put(`/raidGroup/${raidGroupId}/classGroup/${classGroup.classGroupId}`,
|
||||
{
|
||||
classGroup,
|
||||
gameClassIds
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({queryKey: ["gameClasses", "classGroups"]});
|
||||
queryClient.invalidateQueries({queryKey: ["classGroups"]});
|
||||
void queryClient.invalidateQueries({queryKey: ["gameClasses", "classGroups"]});
|
||||
void queryClient.invalidateQueries({queryKey: ["classGroups"]});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -173,24 +103,10 @@ export function useDeleteClassGroup(raidGroupId: string, classGroupId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["deleteClassGroup", classGroupId, raidGroupId],
|
||||
mutationFn: async () => {
|
||||
try{
|
||||
const response = await api.delete(`/raidGroup/${raidGroupId}/classGroup/${classGroupId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.delete(`/raidGroup/${raidGroupId}/classGroup/${classGroupId}`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({queryKey: ["classGroups"]});
|
||||
void queryClient.invalidateQueries({queryKey: ["classGroups"]});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,30 +1,16 @@
|
||||
import { Counter } from "@/interface/Counters";
|
||||
import { GameClass } from "@/interface/GameClass";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import api from "@/util/AxiosUtil";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
|
||||
export function useGetGameClass(gameClassId: string){
|
||||
return useQuery({
|
||||
queryKey: ["gameClasses", gameClassId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/gameClass/${gameClassId}`);
|
||||
const response = await api.get(`/gameClass/${gameClassId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as GameClass;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as GameClass;
|
||||
},
|
||||
enabled: !!gameClassId
|
||||
})
|
||||
@@ -41,23 +27,9 @@ export function useGetGameClasses(gameId: string, page: number, pageSize: number
|
||||
params.append("searchTerm", searchTerm);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.get(`/gameClass/game/${gameId}?${params}`);
|
||||
const response = await api.get(`/gameClass/game/${gameId}?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as GameClass[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as GameClass[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -66,23 +38,9 @@ export function useGetGameClassesByClassGroup(classGroupId?: string){
|
||||
return useQuery({
|
||||
queryKey: ["gameClasses", "classGroups", classGroupId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/gameClass/classGroup/${classGroupId}`);
|
||||
const response = await api.get(`/gameClass/classGroup/${classGroupId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as GameClass[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as GameClass[];
|
||||
},
|
||||
enabled: !!classGroupId
|
||||
});
|
||||
@@ -99,23 +57,9 @@ export function useGetGameClassesCount(gameId: string, searchTerm?: string){
|
||||
return useQuery({
|
||||
queryKey: ["gameClasses", gameId, "count", searchTerm],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/gameClass/game/${gameId}/count?${searchParams}`);
|
||||
const response = await api.get(`/gameClass/game/${gameId}/count?${searchParams}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Counter).count;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -135,27 +79,13 @@ export function useCreateGameClass(){
|
||||
formData.append("gameClassName", gameClassName);
|
||||
formData.append("gameId", gameId);
|
||||
|
||||
try{
|
||||
const response = await api.post(
|
||||
`/gameClass/game/${gameId}`,
|
||||
formData
|
||||
);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post(
|
||||
`/gameClass/game/${gameId}`,
|
||||
formData
|
||||
);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["gameClasses"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["gameClasses"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -177,24 +107,10 @@ export function useUpdateGameClass(){
|
||||
formData.append("gameClassIcon", gameClass.gameClassIcon);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.put(`/gameClass/${gameClass.gameClassId}/game/${gameClass.gameId}`, formData);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/gameClass/${gameClass.gameClassId}/game/${gameClass.gameId}`, formData);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["gameClasses"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["gameClasses"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -206,24 +122,10 @@ export function useDeleteGameClass(){
|
||||
return useMutation({
|
||||
mutationKey: ["deleteGameClass"],
|
||||
mutationFn: async (gameClass: GameClass) => {
|
||||
try{
|
||||
const response = await api.delete(`/gameClass/${gameClass.gameClassId}/game/${gameClass.gameId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.delete(`/gameClass/${gameClass.gameClassId}/game/${gameClass.gameId}`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["gameClasses"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["gameClasses"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,30 +1,16 @@
|
||||
import { Counter } from "@/interface/Counters";
|
||||
import { Game } from "@/interface/Game";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import api from "@/util/AxiosUtil";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
|
||||
export function useGetGame(gameId: string, disabled: boolean){
|
||||
return useQuery({
|
||||
queryKey: ["games", gameId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/game/${gameId}`);
|
||||
const response = await api.get(`/game/${gameId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data?.gameId ? response.data as Game : undefined;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Game)?.gameId ? response.data as Game : undefined;
|
||||
},
|
||||
enabled: !disabled
|
||||
});
|
||||
@@ -41,19 +27,9 @@ export function useGetGames(page: number, pageSize: number, searchTerm?: string)
|
||||
params.append("searchTerm", searchTerm);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.get(`/game?${params}`);
|
||||
const response = await api.get(`/game?${params}`);
|
||||
|
||||
return response.data as Game[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as Game[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -68,23 +44,9 @@ export function useGetGamesCount(searchTerm?: string){
|
||||
return useQuery({
|
||||
queryKey: ["games", "count", searchTerm],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/game/count?${searchParams}`);
|
||||
const response = await api.get(`/game/count?${searchParams}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Counter).count;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -102,27 +64,13 @@ export function useCreateGame(){
|
||||
}
|
||||
formData.append("gameName", gameName);
|
||||
|
||||
try{
|
||||
const response = await api.post(
|
||||
"/game",
|
||||
formData
|
||||
);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post(
|
||||
"/game",
|
||||
formData
|
||||
);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["games"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["games"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -143,24 +91,10 @@ export function useUpdateGame(){
|
||||
formData.append("gameIcon", game.gameIcon);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.put(`/game/${game.gameId}`, formData);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/game/${game.gameId}`, formData);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["games"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["games"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -172,24 +106,10 @@ export function useDeleteGame(){
|
||||
return useMutation({
|
||||
mutationKey: ["deleteGame"],
|
||||
mutationFn: async (gameId: string) => {
|
||||
try{
|
||||
const response = await api.delete(`/game/${gameId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.delete(`/game/${gameId}`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["games"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["games"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,30 +1,16 @@
|
||||
import { Counter } from "@/interface/Counters";
|
||||
import { PersonCharacter } from "@/interface/PersonCharacter";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import api from "@/util/AxiosUtil";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
|
||||
export function useGetPersonCharactersByPersonId(personId: string, raidGroupId: string){
|
||||
return useQuery({
|
||||
queryKey: ["personCharacters", personId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person/${personId}/character`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person/${personId}/character`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as PersonCharacter[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as PersonCharacter[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -41,23 +27,9 @@ export function useGetPersonCharactersByPersonIdSearch(personId: string, raidGro
|
||||
return useQuery({
|
||||
queryKey: ["personCharacters", personId, { page, pageSize, searchTerm }],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person/${personId}/character/page?${params}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person/${personId}/character/page?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as PersonCharacter[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as PersonCharacter[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -71,23 +43,9 @@ export function useGetPersonCharactersCountByPersonIdSearch(personId: string, ra
|
||||
return useQuery({
|
||||
queryKey: ["personCharactersCount", personId, { searchTerm }],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person/${personId}/character/count?${params}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person/${personId}/character/count?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Counter).count;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -96,23 +54,9 @@ export function useGetPersonCharactersByRaidGroup(raidGroupId: string){
|
||||
return useQuery({
|
||||
queryKey: ["personCharacters", raidGroupId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person/character`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person/character`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as PersonCharacter[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as PersonCharacter[];
|
||||
},
|
||||
enabled: !!raidGroupId
|
||||
});
|
||||
@@ -125,24 +69,10 @@ export function useCreatePersonCharacter(raidGroupId: string, personId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["createPersonCharacter"],
|
||||
mutationFn: async (personCharacter: PersonCharacter) => {
|
||||
try{
|
||||
const response = await api.post(`/raidGroup/${raidGroupId}/person/${personId}/character`, personCharacter);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post(`/raidGroup/${raidGroupId}/person/${personId}/character`, personCharacter);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["personCharacters"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["personCharacters"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -154,24 +84,10 @@ export function useUpdatePersonCharacter(raidGroupId: string, personId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["updatePersonCharacter"],
|
||||
mutationFn: async (personCharacter: PersonCharacter) => {
|
||||
try{
|
||||
const response = await api.put(`/raidGroup/${raidGroupId}/person/${personId}/character/${personCharacter.personCharacterId}`, personCharacter);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/raidGroup/${raidGroupId}/person/${personId}/character/${personCharacter.personCharacterId}`, personCharacter);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["personCharacters"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["personCharacters"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -183,24 +99,10 @@ export function useDeletePersonCharacter(raidGroupId: string, personId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["deletePersonCharacter"],
|
||||
mutationFn: async (personCharacterId: string) => {
|
||||
try{
|
||||
const response = await api.delete(`/raidGroup/${raidGroupId}/person/${personId}/character/${personCharacterId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.delete(`/raidGroup/${raidGroupId}/person/${personId}/character/${personCharacterId}`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["personCharacters"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["personCharacters"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,30 +1,16 @@
|
||||
import { Counter } from "@/interface/Counters";
|
||||
import { Person } from "@/interface/Person";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import api from "@/util/AxiosUtil";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
|
||||
export function useGetPerson(raidGroupId: string, personId: string, disabled: boolean){
|
||||
return useQuery({
|
||||
queryKey: ["people", raidGroupId, personId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person/${personId}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person/${personId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as Person;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as Person;
|
||||
},
|
||||
enabled: !disabled
|
||||
});
|
||||
@@ -41,23 +27,9 @@ export function useGetPeopleByRaidGroup(raidGroupId: string, page: number, pageS
|
||||
searchParams.append("searchTerm", searchTerm);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person?${searchParams}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person?${searchParams}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as Person[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as Person[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -72,23 +44,9 @@ export function useGetPeopleByRaidGroupCount(raidGroupId: string, searchTerm?: s
|
||||
return useQuery({
|
||||
queryKey: ["people", raidGroupId, "count", searchTerm],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person/count?${searchParams}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/person/count?${searchParams}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Counter).count;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -100,24 +58,10 @@ export function useCreatePerson(){
|
||||
return useMutation({
|
||||
mutationKey: ["createPerson"],
|
||||
mutationFn: async ({raidGroupId, personName, discordId}:{raidGroupId: string; personName: string; discordId?: string;}) => {
|
||||
try{
|
||||
const response = await api.post(`/raidGroup/${raidGroupId}/person`, {raidGroupId, personName, discordId});
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post(`/raidGroup/${raidGroupId}/person`, {raidGroupId, personName, discordId});
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["people"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["people"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -129,24 +73,10 @@ export function useUpdatePerson(){
|
||||
return useMutation({
|
||||
mutationKey: ["updatePerson"],
|
||||
mutationFn: async (person: Person) => {
|
||||
try{
|
||||
const response = await api.put(`/raidGroup/${person.raidGroupId}/person/${person.personId}`, person);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/raidGroup/${person.raidGroupId}/person/${person.personId}`, person);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["people"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["people"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -158,24 +88,10 @@ export function useDeletePerson(){
|
||||
return useMutation({
|
||||
mutationKey: ["deletePerson"],
|
||||
mutationFn: async ({raidGroupId, personId}:{raidGroupId: string; personId: string;}) => {
|
||||
try{
|
||||
const response = await api.delete(`/raidGroup/${raidGroupId}/person/${personId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.delete(`/raidGroup/${raidGroupId}/person/${personId}`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["people"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["people"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,30 +1,16 @@
|
||||
import { Counter } from "@/interface/Counters";
|
||||
import { RaidGroup } from "@/interface/RaidGroup";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import api from "@/util/AxiosUtil";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
|
||||
export function useGetRaidGroup(raidGroupId: string, disabled: boolean){
|
||||
return useQuery({
|
||||
queryKey: ["raidGroups", raidGroupId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data?.raidGroupId ? response.data as RaidGroup : undefined;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as RaidGroup)?.raidGroupId ? response.data as RaidGroup : undefined;
|
||||
},
|
||||
enabled: !disabled
|
||||
});
|
||||
@@ -41,23 +27,9 @@ export function useGetRaidGroups(page: number, pageSize: number, searchTerm?: st
|
||||
params.append("searchTerm", searchTerm);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.get(`/raidGroup?${params}`);
|
||||
const response = await api.get(`/raidGroup?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as RaidGroup[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as RaidGroup[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -72,23 +44,9 @@ export function useGetRaidGroupsCount(searchTerm?: string){
|
||||
return useQuery({
|
||||
queryKey: ["raidGroups", "count", searchTerm],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/count?${searchParams}`);
|
||||
const response = await api.get(`/raidGroup/count?${searchParams}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Counter).count;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -104,23 +62,9 @@ export function useGetRaidGroupsByGame(gameId: string, page: number, pageSize: n
|
||||
params.append("searchTerm", searchTerm);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/game/${gameId}?${params}`);
|
||||
const response = await api.get(`/raidGroup/game/${gameId}?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as RaidGroup[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as RaidGroup[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -135,23 +79,9 @@ export function useGetRaidGroupsByGameCount(gameId: string, searchTerm?: string)
|
||||
return useQuery({
|
||||
queryKey: ["raidGroups", gameId, "count", searchTerm],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/game/${gameId}/count?${searchParams}`);
|
||||
const response = await api.get(`/raidGroup/game/${gameId}/count?${searchParams}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Counter).count;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -167,23 +97,9 @@ export function useGetRaidGroupsByAccount(accountId: string, page: number, pageS
|
||||
params.append("searchTerm", searchTerm);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/account/${accountId}?${params}`);
|
||||
const response = await api.get(`/raidGroup/account/${accountId}?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as RaidGroup[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as RaidGroup[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -198,23 +114,9 @@ export function useGetRaidGroupsCountByAccount(accountId: string, searchTerm?: s
|
||||
return useQuery({
|
||||
queryKey: ["raidGroups", accountId, "count", searchTerm],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/account/${accountId}/count?${searchParams}`);
|
||||
const response = await api.get(`/raidGroup/account/${accountId}/count?${searchParams}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Counter).count;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -235,27 +137,13 @@ export function useCreateRaidGroup(){
|
||||
formData.append("raidGroupName", raidGroupName);
|
||||
formData.append("gameId", gameId);
|
||||
|
||||
try{
|
||||
const response = await api.post(
|
||||
"/raidGroup",
|
||||
formData
|
||||
);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post(
|
||||
"/raidGroup",
|
||||
formData
|
||||
);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidGroups"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidGroups"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -277,24 +165,10 @@ export function useUpdateRaidGroup(){
|
||||
formData.append("raidGroupIcon", raidGroup.raidGroupIcon);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.put(`/raidGroup/${raidGroup.raidGroupId}`, formData);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/raidGroup/${raidGroup.raidGroupId}`, formData);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidGroups"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidGroups"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -306,24 +180,10 @@ export function useDeleteRaidGroup(){
|
||||
return useMutation({
|
||||
mutationKey: ["deleteRaidGroup"],
|
||||
mutationFn: async (raidGroupId: string) => {
|
||||
try{
|
||||
const response = await api.delete(`/raidGroup/${raidGroupId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.delete(`/raidGroup/${raidGroupId}`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidGroups"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidGroups"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Counter } from "@/interface/Counters";
|
||||
import { RaidGroupPermissionType } from "@/interface/RaidGroup";
|
||||
import { RaidGroupRequest } from "@/interface/RaidGroupRequest";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import api from "@/util/AxiosUtil";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
|
||||
export function useGetRaidGroupRequests(raidGroupId: string, page: number, pageSize: number, searchTerm?: string){
|
||||
@@ -16,23 +16,9 @@ export function useGetRaidGroupRequests(raidGroupId: string, page: number, pageS
|
||||
return useQuery({
|
||||
queryKey: ["raidGroupRequest", raidGroupId, {page, pageSize, searchTerm}],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidGroupRequest?${searchParams}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidGroupRequest?${searchParams}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as RaidGroupRequest[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as RaidGroupRequest[];
|
||||
},
|
||||
enabled: !!raidGroupId && raidGroupId !== ""
|
||||
});
|
||||
@@ -47,23 +33,9 @@ export function useGetRaidGroupRequestCount(raidGroupId?: string, searchTerm?: s
|
||||
return useQuery({
|
||||
queryKey: ["raidGroupRequest", raidGroupId, "count", searchTerm],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidGroupRequest/count?${searchParams}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidGroupRequest/count?${searchParams}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Counter).count;
|
||||
},
|
||||
enabled: !!raidGroupId && raidGroupId !== ""
|
||||
});
|
||||
@@ -76,24 +48,10 @@ export function useCreateRaidGroupRequest(raidGroupId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["raidGroupRequest", raidGroupId],
|
||||
mutationFn: async (requestMessage: string) => {
|
||||
try{
|
||||
const response = await api.post(`/raidGroup/${raidGroupId}/raidGroupRequest`, {requestMessage});
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post(`/raidGroup/${raidGroupId}/raidGroupRequest`, {requestMessage});
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidGroupRequest", raidGroupId] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidGroupRequest", raidGroupId] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -104,24 +62,10 @@ export function useResolveRaidGroupRequest(raidGroupId: string, raidGroupRequest
|
||||
return useMutation({
|
||||
mutationKey: ["raidGroupRequest", raidGroupId, raidGroupRequestId],
|
||||
mutationFn: async (permission: RaidGroupPermissionType) => {
|
||||
try{
|
||||
const response = await api.put(`/raidGroup/${raidGroupId}/raidGroupRequest/${raidGroupRequestId}/resolve`, {resolution: permission});
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/raidGroup/${raidGroupId}/raidGroupRequest/${raidGroupRequestId}/resolve`, {resolution: permission});
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidGroupRequest", raidGroupId] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidGroupRequest", raidGroupId] });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -133,24 +77,10 @@ export function useDeleteRaidGroupRequest(raidGroupId: string, raidGroupRequestI
|
||||
return useMutation({
|
||||
mutationKey: ["raidGroupRequest", raidGroupId, raidGroupRequestId],
|
||||
mutationFn: async () => {
|
||||
try{
|
||||
const response = await api.delete(`/raidGroup/${raidGroupId}/raidGroupRequest/${raidGroupRequestId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.delete(`/raidGroup/${raidGroupId}/raidGroupRequest/${raidGroupRequestId}`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidGroupRequest", raidGroupId] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidGroupRequest", raidGroupId] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,31 +1,17 @@
|
||||
import { Counter } from "@/interface/Counters";
|
||||
import { RaidInstance } from "@/interface/RaidInstance";
|
||||
import { RaidInstancePersonCharacterXref } from "@/interface/RaidInstancePersonCharacterXref";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import api from "@/util/AxiosUtil";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
|
||||
export function useGetRaidInstance(raidInstanceId: string, raidGroupId: string){
|
||||
return useQuery({
|
||||
queryKey: ["raidInstances", raidInstanceId, raidGroupId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidInstance/${raidInstanceId}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidInstance/${raidInstanceId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as RaidInstance;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as RaidInstance;
|
||||
},
|
||||
enabled: !!raidInstanceId && !!raidGroupId
|
||||
});
|
||||
@@ -42,23 +28,9 @@ export function useGetRaidInstancesByRaidGroup(raidGroupId: string, page: number
|
||||
params.append("searchTerm", searchTerm);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidInstance?${params}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidInstance?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as RaidInstance[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as RaidInstance[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -73,23 +45,9 @@ export function useGetRaidInstancesByRaidGroupCount(raidGroupId: string, searchT
|
||||
params.append("searchTerm", searchTerm);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidInstance/count?${params}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidInstance/count?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Counter).count;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -102,26 +60,12 @@ export function useCreateRaidInstance(raidGroupId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["createRaidInstance", raidGroupId],
|
||||
mutationFn: async (raidInstance: RaidInstance) => {
|
||||
try{
|
||||
const response = await api.post(`/raidGroup/${raidGroupId}/raidInstance`, raidInstance);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.raidInstanceId as string;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as RaidInstance).raidInstanceId;
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidInstances"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidInstances"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -133,24 +77,10 @@ export function useUpdateRaidInstance(raidGroupId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["updateRaidInstance", raidGroupId],
|
||||
mutationFn: async (raidInstance: RaidInstance) => {
|
||||
try{
|
||||
const response = await api.put(`/raidGroup/${raidGroupId}/raidInstance/${raidInstance.raidInstanceId}`, raidInstance);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/raidGroup/${raidGroupId}/raidInstance/${raidInstance.raidInstanceId}`, raidInstance);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidInstances"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidInstances"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -159,21 +89,7 @@ export function useUpdateRaidInstanceNoInvalidation(raidGroupId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["updateRaidInstance", raidGroupId],
|
||||
mutationFn: async (raidInstance: RaidInstance) => {
|
||||
try{
|
||||
const response = await api.put(`/raidGroup/${raidGroupId}/raidInstance/${raidInstance.raidInstanceId}`, raidInstance);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.put(`/raidGroup/${raidGroupId}/raidInstance/${raidInstance.raidInstanceId}`, raidInstance);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -185,24 +101,10 @@ export function useDeleteRaidInstance(raidGroupId: string, raidInstanceId: strin
|
||||
return useMutation({
|
||||
mutationKey: ["deleteRaidInstance", raidGroupId, raidInstanceId],
|
||||
mutationFn: async () => {
|
||||
try{
|
||||
const response = await api.delete(`/raidGroup/${raidGroupId}/raidInstance/${raidInstanceId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.delete(`/raidGroup/${raidGroupId}/raidInstance/${raidInstanceId}`);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidInstances"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidInstances"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -212,23 +114,9 @@ export function useGetRaidInstancePersonCharacterXrefs(raidGroupId?: string, rai
|
||||
return useQuery({
|
||||
queryKey: ["raidInstancePersonCharacterXrefs", raidGroupId, raidInstanceId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidInstance/${raidInstanceId}/personCharacterXref`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidInstance/${raidInstanceId}/personCharacterXref`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as RaidInstancePersonCharacterXref[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as RaidInstancePersonCharacterXref[];
|
||||
},
|
||||
enabled: !!raidGroupId && !!raidInstanceId
|
||||
});
|
||||
@@ -241,24 +129,10 @@ export function useUpdateRaidInstancePersonCharacterXrefs(raidGroupId?: string,
|
||||
return useMutation({
|
||||
mutationKey: ["updateRaidInstancePersonCharacterXrefs", raidGroupId, raidInstanceId],
|
||||
mutationFn: async (raidInstancePersonCharacterXrefs: RaidInstancePersonCharacterXref[]) => {
|
||||
try{
|
||||
const response = await api.post(`/raidGroup/${raidGroupId}/raidInstance/${raidInstanceId}/personCharacterXref`, raidInstancePersonCharacterXrefs);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.post(`/raidGroup/${raidGroupId}/raidInstance/${raidInstanceId}/personCharacterXref`, raidInstancePersonCharacterXrefs);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidInstancePersonCharacterXrefs", raidGroupId, raidInstanceId] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidInstancePersonCharacterXrefs", raidGroupId, raidInstanceId] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,30 +1,16 @@
|
||||
import { Counter } from "@/interface/Counters";
|
||||
import { RaidLayout, RaidLayoutClassGroupXref } from "@/interface/RaidLayout";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import api from "@/util/AxiosUtil";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
|
||||
export function useGetRaidLayout(raidGroupId?: string, raidLayoutId?: string){
|
||||
return useQuery({
|
||||
queryKey: ["raidLayout", raidGroupId, raidLayoutId],
|
||||
queryFn: async () => {
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidLayout/${raidLayoutId}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidLayout/${raidLayoutId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as RaidLayout;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as RaidLayout;
|
||||
},
|
||||
enabled: !!raidGroupId && !!raidLayoutId
|
||||
});
|
||||
@@ -41,23 +27,9 @@ export function useGetRaidLayoutsByRaidGroup(raidGroupId: string, page: number,
|
||||
params.append("searchTerm", searchTerm);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidLayout?${params}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidLayout?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data as RaidLayout[];
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return response.data as RaidLayout[];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -71,23 +43,9 @@ export function useGetRaidLayoutsByRaidGroupCount(raidGroupId: string, searchTer
|
||||
params.append("searchTerm", searchTerm);
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidLayout/count?${params}`);
|
||||
const response = await api.get(`/raidGroup/${raidGroupId}/raidLayout/count?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
|
||||
return response.data.count as number;
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return (response.data as Counter).count;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -99,29 +57,15 @@ export function useCreateRaidLayout(raidGroupId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["createRaidLayout", raidGroupId],
|
||||
mutationFn: async ({raidLayout, raidLayoutClassGroupXrefs}:{raidLayout: RaidLayout; raidLayoutClassGroupXrefs: RaidLayoutClassGroupXref[];}) => {
|
||||
try{
|
||||
const response = await api.post(`/raidGroup/${raidGroupId}/raidLayout`,
|
||||
{
|
||||
raidLayout,
|
||||
raidLayoutClassGroupXrefs
|
||||
}
|
||||
);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
await api.post(`/raidGroup/${raidGroupId}/raidLayout`,
|
||||
{
|
||||
raidLayout,
|
||||
raidLayoutClassGroupXrefs
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidLayouts", raidGroupId] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidLayouts", raidGroupId] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -133,30 +77,16 @@ export function useUpdateRaidLayout(raidGroupId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["updateRaidLayout", raidGroupId],
|
||||
mutationFn: async ({raidLayout, raidLayoutClassGroupXrefs}:{raidLayout: RaidLayout; raidLayoutClassGroupXrefs: RaidLayoutClassGroupXref[];}) => {
|
||||
try{
|
||||
const response = await api.put(`/raidGroup/${raidGroupId}/raidLayout/${raidLayout.raidLayoutId}`,
|
||||
{
|
||||
raidLayout,
|
||||
raidLayoutClassGroupXrefs
|
||||
}
|
||||
);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
await api.put(`/raidGroup/${raidGroupId}/raidLayout/${raidLayout.raidLayoutId}`,
|
||||
{
|
||||
raidLayout,
|
||||
raidLayoutClassGroupXrefs
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidLayouts", raidGroupId] });
|
||||
queryClient.invalidateQueries({ queryKey: ["classGroups", "raidLayout"] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidLayouts", raidGroupId] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["classGroups", "raidLayout"] });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -168,24 +98,10 @@ export function useDeleteRaidLayout(raidGroupId: string, raidLayoutId: string){
|
||||
return useMutation({
|
||||
mutationKey: ["deleteRaidLayout", raidGroupId, raidLayoutId],
|
||||
mutationFn: async () => {
|
||||
try{
|
||||
const response = await api.delete(`/raidGroup/${raidGroupId}/raidLayout/${raidLayoutId}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await api.delete(`/raidGroup/${raidGroupId}/raidLayout/${raidLayoutId}`)
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["raidLayouts", raidGroupId] });
|
||||
void queryClient.invalidateQueries({ queryKey: ["raidLayouts", raidGroupId] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user