refactor: usersControl

This commit is contained in:
Takeshi Kimata
2024-07-18 10:39:07 +09:00
parent 7e05eda259
commit aab9f91156
8 changed files with 118 additions and 115 deletions

View File

@@ -0,0 +1,50 @@
import Config from '@/config/config';
const apiServer = Config.apiServer;
async function findUser(jwt: string, userId: number) {
const fetchOptions = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${jwt}`,
},
};
const url = `${apiServer}/users/find/${userId}`;
try {
const response = await fetch(url, fetchOptions);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error: any) {
console.error('Error fetching data:', error.message);
}
}
async function searchUsers(jwt: string, projectId: number, searchText: string) {
const fetchOptions = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${jwt}`,
},
};
const url = `${apiServer}/users/search?projectId=${projectId}&search=${searchText}`;
try {
const response = await fetch(url, fetchOptions);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error: any) {
console.error('Error fetching data:', error.message);
}
}
export { findUser, searchUsers };