Skip to content

Commit

Permalink
fixed request missing headers on buid
Browse files Browse the repository at this point in the history
  • Loading branch information
guipeeix7 committed Jan 12, 2025
1 parent 485bdb5 commit 3638496
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 15 deletions.
19 changes: 13 additions & 6 deletions src/Services/Permissions/permissionsService.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { APIUsers } from "../BaseService";
import { getToken } from "../Functions/loader";

// Create a new permission
export const createPermission = async (permissionData) => {
Expand All @@ -9,7 +10,7 @@ export const createPermission = async (permissionData) => {
}
const response = await APIUsers.post("/permission", permissionData, {
headers: {
Authorization: `Bearer ${token}`,
Authorization: `Bearer ${getToken()}`,
},
});
return response.data;
Expand All @@ -27,7 +28,13 @@ export const getAllPermissions = async () => {
if (!token) {
throw new Error("No token found");
}
const response = await APIUsers.get("/permission");
const response = await APIUsers.get("/permission",
{
headers: {
Authorization: `Bearer ${getToken()}`,
}
}
);
return response.data;
} catch (error) {
console.error("Erro ao buscar permissões:", error.response?.data || error);
Expand All @@ -45,7 +52,7 @@ export const getPermissionById = async (id) => {
}
const response = await APIUsers.get(`/permission/${id}`, {
headers: {
Authorization: `Bearer ${token}`,
Authorization: `Bearer ${getToken()}`,
},
});
return response.data;
Expand All @@ -64,7 +71,7 @@ export const updatePermissionById = async (id, permissionData) => {
}
const response = await APIUsers.put(`/permission/${id}`, permissionData, {
headers: {
Authorization: `Bearer ${token}`,
Authorization: `Bearer ${getToken()}`,
},
});
return response.data;
Expand All @@ -83,7 +90,7 @@ export const deletePermissionById = async (id) => {
}
await APIUsers.delete(`/permission/${id}`, {
headers: {
Authorization: `Bearer ${token}`,
Authorization: `Bearer ${getToken()}`,
},
});
} catch (error) {
Expand All @@ -104,7 +111,7 @@ export const searchPermissionByName = async (name) => {
{ name },
{
headers: {
Authorization: `Bearer ${token}`,
Authorization: `Bearer ${getToken()}`,
},
}
);
Expand Down
34 changes: 27 additions & 7 deletions src/Services/RoleService/roleService.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { APIUsers } from "../BaseService";
import { getToken } from "../Functions/loader";

export const createRole = async (roleData) => {
try {
Expand Down Expand Up @@ -27,7 +28,10 @@ export const createRole = async (roleData) => {
moduleName: "users",
action: "create",
},

headers: {
Authorization: `Bearer ${getToken()}`,
},

});
return response.data;
} catch (error) {
Expand All @@ -43,7 +47,9 @@ export const getAllRoles = async () => {
throw new Error("No token found");
}
const response = await APIUsers.get("/role", {

headers: {
Authorization: `Bearer ${getToken()}`,
},
});
return response.data;
} catch (error) {
Expand All @@ -58,7 +64,11 @@ export const getRoleById = async (id) => {
if (!token) {
throw new Error("No token found");
}
const response = await APIUsers.get(`/role/${id}`, );
const response = await APIUsers.get(`/role/${id}`, {
headers: {
Authorization: `Bearer ${getToken()}`,
},
});
return response.data;
} catch (error) {
console.error("Erro ao buscar role:", error);
Expand All @@ -75,10 +85,12 @@ export const assignPermissionsToRole = async (roleId, permissions) => {
const response = await APIUsers.put(`/roles/${roleId}/permissions`, {
permissions,
}, {

headers: {
Authorization: `Bearer ${getToken()}`,
},
});

return response.data;
return response.data;
} catch (error) {
console.error("Erro ao vincular permissões à role:", error);
throw error;
Expand Down Expand Up @@ -111,7 +123,11 @@ export const updateRole = async (id, roleData) => {
moduleName: "users",
action: "update",
},


headers: {
Authorization: `Bearer ${getToken()}`,
},

});
return response.data;
} catch (error) {
Expand Down Expand Up @@ -146,7 +162,11 @@ export const deleteRole = async (id) => {
moduleName: "users",
action: "delete",
},


headers: {
Authorization: `Bearer ${getToken()}`,
},

});
return response.data;
} catch (error) {
Expand Down
30 changes: 28 additions & 2 deletions src/Services/organService.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { APIUsers } from "./BaseService";
import { getToken } from "./Functions/loader";

export async function createOrgan(orgao, lotacao) {
try {
Expand Down Expand Up @@ -26,6 +27,10 @@ export async function createOrgan(orgao, lotacao) {
moduleName: "users",
action: "create",
},
headers: {
Authorization: `Bearer ${getToken()}`,
},

}
);
return response.status;
Expand All @@ -37,7 +42,13 @@ export async function createOrgan(orgao, lotacao) {

export async function listOrgans() {
try {
const response = await APIUsers.get("organ/list");
const response = await APIUsers.get("organ/list",
{
headers: {
Authorization: `Bearer ${getToken()}`,
},
}
);
return response.data;
} catch (error) {
return error.response.data.error;
Expand Down Expand Up @@ -68,6 +79,10 @@ export async function updateOrgan(id, updatedData) {
moduleName: "users",
action: "update",
},
headers: {
Authorization: `Bearer ${getToken()}`,
},

}
);
return response.status;
Expand All @@ -81,7 +96,13 @@ export async function updateOrgan(id, updatedData) {

export async function getOrganById(id) {
try {
const response = await APIUsers.get(`organ/get/${id}`);
const response = await APIUsers.get(`organ/get/${id}`,
{
headers: {
Authorization: `Bearer ${getToken()}`,
},
}
);
return response.data;
} catch (error) {
return error.response.data.error;
Expand Down Expand Up @@ -110,6 +131,11 @@ export async function deleteOrganById(id) {
moduleName: "users",
action: "delete",
},

headers: {
Authorization: `Bearer ${getToken()}`,
},

});
return response.status;
} catch (error) {
Expand Down

0 comments on commit 3638496

Please sign in to comment.