forked from BLC/sgeUpdated
Add 'sge-frontend/' from commit '5fa787e054b25ac53edc7ff0275ea7960a709401'
git-subtree-dir: sge-frontend git-subtree-mainline:876c278ac4git-subtree-split:5fa787e054
This commit is contained in:
42
sge-frontend/src/redux/actions/accessToken/index.js
Normal file
42
sge-frontend/src/redux/actions/accessToken/index.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import jwtDecode from "jwt-decode";
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
const refreshToken = localStorage.getItem("refreshToken");
|
||||
|
||||
export const newAccessToken = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
refreshToken(input: { refreshToken: "` +
|
||||
refreshToken +
|
||||
`" }) {
|
||||
accessToken
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const newAccessToken = response.data.data.refreshToken.accessToken;
|
||||
const decodenewAccessToken = jwtDecode(newAccessToken);
|
||||
localStorage.setItem("accessToken", newAccessToken);
|
||||
localStorage.setItem("accessTokenExp", decodenewAccessToken.exp);
|
||||
dispatch({
|
||||
type: "GET_NEWACCESSTOKEN",
|
||||
payload: {
|
||||
newAccessToken,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
208
sge-frontend/src/redux/actions/answer/index.js
Normal file
208
sge-frontend/src/redux/actions/answer/index.js
Normal file
@@ -0,0 +1,208 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getAnswers = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
answers {
|
||||
id
|
||||
value
|
||||
answer
|
||||
isDefault
|
||||
isDeleted
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const answers1 = response.data.data.answers;
|
||||
const answers = answers1.filter((answer) => answer.isDeleted != true);
|
||||
dispatch({
|
||||
type: "GET_ANSWERS",
|
||||
payload: {
|
||||
answers,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getAnswersWithPaginate = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
paginateAnswers(
|
||||
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
} }
|
||||
criteria:{deleted:false}
|
||||
sortBy: [{ direction: ASC, field: "value" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
numberOfElements
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
content {
|
||||
id
|
||||
value
|
||||
answer
|
||||
isDefault
|
||||
isDeleted
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const answersWithPaginate = response?.data?.data?.paginateAnswers;
|
||||
dispatch({
|
||||
type: "GET_ANSWERS_WITH_PAGINATE",
|
||||
payload: {
|
||||
answersWithPaginate,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const addAnswer = (data) => {
|
||||
const dataToJSON = JSON.stringify(data);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
addAnswer(
|
||||
input: ${deleteQuotesFromKey} )
|
||||
{
|
||||
id
|
||||
value
|
||||
answer
|
||||
isDefault
|
||||
isDeleted
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "ADD_ANSWER",
|
||||
payload: {
|
||||
answers: response.data.data.addAnswer,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const updateAnswer = (data) => {
|
||||
let deleteIdFromData = { ...data };
|
||||
delete deleteIdFromData.id;
|
||||
const dataToJSON = JSON.stringify(deleteIdFromData);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
updateAnswer(id: "` +
|
||||
data.id +
|
||||
`", input: ${deleteQuotesFromKey}) {
|
||||
id
|
||||
value
|
||||
answer
|
||||
isDeleted
|
||||
isDefault
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "UPDATE_ANSWER",
|
||||
payload: {
|
||||
answers: response.data.data.updateAnswer,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const deleteAnswer = (id) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `mutation {
|
||||
deleteAnswer(id:"${id}")
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
dispatch({
|
||||
type: "DELETE_ANSWER",
|
||||
payload: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
553
sge-frontend/src/redux/actions/areas/index.js
Normal file
553
sge-frontend/src/redux/actions/areas/index.js
Normal file
@@ -0,0 +1,553 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getAreas = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
areas {
|
||||
id
|
||||
tag
|
||||
isDeleted
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const areas1 = response?.data?.data?.areas;
|
||||
const areas = areas1?.filter((area) => area.isDeleted != true) || [];
|
||||
dispatch({
|
||||
type: "GET_AREAS",
|
||||
payload: {
|
||||
areas,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching areas:", error);
|
||||
dispatch({
|
||||
type: "GET_AREAS",
|
||||
payload: {
|
||||
areas: [],
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getAreasWithPaginate = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
paginateAreas(
|
||||
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
} }
|
||||
criteria: { deleted:false }
|
||||
sortBy: [{ direction: ASC, field: "tag" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
numberOfElements
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
content {
|
||||
id
|
||||
tag
|
||||
countries
|
||||
{
|
||||
id
|
||||
countryCode
|
||||
name
|
||||
}
|
||||
cities{
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
districts{
|
||||
id
|
||||
name
|
||||
city{
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
neighborhoods{
|
||||
id
|
||||
name
|
||||
district{
|
||||
id
|
||||
name
|
||||
city{
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
isDeleted
|
||||
defaultArea
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const areasWithPaginate = response?.data?.data?.paginateAreas;
|
||||
dispatch({
|
||||
type: "GET_AREAS_WITH_PAGINATE",
|
||||
payload: {
|
||||
areasWithPaginate,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getAreasWithCriteria = (organizationId) => {
|
||||
return async (dispatch) => {
|
||||
// Don't make the request if organizationId is undefined, null, or empty
|
||||
if (!organizationId || organizationId === "undefined") {
|
||||
dispatch({
|
||||
type: "GET_AREAS_WITH_CRITERIA",
|
||||
payload: {
|
||||
getAreasWithCriteria: [],
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
areas(
|
||||
criteria: { organizations:"${organizationId}" }
|
||||
) {
|
||||
id
|
||||
tag
|
||||
countries {
|
||||
id
|
||||
countryCode
|
||||
name
|
||||
}
|
||||
cities {
|
||||
id
|
||||
name
|
||||
coordinates
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
districts {
|
||||
id
|
||||
name
|
||||
coordinates
|
||||
city{
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
neighborhoods {
|
||||
id
|
||||
name
|
||||
minLong
|
||||
maxLong
|
||||
minLat
|
||||
maxLat
|
||||
district{
|
||||
id
|
||||
name
|
||||
city{
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
isDeleted
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const areas1 = response?.data?.data?.areas;
|
||||
const getAreasWithCriteria = areas1?.filter(
|
||||
(area) => area.isDeleted != true
|
||||
) || [];
|
||||
dispatch({
|
||||
type: "GET_AREAS_WITH_CRITERIA",
|
||||
payload: {
|
||||
getAreasWithCriteria,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching areas with criteria:", error);
|
||||
dispatch({
|
||||
type: "GET_AREAS_WITH_CRITERIA",
|
||||
payload: {
|
||||
getAreasWithCriteria: [],
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getAreasByDataCenter = (dataCenterId) => {
|
||||
return async (dispatch) => {
|
||||
// Don't make the request if dataCenterId is undefined, null, or empty
|
||||
if (!dataCenterId || dataCenterId === "undefined") {
|
||||
dispatch({
|
||||
type: "GET_AREAS_WITH_CRITERIA",
|
||||
payload: {
|
||||
getAreasWithCriteria: [],
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
dataCenter(id: "${dataCenterId}") {
|
||||
id
|
||||
dataCenter
|
||||
area {
|
||||
id
|
||||
tag
|
||||
countries {
|
||||
id
|
||||
countryCode
|
||||
name
|
||||
}
|
||||
cities {
|
||||
id
|
||||
name
|
||||
coordinates
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
districts {
|
||||
id
|
||||
name
|
||||
coordinates
|
||||
city{
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
neighborhoods {
|
||||
id
|
||||
name
|
||||
minLong
|
||||
maxLong
|
||||
minLat
|
||||
maxLat
|
||||
district{
|
||||
id
|
||||
name
|
||||
city{
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
isDeleted
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const dataCenter = response?.data?.data?.dataCenter;
|
||||
let areas = [];
|
||||
|
||||
if (dataCenter && dataCenter.area && !dataCenter.area.isDeleted) {
|
||||
areas = [dataCenter.area];
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: "GET_AREAS_WITH_CRITERIA",
|
||||
payload: {
|
||||
getAreasWithCriteria: areas,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching areas by data center:", error);
|
||||
dispatch({
|
||||
type: "GET_AREAS_WITH_CRITERIA",
|
||||
payload: {
|
||||
getAreasWithCriteria: [],
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const addArea = (data) => {
|
||||
const dataToJSON = JSON.stringify(data);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
createArea(
|
||||
input: ${deleteQuotesFromKey} )
|
||||
{
|
||||
id
|
||||
tag
|
||||
countries {
|
||||
id
|
||||
countryCode
|
||||
name
|
||||
}
|
||||
cities {
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
districts {
|
||||
id
|
||||
name
|
||||
city{
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
neighborhoods {
|
||||
id
|
||||
name
|
||||
district{
|
||||
id
|
||||
name
|
||||
city{
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
isDeleted
|
||||
defaultArea
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "ADD_AREA",
|
||||
payload: {
|
||||
areas: response.data.data.createArea,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const updateArea = (data) => {
|
||||
let deleteIdFromData = { ...data };
|
||||
delete deleteIdFromData.id;
|
||||
const dataToJSON = JSON.stringify(deleteIdFromData);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
updateArea(id: "` +
|
||||
data.id +
|
||||
`", input: ${deleteQuotesFromKey}) {
|
||||
id
|
||||
tag
|
||||
countries {
|
||||
id
|
||||
countryCode
|
||||
name
|
||||
}
|
||||
cities {
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
districts {
|
||||
id
|
||||
name
|
||||
city{
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
neighborhoods {
|
||||
id
|
||||
name
|
||||
district{
|
||||
id
|
||||
name
|
||||
city{
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
isDeleted
|
||||
defaultArea
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "UPDATE_AREA",
|
||||
payload: {
|
||||
areas: response.data.data.updateArea,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const deleteArea = (id) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `mutation {
|
||||
deleteArea(id:"${id}")
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
dispatch({
|
||||
type: "DELETE_AREA",
|
||||
payload: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
117
sge-frontend/src/redux/actions/auth/index.js
Normal file
117
sge-frontend/src/redux/actions/auth/index.js
Normal file
@@ -0,0 +1,117 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
import jwtDecode from "jwt-decode";
|
||||
|
||||
export const handleLogin = (email, password) => async (dispatch) => {
|
||||
try {
|
||||
const res = await ApplicationService.httpWithoutAuthorization().post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
login(input: { email: "` +
|
||||
email +
|
||||
`", password: "` +
|
||||
password +
|
||||
`" }) {
|
||||
accessToken
|
||||
email
|
||||
user {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
email
|
||||
role{
|
||||
id
|
||||
tag
|
||||
permissions{
|
||||
tag
|
||||
}
|
||||
}
|
||||
organizations{
|
||||
id
|
||||
tag
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
}
|
||||
);
|
||||
const data = res.data;
|
||||
dispatch({
|
||||
type: "LOGIN",
|
||||
payload: res.data.data,
|
||||
});
|
||||
|
||||
localStorage.setItem("accessToken", data.data.login.accessToken);
|
||||
// localStorage.setItem("refreshToken", res.data.data.login.refreshToken);
|
||||
localStorage.setItem("userId", res.data.data.login.user.id);
|
||||
localStorage.setItem("roleId", res.data.data.login.user.role.id);
|
||||
localStorage.setItem("roleTag", res.data.data.login.user.role.tag);
|
||||
localStorage.setItem(
|
||||
"organizationId",
|
||||
res.data.data.login.user.organizations?.[0]?.id
|
||||
);
|
||||
localStorage.setItem(
|
||||
"organizationName",
|
||||
res.data.data.login.user.organizations?.[0]?.tag
|
||||
);
|
||||
localStorage.setItem(
|
||||
"currentUser",
|
||||
data.data.login.user.firstName + " " + data.data.login.user.lastName
|
||||
);
|
||||
localStorage.setItem(
|
||||
"permissions",
|
||||
JSON.stringify(data.data.login.user.role.permissions)
|
||||
);
|
||||
|
||||
const token = jwtDecode(data.data.login.accessToken);
|
||||
localStorage.setItem("accessTokenExp", token.exp);
|
||||
|
||||
return data.data.login;
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
if (error.message !== "Bu hesap için yetkiniz yok.") {
|
||||
error.message = "Kullanıcı bilgileri hatalıdır. Lütfen tekrar deneyiniz.";
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// export const handleLogout = () => {
|
||||
// return (dispatch) => {
|
||||
// dispatch({
|
||||
// type: "LOGOUT",
|
||||
// });
|
||||
// localStorage.clear();
|
||||
// };
|
||||
// };
|
||||
|
||||
export const handleLogout = () => async (dispatch) => {
|
||||
try {
|
||||
// const res = await ApplicationService.httpWithoutAuthorization().post(
|
||||
// "/graphql",
|
||||
// {
|
||||
// query: `
|
||||
// mutation {
|
||||
// logout(input:{refreshToken:"${localStorage.getItem("refreshToken")}"})
|
||||
// }
|
||||
// `,
|
||||
// },
|
||||
// {
|
||||
// headers: {
|
||||
// Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
// },
|
||||
// }
|
||||
// );
|
||||
dispatch({
|
||||
type: "LOGOUT",
|
||||
});
|
||||
localStorage.clear();
|
||||
window.location.reload();
|
||||
} catch (error) {
|
||||
console.log("error: ", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
126
sge-frontend/src/redux/actions/cities/index.js
Normal file
126
sge-frontend/src/redux/actions/cities/index.js
Normal file
@@ -0,0 +1,126 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getCities = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
cities (sortBy: [{ direction: ASC, field: "name" }]) {
|
||||
id
|
||||
name
|
||||
country {
|
||||
id
|
||||
countryCode
|
||||
name
|
||||
}
|
||||
coordinates
|
||||
isDeleted
|
||||
defaultCity
|
||||
mainDataTables {
|
||||
id
|
||||
year
|
||||
totalEmission
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const cities = response.data.data.cities;
|
||||
dispatch({
|
||||
type: "GET_CITIES",
|
||||
payload: {
|
||||
cities,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const paginateCities = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
paginateCities(
|
||||
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
} }
|
||||
sortBy: [{ direction: ASC, field: "name" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
}
|
||||
content {
|
||||
id
|
||||
name
|
||||
country{
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const paginateCities = response.data.data.paginateCities;
|
||||
dispatch({
|
||||
type: "PAGINATE_CITIES",
|
||||
payload: {
|
||||
paginateCities,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getCitiesWithoutCoords = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
cities (sortBy: [{ direction: ASC, field: "name" }]) {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const cities = response.data.data.cities;
|
||||
dispatch({
|
||||
type: "GET_CITIES_WITHOUT_COORDS",
|
||||
payload: {
|
||||
cities,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
54
sge-frontend/src/redux/actions/city/index.js
Normal file
54
sge-frontend/src/redux/actions/city/index.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getCity = (cityId) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
city(id: "${cityId}") {
|
||||
id
|
||||
name
|
||||
coordinates
|
||||
isDeleted
|
||||
defaultCity
|
||||
districts {
|
||||
id
|
||||
name
|
||||
coordinates
|
||||
city{
|
||||
id
|
||||
name
|
||||
}
|
||||
mainDataTables {
|
||||
id
|
||||
year
|
||||
totalEmission
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const city = response.data.data.city;
|
||||
dispatch({
|
||||
type: "GET_CITY",
|
||||
payload: {
|
||||
city,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
37
sge-frontend/src/redux/actions/country/index.js
Normal file
37
sge-frontend/src/redux/actions/country/index.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getCountries = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
countries {
|
||||
id
|
||||
countryCode
|
||||
name
|
||||
isDeleted
|
||||
defaultCountry
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const countries = response.data.data.countries;
|
||||
dispatch({
|
||||
type: "GET_COUNTRIES",
|
||||
payload: {
|
||||
countries,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
424
sge-frontend/src/redux/actions/dataCenter/index.js
Normal file
424
sge-frontend/src/redux/actions/dataCenter/index.js
Normal file
@@ -0,0 +1,424 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getDataCenters = () => {
|
||||
return async (dispatch) => {
|
||||
dispatch({
|
||||
type: "GET_DATA_CENTERS_LOADING",
|
||||
});
|
||||
|
||||
// Get access token
|
||||
const accessToken = localStorage.getItem("accessToken");
|
||||
if (!accessToken) {
|
||||
dispatch({
|
||||
type: "GET_DATA_CENTERS_ERROR",
|
||||
payload: {
|
||||
error: "No access token found. Please log in again.",
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
query GetDataCenters {
|
||||
dataCenters(sortBy: [{ direction: DESC, field: "number" }]) {
|
||||
id
|
||||
dataCenter
|
||||
externalId
|
||||
ayposURL
|
||||
number
|
||||
address
|
||||
latitude
|
||||
longitude
|
||||
area {
|
||||
tag
|
||||
cityNames
|
||||
districtNames
|
||||
}
|
||||
projects {
|
||||
id
|
||||
name
|
||||
physicalMachines {
|
||||
id
|
||||
name
|
||||
vms {
|
||||
active {
|
||||
id
|
||||
status
|
||||
name
|
||||
power
|
||||
config {
|
||||
id
|
||||
cpu
|
||||
ram
|
||||
disk
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + accessToken,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
// Debug logging
|
||||
console.log("GraphQL Response:", {
|
||||
status: response.status,
|
||||
data: response.data,
|
||||
errors: response.data?.errors
|
||||
});
|
||||
|
||||
// Check for GraphQL errors
|
||||
if (response.data?.errors) {
|
||||
throw new Error(response.data.errors[0].message);
|
||||
}
|
||||
|
||||
// Validate response structure
|
||||
if (!response.data?.data?.dataCenters) {
|
||||
throw new Error("Invalid response structure: dataCenters not found");
|
||||
}
|
||||
|
||||
const dataCenters = response.data.data.dataCenters;
|
||||
|
||||
// Validate dataCenters is an array
|
||||
if (!Array.isArray(dataCenters)) {
|
||||
throw new Error("Invalid response: dataCenters is not an array");
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: "GET_DATA_CENTERS_SUCCESS",
|
||||
payload: {
|
||||
dataCenters,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
// Enhanced error logging
|
||||
console.error("Error fetching data centers:", {
|
||||
message: error.message,
|
||||
response: error.response?.data,
|
||||
status: error.response?.status,
|
||||
stack: error.stack
|
||||
});
|
||||
|
||||
// Check for specific error types
|
||||
let errorMessage = "Failed to fetch data centers";
|
||||
if (error.response?.status === 401) {
|
||||
errorMessage = "Unauthorized. Please log in again.";
|
||||
} else if (error.response?.status === 403) {
|
||||
errorMessage = "You don't have permission to view data centers.";
|
||||
} else if (error.message) {
|
||||
errorMessage = error.message;
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: "GET_DATA_CENTERS_ERROR",
|
||||
payload: {
|
||||
error: errorMessage,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const createDataCenter = (dataCenterData) => {
|
||||
return async (dispatch) => {
|
||||
dispatch({
|
||||
type: "CREATE_DATA_CENTER_LOADING",
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation CreateDataCenter($input: DataCenterInput!) {
|
||||
createDataCenter(input: $input) {
|
||||
id
|
||||
dataCenter
|
||||
externalId
|
||||
ayposURL
|
||||
number
|
||||
address
|
||||
latitude
|
||||
longitude
|
||||
area {
|
||||
tag
|
||||
cityNames
|
||||
districtNames
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
input: {
|
||||
dataCenter: dataCenterData.name,
|
||||
externalId: parseInt(dataCenterData.externalId),
|
||||
ayposURL: dataCenterData.ayposURL || "",
|
||||
number: parseInt(dataCenterData.number) || 1,
|
||||
areaId: dataCenterData.areaId,
|
||||
address: dataCenterData.address || "",
|
||||
latitude: dataCenterData.latitude ? parseFloat(dataCenterData.latitude) : null,
|
||||
longitude: dataCenterData.longitude ? parseFloat(dataCenterData.longitude) : null,
|
||||
city: dataCenterData.city
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
// Debug logging
|
||||
console.log("Create Response:", {
|
||||
status: response.status,
|
||||
data: response.data,
|
||||
errors: response.data?.errors
|
||||
});
|
||||
|
||||
if (response.data?.errors) {
|
||||
throw new Error(response.data.errors[0].message);
|
||||
}
|
||||
|
||||
if (!response.data?.data?.createDataCenter) {
|
||||
throw new Error("Invalid response: createDataCenter data not found");
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: "CREATE_DATA_CENTER_SUCCESS",
|
||||
payload: response.data.data.createDataCenter,
|
||||
});
|
||||
|
||||
return response.data.data.createDataCenter;
|
||||
} catch (error) {
|
||||
console.error("Error creating data center:", error);
|
||||
dispatch({
|
||||
type: "CREATE_DATA_CENTER_ERROR",
|
||||
payload: {
|
||||
error: error.message || "Failed to create data center",
|
||||
},
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const updateDataCenter = (id, dataCenterData) => {
|
||||
return async (dispatch) => {
|
||||
dispatch({
|
||||
type: "UPDATE_DATA_CENTER_LOADING",
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation UpdateDataCenter($id: ID!, $input: DataCenterInput!) {
|
||||
updateDataCenter(id: $id, input: $input) {
|
||||
id
|
||||
dataCenter
|
||||
externalId
|
||||
ayposURL
|
||||
number
|
||||
address
|
||||
latitude
|
||||
longitude
|
||||
area {
|
||||
tag
|
||||
cityNames
|
||||
districtNames
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
id: id,
|
||||
input: {
|
||||
dataCenter: dataCenterData.name,
|
||||
externalId: parseInt(dataCenterData.externalId),
|
||||
ayposURL: dataCenterData.ayposURL || "",
|
||||
number: parseInt(dataCenterData.number) || 1,
|
||||
areaId: dataCenterData.areaId,
|
||||
address: dataCenterData.address || "",
|
||||
latitude: dataCenterData.latitude ? parseFloat(dataCenterData.latitude) : null,
|
||||
longitude: dataCenterData.longitude ? parseFloat(dataCenterData.longitude) : null,
|
||||
city: dataCenterData.city
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data?.errors) {
|
||||
throw new Error(response.data.errors[0].message);
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: "UPDATE_DATA_CENTER_SUCCESS",
|
||||
payload: response.data.data.updateDataCenter
|
||||
});
|
||||
|
||||
return response.data.data.updateDataCenter;
|
||||
} catch (error) {
|
||||
console.error("Error updating data center:", error);
|
||||
dispatch({
|
||||
type: "UPDATE_DATA_CENTER_ERROR",
|
||||
payload: {
|
||||
error: error.message || "Failed to update data center",
|
||||
},
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const deleteDataCenter = (id) => {
|
||||
return async (dispatch) => {
|
||||
dispatch({
|
||||
type: "DELETE_DATA_CENTER_LOADING",
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation DeleteDataCenter($id: ID!) {
|
||||
deleteDataCenter(id: $id)
|
||||
}
|
||||
`,
|
||||
variables: {
|
||||
id: id
|
||||
}
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data?.errors) {
|
||||
throw new Error(response.data.errors[0].message);
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: "DELETE_DATA_CENTER_SUCCESS",
|
||||
payload: id
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("Error deleting data center:", error);
|
||||
dispatch({
|
||||
type: "DELETE_DATA_CENTER_ERROR",
|
||||
payload: {
|
||||
error: error.message || "Failed to delete data center",
|
||||
},
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const getDataCenterVMs = (dataCenterId) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// Don't make the request if dataCenterId is undefined, null, or empty
|
||||
if (!dataCenterId || dataCenterId === "undefined") {
|
||||
console.log('getDataCenterVMs: No dataCenterId provided');
|
||||
resolve([]);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log('getDataCenterVMs: Fetching VMs for data center:', dataCenterId);
|
||||
const response = await ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
dataCenter(id: "${dataCenterId}") {
|
||||
id
|
||||
dataCenter
|
||||
projects {
|
||||
id
|
||||
name
|
||||
physicalMachines {
|
||||
id
|
||||
name
|
||||
vms {
|
||||
active {
|
||||
id
|
||||
name
|
||||
status
|
||||
power
|
||||
}
|
||||
inactive {
|
||||
id
|
||||
name
|
||||
status
|
||||
power
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const dataCenter = response?.data?.data?.dataCenter;
|
||||
console.log('getDataCenterVMs: Data center response:', dataCenter);
|
||||
|
||||
let allVMs = [];
|
||||
|
||||
if (dataCenter && dataCenter.projects) {
|
||||
dataCenter.projects.forEach(project => {
|
||||
if (project.physicalMachines) {
|
||||
project.physicalMachines.forEach(pm => {
|
||||
if (pm.vms) {
|
||||
if (pm.vms.active) {
|
||||
allVMs = allVMs.concat(pm.vms.active);
|
||||
}
|
||||
if (pm.vms.inactive) {
|
||||
allVMs = allVMs.concat(pm.vms.inactive);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log('getDataCenterVMs: Found VMs:', allVMs);
|
||||
resolve(allVMs);
|
||||
} catch (error) {
|
||||
console.error("Error fetching VMs by data center:", error);
|
||||
resolve([]);
|
||||
}
|
||||
});
|
||||
};
|
||||
338
sge-frontend/src/redux/actions/datas/index.js
Normal file
338
sge-frontend/src/redux/actions/datas/index.js
Normal file
@@ -0,0 +1,338 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getSectors = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
sectors {
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
sectorNo
|
||||
subSectors {
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
subSectorNo
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const sectors = response.data.data.sectors;
|
||||
dispatch({
|
||||
type: "GET_SECTORS",
|
||||
payload: {
|
||||
sectors,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getSectorById = (id) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
sector(id: "${id}") {
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
sectorNo
|
||||
subSectors {
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
subSectorNo
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const sector = response.data.data.sector;
|
||||
dispatch({
|
||||
type: "GET_SECTOR_BY_ID",
|
||||
payload: {
|
||||
sector,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getSubSectors = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
subSectors{
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
sector {
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
sectorNo
|
||||
}
|
||||
subSectorNo
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const subSectors = response.data.data.subSectors;
|
||||
dispatch({
|
||||
type: "GET_SUBSECTORS",
|
||||
payload: {
|
||||
subSectors,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getSubSectorById = (id) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
subSector(id: "${id}"){
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
activitySubUnits {
|
||||
id
|
||||
tag
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const subSector = response.data.data.subSector;
|
||||
dispatch({
|
||||
type: "GET_SUBSECTOR_BY_ID",
|
||||
payload: {
|
||||
subSector: subSector || {},
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getActivitySubUnits = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
activitySubUnits{
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
subSector {
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
sector{
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
subSectorNo
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const activitySubUnits = response.data.data.activitySubUnits;
|
||||
dispatch({
|
||||
type: "GET_ACTIVITY_SUBUNITS",
|
||||
payload: {
|
||||
activitySubUnits,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getConsuptionUnits = ({ id, sector }) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
sector != "Atık"
|
||||
? `
|
||||
{
|
||||
emissionSource(id: "${id}") {
|
||||
emissionSourceConvertUnits {
|
||||
unit {
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
: `
|
||||
{
|
||||
consuptionUnits {
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const consuptionUnits =
|
||||
sector != "Atık"
|
||||
? response.data.data.emissionSource?.emissionSourceConvertUnits
|
||||
: response.data.data.consuptionUnits;
|
||||
dispatch({
|
||||
type: "GET_CONSUPTION_UNITS",
|
||||
payload: {
|
||||
consuptionUnits,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getGpcReferences = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
gpcReferences {
|
||||
id
|
||||
referenceNumber
|
||||
description
|
||||
deleted
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const gpcReferences = response.data.data.gpcReferences;
|
||||
dispatch({
|
||||
type: "GET_GPC_REFERENCES",
|
||||
payload: {
|
||||
gpcReferences,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getMcfTypes = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
mcfTypes {
|
||||
id
|
||||
typeName
|
||||
value
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const mcfTypes = response.data.data.mcfTypes;
|
||||
dispatch({
|
||||
type: "GET_MCF_TYPES",
|
||||
payload: {
|
||||
mcfTypes,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
62
sge-frontend/src/redux/actions/district/index.js
Normal file
62
sge-frontend/src/redux/actions/district/index.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getDistrict = (districtId) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
district(id: "${districtId}") {
|
||||
id
|
||||
name
|
||||
coordinates
|
||||
isDeleted
|
||||
defaultDistrict
|
||||
neighborhoods {
|
||||
id
|
||||
name
|
||||
minLong
|
||||
maxLong
|
||||
minLat
|
||||
maxLat
|
||||
mainDataTables {
|
||||
id
|
||||
year
|
||||
totalEmission
|
||||
}
|
||||
district{
|
||||
id
|
||||
name
|
||||
city{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
city{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const district = response.data.data.district;
|
||||
dispatch({
|
||||
type: "GET_DISTRICT",
|
||||
payload: {
|
||||
district,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
55
sge-frontend/src/redux/actions/districts/index.js
Normal file
55
sge-frontend/src/redux/actions/districts/index.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
export const getDistricts = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
paginateDistricts(
|
||||
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
} }
|
||||
sortBy: [{ direction: ASC, field: "cityName" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
numberOfElements
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
content {
|
||||
id
|
||||
name
|
||||
city{
|
||||
id
|
||||
name
|
||||
country{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const districts = response.data.data.paginateDistricts;
|
||||
dispatch({
|
||||
type: "GET_DISTRICTS",
|
||||
payload: {
|
||||
districts,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
393
sge-frontend/src/redux/actions/emissionSources/index.js
Normal file
393
sge-frontend/src/redux/actions/emissionSources/index.js
Normal file
@@ -0,0 +1,393 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getAllEmissionSources = (subSectorId) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
emissionSources(criteria: {subSector:"${subSectorId}"}) {
|
||||
id
|
||||
tag
|
||||
convertUnitCheck
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const emissionSources = response.data.data.emissionSources?.filter(
|
||||
(emissionSource) => emissionSource?.deleted != true
|
||||
);
|
||||
dispatch({
|
||||
type: "GET_EMISSION_SOURCES",
|
||||
payload: {
|
||||
emissionSources,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getEmissionSourcesWithPaginate = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
paginateEmissionSources(
|
||||
pagination: {page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
} }
|
||||
criteria: {deleted: ${data.showDeletedEmissionSource}, sector:"${
|
||||
data?.selectedSectorFilter
|
||||
}"}
|
||||
sortBy: [{ direction: ASC, field: "tag" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
numberOfElements
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
content {
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDeleted
|
||||
co2
|
||||
ch4
|
||||
n2o
|
||||
emissionScope
|
||||
subSector{
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
subSectorNo
|
||||
sector{
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
}
|
||||
emissionSourceConvertUnits {
|
||||
value
|
||||
unit{
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
}
|
||||
wasteEmissionSourceSupplement {
|
||||
dryWeightCH4
|
||||
wetWeightCH4
|
||||
dryWeightN2O
|
||||
wetWeightN2O
|
||||
dampWeightCH4
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const emissionSourcesWithPaginate =
|
||||
response.data.data.paginateEmissionSources;
|
||||
dispatch({
|
||||
type: "GET_EMISSION_SOURCES_WITH_PAGINATE",
|
||||
payload: {
|
||||
emissionSourcesWithPaginate,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const addEmissionSource = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
createEmissionSource(
|
||||
input: {
|
||||
tag: "${data.tag}"
|
||||
description: "${data.description}"
|
||||
isDeleted: true
|
||||
co2: "${data.co2}"
|
||||
ch4: "${data.ch4}"
|
||||
n2o: "${data.n2o}"
|
||||
subSector: "${data.subSector}"
|
||||
emissionScope:"${data.emissionScope}"
|
||||
emissionSourceConvertUnitInputs: ${data.emissionSourceConvertUnits}
|
||||
}
|
||||
) {
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDeleted
|
||||
co2
|
||||
ch4
|
||||
n2o
|
||||
emissionScope
|
||||
subSector{
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
sector{
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
subSectorNo
|
||||
}
|
||||
emissionSourceConvertUnits {
|
||||
value
|
||||
unit{
|
||||
id
|
||||
tag
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "ADD_EMISSION_SOURCE",
|
||||
payload: {
|
||||
emissionSource: response.data.data.createEmissionSource,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const updateEmissionSource = (data) => async (dispatch) => {
|
||||
try {
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
updateEmissionSource(id: "${data.id}",
|
||||
input: {
|
||||
tag: "${data.tag}"
|
||||
description: "${data.description}"
|
||||
isDeleted: true
|
||||
co2: "${data.co2}"
|
||||
ch4: "${data.ch4}"
|
||||
n2o: "${data.n2o}"
|
||||
subSector: "${data.subSector}"
|
||||
emissionScope:"${data.emissionScope}"
|
||||
emissionSourceConvertUnitInputs: ${data.emissionSourceConvertUnits}
|
||||
}
|
||||
) {
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDeleted
|
||||
co2
|
||||
ch4
|
||||
n2o
|
||||
emissionScope
|
||||
subSector{
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
sector{
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
subSectorNo
|
||||
}
|
||||
emissionSourceConvertUnits {
|
||||
value
|
||||
unit{
|
||||
id
|
||||
tag
|
||||
}
|
||||
}
|
||||
wasteEmissionSourceSupplement {
|
||||
dryWeightCH4
|
||||
wetWeightCH4
|
||||
dryWeightN2O
|
||||
wetWeightN2O
|
||||
dampWeightCH4
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data.errors) {
|
||||
const errorMessage = response.data.errors[0].extensions.ErrorCode;
|
||||
throw errorMessage;
|
||||
} else {
|
||||
dispatch({
|
||||
type: "UPDATE_EMISSION_SOURCE",
|
||||
payload: {
|
||||
emissionSource: response.data.data.updateEmissionSource,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Network error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const updateEmissionSourceOfWaste = (data) => async (dispatch) => {
|
||||
try {
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
updateEmissionSource(id: "${data.id}",
|
||||
input: {
|
||||
tag: "${data.tag}"
|
||||
subSector: "${data.subSector}"
|
||||
dampWeightCh4: "${data.dampWeightCH4}"
|
||||
dryWeightCh4: "${data.dryWeightCH4}"
|
||||
dryWeightN2o: "${data.dryWeightN2O}"
|
||||
wetWeightCh4: "${data.wetWeightCH4}"
|
||||
wetWeightN2o: "${data.wetWeightN2O}"
|
||||
}
|
||||
) {
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDeleted
|
||||
co2
|
||||
ch4
|
||||
n2o
|
||||
emissionScope
|
||||
subSector{
|
||||
id
|
||||
tag
|
||||
description
|
||||
deleted
|
||||
sector{
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
subSectorNo
|
||||
}
|
||||
emissionSourceConvertUnits {
|
||||
value
|
||||
unit{
|
||||
id
|
||||
tag
|
||||
}
|
||||
}
|
||||
wasteEmissionSourceSupplement {
|
||||
dryWeightCH4
|
||||
wetWeightCH4
|
||||
dryWeightN2O
|
||||
wetWeightN2O
|
||||
dampWeightCH4
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data.errors) {
|
||||
const errorMessage = response.data.errors[0].extensions.ErrorCode;
|
||||
throw errorMessage;
|
||||
} else {
|
||||
dispatch({
|
||||
type: "UPDATE_EMISSION_SOURCE_OF_WASTE",
|
||||
payload: {
|
||||
emissionSource: response.data.data.updateEmissionSource,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Network error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteEmissionSource = (id) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
deleteEmissionSource(id: "${id}")
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
dispatch({
|
||||
type: "DELETE_EMISSION_SOURCE",
|
||||
payload: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
11
sge-frontend/src/redux/actions/layout/index.js
Normal file
11
sge-frontend/src/redux/actions/layout/index.js
Normal file
@@ -0,0 +1,11 @@
|
||||
// ** Handles Layout Content Width (full / boxed)
|
||||
export const handleContentWidth = value => dispatch => dispatch({ type: 'HANDLE_CONTENT_WIDTH', value })
|
||||
|
||||
// ** Handles Menu Collapsed State (Bool)
|
||||
export const handleMenuCollapsed = value => dispatch => dispatch({ type: 'HANDLE_MENU_COLLAPSED', value })
|
||||
|
||||
// ** Handles Menu Hidden State (Bool)
|
||||
export const handleMenuHidden = value => dispatch => dispatch({ type: 'HANDLE_MENU_HIDDEN', value })
|
||||
|
||||
// ** Handles RTL (Bool)
|
||||
export const handleRTL = value => dispatch => dispatch({ type: 'HANDLE_RTL', value })
|
||||
105
sge-frontend/src/redux/actions/mailSettings/index.js
Normal file
105
sge-frontend/src/redux/actions/mailSettings/index.js
Normal file
@@ -0,0 +1,105 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getMailSettings = () => {
|
||||
return async (dispatch) => {
|
||||
dispatch({ type: "GET_MAIL_SETTINGS_PENDING" });
|
||||
|
||||
try {
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
query GetMainMailInfo {
|
||||
mainMailInfo {
|
||||
id
|
||||
hostName
|
||||
smtpPort
|
||||
emailAddress
|
||||
mainMail
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
dispatch({
|
||||
type: "GET_MAIL_SETTINGS_FULFILLED",
|
||||
payload: response.data.data.mainMailInfo,
|
||||
});
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: "GET_MAIL_SETTINGS_REJECTED",
|
||||
payload: error.response?.data || error.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const updateMailSettings = (mailData) => {
|
||||
return async (dispatch) => {
|
||||
dispatch({ type: "UPDATE_MAIL_SETTINGS_PENDING" });
|
||||
|
||||
try {
|
||||
const { id, hostName, smtpPort, emailAddress, emailPassword, mainMail } =
|
||||
mailData;
|
||||
|
||||
let variables = { id, hostName, smtpPort, emailAddress, mainMail };
|
||||
if (emailPassword) {
|
||||
variables.emailPassword = emailPassword;
|
||||
}
|
||||
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation UpdateMailInfo($id: ID!, $hostName: String, $smtpPort: Int, $emailAddress: String, $emailPassword: String, $mainMail: Boolean) {
|
||||
updateMailInfo(
|
||||
id: $id,
|
||||
hostName: $hostName,
|
||||
smtpPort: $smtpPort,
|
||||
emailAddress: $emailAddress,
|
||||
emailPassword: $emailPassword,
|
||||
mainMail: $mainMail
|
||||
) {
|
||||
id
|
||||
hostName
|
||||
smtpPort
|
||||
emailAddress
|
||||
mainMail
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
dispatch({
|
||||
type: "UPDATE_MAIL_SETTINGS_FULFILLED",
|
||||
payload: response.data.data.updateMailInfo,
|
||||
});
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: "UPDATE_MAIL_SETTINGS_REJECTED",
|
||||
payload: error.response?.data || error.message,
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const clearMailError = () => ({
|
||||
type: "CLEAR_MAIL_ERROR",
|
||||
});
|
||||
|
||||
export const clearMailSuccess = () => ({
|
||||
type: "CLEAR_MAIL_SUCCESS",
|
||||
});
|
||||
807
sge-frontend/src/redux/actions/mainDataTables/index.js
Normal file
807
sge-frontend/src/redux/actions/mainDataTables/index.js
Normal file
@@ -0,0 +1,807 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getVMEmissionSummary = () => {
|
||||
return async (dispatch) => {
|
||||
try {
|
||||
const response = await ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
vmEmissionSummary {
|
||||
vmId
|
||||
vmName
|
||||
vmPower
|
||||
vmStatus
|
||||
totalEmission
|
||||
createdDate
|
||||
physicalMachine
|
||||
project
|
||||
dataCenter
|
||||
co2
|
||||
ch4
|
||||
n2o
|
||||
reportGeneratedTime
|
||||
}
|
||||
}
|
||||
`
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data.errors) {
|
||||
console.error("GraphQL Errors:", response.data.errors);
|
||||
throw new Error(response.data.errors[0]?.message || "GraphQL Error");
|
||||
}
|
||||
|
||||
const vmEmissionSummary = response.data.data.vmEmissionSummary;
|
||||
|
||||
dispatch({
|
||||
type: "GET_VM_EMISSION_SUMMARY",
|
||||
payload: {
|
||||
vmEmissionSummary,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("API Error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const getMainDataTables = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
mainDataTables(
|
||||
criteria:{
|
||||
year:"${data?.filterOptions?.year?.value}"
|
||||
deleted:false,
|
||||
city:"${data?.filterOptions.city}",
|
||||
district:"${data?.filterOptions.district}",
|
||||
neighborhood:"${data?.filterOptions.neighborhood}",
|
||||
}
|
||||
) {
|
||||
year
|
||||
sector {
|
||||
id
|
||||
tag
|
||||
}
|
||||
subSector{
|
||||
id
|
||||
tag
|
||||
}
|
||||
activitySubUnit{
|
||||
id
|
||||
tag
|
||||
}
|
||||
totalEmission
|
||||
emissionScope{
|
||||
tag
|
||||
}
|
||||
emissionSource{
|
||||
id
|
||||
tag
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const mainDataTables = response.data.data.mainDataTables;
|
||||
dispatch({
|
||||
type: "GET_MAIN_TABLES",
|
||||
payload: {
|
||||
mainDataTables,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getMainDataTablesWithPaginate = (data) => {
|
||||
return async (dispatch) => {
|
||||
try {
|
||||
const response = await ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
paginateMainDataTables(
|
||||
pagination: { page: 0, rowsPerPage: 100 }
|
||||
criteria: { deleted: false }
|
||||
sortBy: [{ field: "createdDate", direction: DESC }]
|
||||
) {
|
||||
content {
|
||||
id
|
||||
sector {
|
||||
id
|
||||
tag
|
||||
}
|
||||
subSector {
|
||||
id
|
||||
tag
|
||||
}
|
||||
co2
|
||||
ch4
|
||||
n2o
|
||||
totalEmission
|
||||
createdDate
|
||||
}
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data.errors) {
|
||||
console.error("GraphQL Errors:", response.data.errors);
|
||||
throw new Error(response.data.errors[0]?.message || "GraphQL Error");
|
||||
}
|
||||
|
||||
const mainDataTablesWithPaginate = response.data.data.paginateMainDataTables;
|
||||
|
||||
// Log the response for debugging
|
||||
console.log("API Response:", response.data);
|
||||
|
||||
dispatch({
|
||||
type: "GET_MAIN_TABLES_WITH_PAGINATE",
|
||||
payload: {
|
||||
mainDataTablesWithPaginate,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("API Error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const addDataInput = (data) => async (dispatch) => {
|
||||
try {
|
||||
const dataToJSON = JSON.stringify(data);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
createMainDataTable(input: ${deleteQuotesFromKey}) {
|
||||
id
|
||||
createdDate
|
||||
co2
|
||||
ch4
|
||||
n2o
|
||||
totalEmission
|
||||
deleted
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
if (response.data.errors) {
|
||||
const errorMessage = response.data.errors[0].extensions.ErrorCode;
|
||||
throw errorMessage;
|
||||
} else {
|
||||
dispatch({
|
||||
type: "ADD_DATA_INPUT",
|
||||
payload: {
|
||||
dataInput: response.data.data.createMainDataTable,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Network error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const createSolidWasteMainDataTable = (data) => async (dispatch) => {
|
||||
try {
|
||||
const dataToJSON = JSON.stringify(data);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
createSolidWasteMainDataTable(input: ${deleteQuotesFromKey}) {
|
||||
id
|
||||
createdDate
|
||||
co2
|
||||
ch4
|
||||
n2o
|
||||
totalEmission
|
||||
deleted
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data.errors) {
|
||||
const errorMessage = response.data.errors[0].extensions.ErrorCode;
|
||||
throw errorMessage;
|
||||
} else {
|
||||
dispatch({
|
||||
type: "ADD_SOLID_WASTE",
|
||||
payload: {
|
||||
dataInput: response.data.data.createSolidWasteMainDataTable,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Network error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const createWasteMainDataTable = (data) => async (dispatch) => {
|
||||
try {
|
||||
const dataToJSON = JSON.stringify(data);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
createWasteMainDataTable(input: ${deleteQuotesFromKey}) {
|
||||
id
|
||||
createdDate
|
||||
co2
|
||||
ch4
|
||||
n2o
|
||||
totalEmission
|
||||
deleted
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data.errors) {
|
||||
const errorMessage = response.data.errors[0].extensions.ErrorCode;
|
||||
throw errorMessage;
|
||||
} else {
|
||||
dispatch({
|
||||
type: "ADD_WASTE",
|
||||
payload: {
|
||||
dataInput: response.data.data.createWasteMainDataTable,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Network error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const updateDataInput = (data) => async (dispatch) => {
|
||||
try {
|
||||
let deleteIdFromData = { ...data };
|
||||
delete deleteIdFromData.id;
|
||||
const dataToJSON = JSON.stringify(deleteIdFromData);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
updateMainDataTable(id: "${data.id}",input: ${deleteQuotesFromKey}) {
|
||||
id
|
||||
createdDate
|
||||
year
|
||||
month
|
||||
city {
|
||||
id
|
||||
name
|
||||
}
|
||||
district {
|
||||
id
|
||||
name
|
||||
city {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
neighborhood {
|
||||
id
|
||||
name
|
||||
district {
|
||||
id
|
||||
name
|
||||
city {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
sector {
|
||||
id
|
||||
tag
|
||||
}
|
||||
subSector {
|
||||
id
|
||||
tag
|
||||
}
|
||||
emissionSource {
|
||||
id
|
||||
tag
|
||||
}
|
||||
activitySubUnit {
|
||||
id
|
||||
tag
|
||||
}
|
||||
consuptionUnit {
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
emissionScope {
|
||||
id
|
||||
tag
|
||||
}
|
||||
gpcReference
|
||||
solidWasteSupplement{
|
||||
domestic
|
||||
frec
|
||||
garden
|
||||
industrial
|
||||
mcfType{
|
||||
id
|
||||
typeName
|
||||
value
|
||||
}
|
||||
methaneCaptureRate
|
||||
paper
|
||||
textile
|
||||
tree
|
||||
}
|
||||
consuptionAmount
|
||||
co2
|
||||
ch4
|
||||
n2o
|
||||
totalEmission
|
||||
deleted
|
||||
scopeCheck
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data.errors) {
|
||||
const errorMessage = response.data.errors[0].extensions.ErrorCode;
|
||||
throw errorMessage;
|
||||
} else {
|
||||
dispatch({
|
||||
type: "UPDATE_DATA_INPUT",
|
||||
payload: {
|
||||
dataInput: response.data.data.updateMainDataTable,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Network error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const updateSolidWasteMainDataTable = (data) => async (dispatch) => {
|
||||
try {
|
||||
let deleteIdFromData = { ...data };
|
||||
delete deleteIdFromData.id;
|
||||
const dataToJSON = JSON.stringify(deleteIdFromData);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
updateSolidWasteMainDataTable(id: "${data.id}",input: ${deleteQuotesFromKey}) {
|
||||
id
|
||||
createdDate
|
||||
year
|
||||
month
|
||||
city {
|
||||
id
|
||||
name
|
||||
}
|
||||
district {
|
||||
id
|
||||
name
|
||||
city {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
neighborhood {
|
||||
id
|
||||
name
|
||||
district {
|
||||
id
|
||||
name
|
||||
city {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
sector {
|
||||
id
|
||||
tag
|
||||
}
|
||||
subSector {
|
||||
id
|
||||
tag
|
||||
}
|
||||
emissionSource {
|
||||
id
|
||||
tag
|
||||
}
|
||||
activitySubUnit {
|
||||
id
|
||||
tag
|
||||
}
|
||||
consuptionUnit {
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
emissionScope {
|
||||
id
|
||||
tag
|
||||
}
|
||||
gpcReference
|
||||
solidWasteSupplement{
|
||||
domestic
|
||||
frec
|
||||
garden
|
||||
industrial
|
||||
mcfType{
|
||||
id
|
||||
typeName
|
||||
value
|
||||
}
|
||||
methaneCaptureRate
|
||||
paper
|
||||
textile
|
||||
tree
|
||||
}
|
||||
consuptionAmount
|
||||
co2
|
||||
ch4
|
||||
n2o
|
||||
totalEmission
|
||||
deleted
|
||||
scopeCheck
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data.errors) {
|
||||
const errorMessage = response.data.errors[0].extensions.ErrorCode;
|
||||
throw errorMessage;
|
||||
} else {
|
||||
dispatch({
|
||||
type: "UPDATE_SOLID_WASTE",
|
||||
payload: {
|
||||
dataInput: response.data.data.updateSolidWasteMainDataTable,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
//console.log("Network error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const updateWasteMainDataTable = (data) => async (dispatch) => {
|
||||
try {
|
||||
let deleteIdFromData = { ...data };
|
||||
delete deleteIdFromData.id;
|
||||
const dataToJSON = JSON.stringify(deleteIdFromData);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
updateWasteMainDataTable(id: "${data.id}",input: ${deleteQuotesFromKey}) {
|
||||
id
|
||||
createdDate
|
||||
year
|
||||
month
|
||||
city {
|
||||
id
|
||||
name
|
||||
}
|
||||
district {
|
||||
id
|
||||
name
|
||||
city {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
neighborhood {
|
||||
id
|
||||
name
|
||||
district {
|
||||
id
|
||||
name
|
||||
city {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
sector {
|
||||
id
|
||||
tag
|
||||
}
|
||||
subSector {
|
||||
id
|
||||
tag
|
||||
}
|
||||
emissionSource {
|
||||
id
|
||||
tag
|
||||
}
|
||||
activitySubUnit {
|
||||
id
|
||||
tag
|
||||
}
|
||||
consuptionUnit {
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
emissionScope {
|
||||
id
|
||||
tag
|
||||
}
|
||||
gpcReference
|
||||
weightType
|
||||
personCount
|
||||
proteinAmount
|
||||
burnOrOpenBurn
|
||||
consuptionAmount
|
||||
co2
|
||||
ch4
|
||||
n2o
|
||||
totalEmission
|
||||
deleted
|
||||
scopeCheck
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data.errors) {
|
||||
const errorMessage = response.data.errors[0].extensions.ErrorCode;
|
||||
throw errorMessage;
|
||||
} else {
|
||||
dispatch({
|
||||
type: "UPDATE_WASTE",
|
||||
payload: {
|
||||
dataInput: response.data.data.updateWasteMainDataTable,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
//console.log("Network error:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteDataInput = (dataId) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `mutation {
|
||||
deleteMainDataTable(id:"${dataId}")
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
dispatch({
|
||||
type: "DELETE_DATA_INPUT",
|
||||
payload: {
|
||||
id: dataId,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getMainDataTablesByVMs = (data) => {
|
||||
return async (dispatch) => {
|
||||
const { filterOptions } = data;
|
||||
try {
|
||||
const response = await ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
mainDataTables(
|
||||
criteria: {
|
||||
year: "${filterOptions?.year?.value}"
|
||||
deleted: false
|
||||
}
|
||||
) {
|
||||
year
|
||||
sector { id tag }
|
||||
subSector{ id tag }
|
||||
activitySubUnit{ id tag }
|
||||
totalEmission
|
||||
emissionScope{ tag }
|
||||
emissionSource{ id tag }
|
||||
vm { id name status power }
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
const allMainDataTables = response.data.data.mainDataTables || [];
|
||||
dispatch({
|
||||
type: "GET_MAIN_TABLES",
|
||||
payload: {
|
||||
mainDataTables: allMainDataTables,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching main data tables:", error);
|
||||
dispatch({
|
||||
type: "GET_MAIN_TABLES",
|
||||
payload: {
|
||||
mainDataTables: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const testMainDataTables = () => {
|
||||
return async (dispatch) => {
|
||||
try {
|
||||
console.log('testMainDataTables: Testing basic mainDataTables query');
|
||||
|
||||
const response = await ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
mainDataTables(
|
||||
criteria: {
|
||||
deleted: false
|
||||
}
|
||||
) {
|
||||
id
|
||||
year
|
||||
totalEmission
|
||||
vm {
|
||||
id
|
||||
name
|
||||
status
|
||||
power
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
console.log('testMainDataTables: Response:', response.data);
|
||||
|
||||
if (response.data.errors) {
|
||||
console.error('testMainDataTables: GraphQL Errors:', response.data.errors);
|
||||
}
|
||||
|
||||
const allData = response.data.data.mainDataTables || [];
|
||||
console.log('testMainDataTables: All mainDataTables:', allData);
|
||||
console.log('testMainDataTables: Count:', allData.length);
|
||||
|
||||
// Check which records have VM data
|
||||
const recordsWithVM = allData.filter(record => record.vm);
|
||||
console.log('testMainDataTables: Records with VM:', recordsWithVM);
|
||||
console.log('testMainDataTables: Records with VM count:', recordsWithVM.length);
|
||||
|
||||
dispatch({
|
||||
type: "GET_MAIN_TABLES",
|
||||
payload: {
|
||||
mainDataTables: allData,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("testMainDataTables: Error:", error);
|
||||
}
|
||||
};
|
||||
};
|
||||
209
sge-frontend/src/redux/actions/neighborhoods/index.js
Normal file
209
sge-frontend/src/redux/actions/neighborhoods/index.js
Normal file
@@ -0,0 +1,209 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getNeighborhoods = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
paginateNeighborhoods(
|
||||
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
} }
|
||||
sortBy: [{ direction: ASC, field: "districtCityName" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
numberOfElements
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
content {
|
||||
id
|
||||
name
|
||||
district {
|
||||
id
|
||||
name
|
||||
city {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
minLong
|
||||
maxLong
|
||||
minLat
|
||||
maxLat
|
||||
isDeleted
|
||||
defaultNeighborhood
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const neighborhoods = response.data.data.paginateNeighborhoods;
|
||||
dispatch({
|
||||
type: "GET_NEIGHBORHOODS",
|
||||
payload: {
|
||||
neighborhoods,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const addNeighborhood = (neighborhood) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
createNeighborhood(
|
||||
input: {
|
||||
name: "${neighborhood.name}",
|
||||
district:"${neighborhood.district}",
|
||||
minLat:${Number(neighborhood.lat)},
|
||||
minLong:${Number(neighborhood.long)},
|
||||
maxLat:${Number(neighborhood.lat)},
|
||||
maxLong:${Number(neighborhood.long)}
|
||||
}
|
||||
) {
|
||||
id
|
||||
name
|
||||
district {
|
||||
id
|
||||
name
|
||||
city{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
minLong
|
||||
maxLong
|
||||
minLat
|
||||
maxLat
|
||||
isDeleted
|
||||
defaultNeighborhood
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "ADD_NEIGHBORHOOD",
|
||||
payload: {
|
||||
neighborhoods: response.data.data.createNeighborhood,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const updateNeighborhood = (neighborhood) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
updateNeighborhood(id:"${neighborhood.id}",
|
||||
input: {
|
||||
name: "${neighborhood.name}",
|
||||
district:"${neighborhood.district}",
|
||||
minLat:${neighborhood.lat},
|
||||
minLong:${neighborhood.long},
|
||||
maxLat:${neighborhood.lat},
|
||||
maxLong:${neighborhood.long}
|
||||
}
|
||||
) {
|
||||
id
|
||||
name
|
||||
district {
|
||||
id
|
||||
name
|
||||
city{
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
minLong
|
||||
maxLong
|
||||
minLat
|
||||
maxLat
|
||||
isDeleted
|
||||
defaultNeighborhood
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "UPDATE_NEIGHBORHOOD",
|
||||
payload: {
|
||||
neighborhoods: response.data.data.updateNeighborhood,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const deleteNeighborhood = (id) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `mutation {
|
||||
deleteNeighborhood(id:"${id}")
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
dispatch({
|
||||
type: "DELETE_NEIGHBORHOOD",
|
||||
payload: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
162
sge-frontend/src/redux/actions/notifications/index.js
Normal file
162
sge-frontend/src/redux/actions/notifications/index.js
Normal file
@@ -0,0 +1,162 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getQuickNotifications = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
getQuickNotifications {
|
||||
id
|
||||
createdDateTime
|
||||
title
|
||||
message
|
||||
read
|
||||
notificationType
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const getQuickNotifications = response.data.data.getQuickNotifications;
|
||||
dispatch({
|
||||
type: "GET_QUICKNOTIFICATIONS",
|
||||
payload: {
|
||||
getQuickNotifications,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const setNotificationRead = (id) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
setNotificationRead(id: "${id}") {
|
||||
id
|
||||
createdDateTime
|
||||
title
|
||||
message
|
||||
read
|
||||
notificationType
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const setNotificationRead = response.data.data.setNotificationRead;
|
||||
dispatch({
|
||||
type: "GET_SETNOTIFICATIONREAD",
|
||||
payload: {
|
||||
setNotificationRead,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getAllNotifications = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
getAllNotifications(
|
||||
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
} }
|
||||
sortBy: [{ direction: DESC, field: "createdDateTime" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
numberOfElements
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
content {
|
||||
id
|
||||
createdDateTime
|
||||
title
|
||||
message
|
||||
read
|
||||
notificationType
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const getAllNotifications = response.data.data.getAllNotifications;
|
||||
dispatch({
|
||||
type: "GET_ALLNOTIFICATION",
|
||||
payload: {
|
||||
getAllNotifications,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const notificationRemove = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
notificationRemove(id: "${data.selectedId}")
|
||||
}
|
||||
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const notificationRemove = response.data.data.notificationRemove;
|
||||
dispatch({
|
||||
type: "GET_NOTIFICATIONREMOVE",
|
||||
payload: {
|
||||
notificationRemove,
|
||||
},
|
||||
});
|
||||
if (notificationRemove === true) {
|
||||
let currentPage = data.currentPage;
|
||||
let rowsPerPage = data.rowsPerPage;
|
||||
dispatch(getAllNotifications({ currentPage, rowsPerPage }));
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
360
sge-frontend/src/redux/actions/organisations/index.js
Normal file
360
sge-frontend/src/redux/actions/organisations/index.js
Normal file
@@ -0,0 +1,360 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getOrganisations = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
organizations {
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDefault
|
||||
deleted
|
||||
areas{
|
||||
id
|
||||
tag
|
||||
}
|
||||
parents {
|
||||
parent{
|
||||
id
|
||||
tag
|
||||
deleted
|
||||
}
|
||||
}
|
||||
children {
|
||||
child{
|
||||
id
|
||||
tag
|
||||
deleted
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const organisations = response.data.data.organizations?.filter(
|
||||
(organization) => organization?.deleted != true
|
||||
);
|
||||
dispatch({
|
||||
type: "GET_ORGANISATIONS",
|
||||
payload: {
|
||||
organisations,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getOrganizationsWithPaginate = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
paginateOrganizations(
|
||||
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
} }
|
||||
criteria:{ deleted:${data.showDeletedOrganizations} }
|
||||
sortBy: [{ direction: ASC, field: "tag" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
numberOfElements
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
content {
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDefault
|
||||
deleted
|
||||
areas{
|
||||
id
|
||||
tag
|
||||
}
|
||||
parents {
|
||||
parent{
|
||||
id
|
||||
tag
|
||||
deleted
|
||||
}
|
||||
}
|
||||
children {
|
||||
child{
|
||||
id
|
||||
tag
|
||||
deleted
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const organizationsWithPaginate =
|
||||
response.data.data.paginateOrganizations;
|
||||
dispatch({
|
||||
type: "GET_ORGANIZATIONS_WITH_PAGINATE",
|
||||
payload: {
|
||||
organizationsWithPaginate,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getOrganisationById = (organizationId) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `{
|
||||
organization(id: "${organizationId}") {
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDefault
|
||||
deleted
|
||||
areas{
|
||||
id
|
||||
tag
|
||||
}
|
||||
parents {
|
||||
id
|
||||
parent{
|
||||
id
|
||||
tag
|
||||
deleted
|
||||
}
|
||||
}
|
||||
children {
|
||||
id
|
||||
child{
|
||||
id
|
||||
tag
|
||||
deleted
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const organisation = response.data.data.organization;
|
||||
dispatch({
|
||||
type: "GET_ORGANISATION_BY_ID",
|
||||
payload: {
|
||||
organisation,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const addOrganization = (data) => {
|
||||
const dataToJSON = JSON.stringify(data);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
createOrganization(input: ${deleteQuotesFromKey}) {
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDefault
|
||||
deleted
|
||||
areas{
|
||||
id
|
||||
tag
|
||||
}
|
||||
parents {
|
||||
parent{
|
||||
id
|
||||
tag
|
||||
deleted
|
||||
}
|
||||
}
|
||||
children {
|
||||
child{
|
||||
id
|
||||
tag
|
||||
deleted
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "ADD_ORGANIZATION",
|
||||
payload: {
|
||||
organisation: response.data.data.createOrganization,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const updateOrganization = (data) => {
|
||||
let deleteIdFromData = { ...data };
|
||||
delete deleteIdFromData.id;
|
||||
const dataToJSON = JSON.stringify(deleteIdFromData);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
updateOrganization(id: "` +
|
||||
data.id +
|
||||
`", input: ${deleteQuotesFromKey}) {
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDefault
|
||||
deleted
|
||||
areas{
|
||||
id
|
||||
tag
|
||||
}
|
||||
parents {
|
||||
parent{
|
||||
id
|
||||
tag
|
||||
deleted
|
||||
}
|
||||
}
|
||||
children {
|
||||
child{
|
||||
id
|
||||
tag
|
||||
deleted
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const organisation = response.data.data.updateOrganization;
|
||||
dispatch({
|
||||
type: "UPDATE_ORGANIZATION",
|
||||
payload: {
|
||||
organisation: organisation,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const deleteOrganization = (id) => {
|
||||
return async (dispatch) => {
|
||||
return ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
deleteOrganization(id: "` +
|
||||
id +
|
||||
`")
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
// Check if there are errors in the response
|
||||
if (response.data.errors) {
|
||||
// Return the error message to be handled by the component
|
||||
return { error: response.data.errors[0].message };
|
||||
}
|
||||
|
||||
// If successful, dispatch the action and return success
|
||||
dispatch({
|
||||
type: "DELETE_ORGANIZATION",
|
||||
payload: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
return { success: true };
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
// Return a generic error message to be handled by the component
|
||||
return { error: "An error occurred while deleting the organization" };
|
||||
});
|
||||
};
|
||||
};
|
||||
82
sge-frontend/src/redux/actions/permissions/index.js
Normal file
82
sge-frontend/src/redux/actions/permissions/index.js
Normal file
@@ -0,0 +1,82 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getUserPermissions = () => {
|
||||
const roleId = localStorage.getItem("roleId");
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
role(id: "${roleId}") {
|
||||
permissions {
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
//alfabetik sıralama
|
||||
const sortPermissions = response.data.data.role?.permissions.sort(
|
||||
function (a, b) {
|
||||
return a.description.localeCompare(b.description);
|
||||
}
|
||||
);
|
||||
const userpermissions = sortPermissions;
|
||||
dispatch({
|
||||
type: "GET_USERPERMISSIONS",
|
||||
payload: {
|
||||
userpermissions,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getAllPermissions = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
permissions {
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const sortPermissions = response.data.data.permissions.sort(
|
||||
function (a, b) {
|
||||
return a.description.localeCompare(b.description);
|
||||
}
|
||||
);
|
||||
dispatch({
|
||||
type: "GET_PERMISSIONS",
|
||||
payload: {
|
||||
permissions: sortPermissions,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
213
sge-frontend/src/redux/actions/question/index.js
Normal file
213
sge-frontend/src/redux/actions/question/index.js
Normal file
@@ -0,0 +1,213 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getQuestions = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
questions {
|
||||
id
|
||||
tag
|
||||
question
|
||||
isDefault
|
||||
isDeleted
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const questions1 = response.data.data.questions;
|
||||
const questions = questions1.filter(
|
||||
(question) => question.isDeleted != true
|
||||
);
|
||||
dispatch({
|
||||
type: "GET_QUESTİONS",
|
||||
payload: {
|
||||
questions,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getQuestionsWithPaginate = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
paginateQuestions(
|
||||
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
} }
|
||||
criteria:{deleted:false}
|
||||
sortBy: [{ direction: ASC, field: "tag" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
numberOfElements
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
content {
|
||||
id
|
||||
tag
|
||||
question
|
||||
isDefault
|
||||
isDeleted
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const questionsWithPaginate = response?.data?.data?.paginateQuestions;
|
||||
dispatch({
|
||||
type: "GET_QUESTİONS_WITH_PAGINATE",
|
||||
payload: {
|
||||
questionsWithPaginate,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const addQuestion = (data) => {
|
||||
const dataToJSON = JSON.stringify(data);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
createQuestion(
|
||||
input: ${deleteQuotesFromKey} )
|
||||
{
|
||||
id
|
||||
tag
|
||||
question
|
||||
isDefault
|
||||
isDeleted
|
||||
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "ADD_QUESTİON",
|
||||
payload: {
|
||||
questions: response.data.data.createQuestion,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const updateQuestion = (data) => {
|
||||
let deleteIdFromData = { ...data };
|
||||
delete deleteIdFromData.id;
|
||||
const dataToJSON = JSON.stringify(deleteIdFromData);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
updateQuestion(id: "` +
|
||||
data.id +
|
||||
`", input: ${deleteQuotesFromKey}) {
|
||||
id
|
||||
tag
|
||||
question
|
||||
isDeleted
|
||||
isDefault
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "UPDATE_QUESTİON",
|
||||
payload: {
|
||||
questions: response.data.data.updateQuestion,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const deleteQuestion = (id) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `mutation {
|
||||
deleteQuestion(id:"${id}")
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
dispatch({
|
||||
type: "DELETE_QUESTİON",
|
||||
payload: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
229
sge-frontend/src/redux/actions/roles/index.js
Normal file
229
sge-frontend/src/redux/actions/roles/index.js
Normal file
@@ -0,0 +1,229 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
const roleTag = localStorage.getItem("roleTag");
|
||||
export const getRoles = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
roles {
|
||||
id
|
||||
tag
|
||||
permissions{
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const roles =
|
||||
roleTag === "SUPER_ADMIN"
|
||||
? response.data.data.roles
|
||||
: response.data.data.roles.filter(
|
||||
(role) => role.tag !== "SUPER_ADMIN"
|
||||
);
|
||||
dispatch({
|
||||
type: "GET_ROLES",
|
||||
payload: {
|
||||
roles,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getRolesWithPaginate = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
paginateRoles(
|
||||
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
} }
|
||||
sortBy: [{ direction: ASC, field: "tag" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
numberOfElements
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
content {
|
||||
id
|
||||
tag
|
||||
permissions {
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
let roles = {};
|
||||
if (roleTag === "SUPER_ADMIN") {
|
||||
roles = response.data.data.paginateRoles;
|
||||
} else {
|
||||
const filteredRoles =
|
||||
response.data.data.paginateRoles?.content?.filter(
|
||||
(role) => role.tag !== "SUPER_ADMIN"
|
||||
);
|
||||
roles = {
|
||||
...response.data.data.paginateRoles,
|
||||
content: filteredRoles,
|
||||
};
|
||||
}
|
||||
dispatch({
|
||||
type: "GET_ROLES_WITH_PAGINATE",
|
||||
payload: {
|
||||
roles,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const addRoles = (role) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
createRole(
|
||||
input: {
|
||||
tag: "${role.tag}",
|
||||
permissions:[${role.permissions}]
|
||||
}
|
||||
) {
|
||||
id
|
||||
tag
|
||||
permissions{
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "ADD_ROLES",
|
||||
payload: {
|
||||
roles: response.data.data.createRole,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const updateRoles = (role) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
updateRole(id:"${role.id}",
|
||||
input: {
|
||||
tag:"${role.tag}",
|
||||
permissions:[${role.permissions}]
|
||||
}
|
||||
) {
|
||||
id
|
||||
tag
|
||||
permissions {
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "UPDATE_ROLES",
|
||||
payload: {
|
||||
roles: response.data.data.updateRole,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const deleteRoles = (roleId) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `mutation {
|
||||
deleteRole(id:"${roleId}")
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
dispatch({
|
||||
type: "DELETE_ROLES",
|
||||
payload: {
|
||||
id: roleId,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
509
sge-frontend/src/redux/actions/surveys/index.js
Normal file
509
sge-frontend/src/redux/actions/surveys/index.js
Normal file
@@ -0,0 +1,509 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getSurvey = (surveyId) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
survey(id: "${surveyId}") {
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDefault
|
||||
isDeleted
|
||||
createdAt
|
||||
relationSurveyQuestions {
|
||||
id
|
||||
isDeleted
|
||||
question{
|
||||
id
|
||||
tag
|
||||
question
|
||||
relationQuestionAnswers{
|
||||
id
|
||||
answer{
|
||||
answer
|
||||
}
|
||||
}
|
||||
}
|
||||
orderNo
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const survey = response.data?.data?.survey;
|
||||
//const survey = survey1.filter((survey) => survey.isDeleted != true);
|
||||
dispatch({
|
||||
type: "GET_SURVEY",
|
||||
payload: {
|
||||
survey,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const getSurveysWithPaginate = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
paginateSurveys(
|
||||
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
} }
|
||||
criteria: {deleted:false}
|
||||
sortBy: [{ direction: ASC, field: "id" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
numberOfElements
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
content {
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDefault
|
||||
isDeleted
|
||||
createdAt
|
||||
relationSurveyQuestions {
|
||||
id
|
||||
isDeleted
|
||||
question {
|
||||
id
|
||||
question
|
||||
relationQuestionAnswers {
|
||||
answer {
|
||||
id
|
||||
answer
|
||||
}
|
||||
}
|
||||
}
|
||||
orderNo
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const surveysWithPaginate = response?.data?.data?.paginateSurveys;
|
||||
dispatch({
|
||||
type: "GET_SURVEYS_WITH_PAGINATE",
|
||||
payload: {
|
||||
surveysWithPaginate,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const savedSurveys = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
savedSurveys(sortBy: [{ direction: ASC, field: "id" }]) {
|
||||
questionValue
|
||||
answerValue
|
||||
isDeleted
|
||||
isApproved
|
||||
publishedSurvey {
|
||||
id
|
||||
participant_email
|
||||
participant_id
|
||||
isDeleted
|
||||
isUsed
|
||||
created_at
|
||||
start_at
|
||||
expire_at
|
||||
survey{
|
||||
id
|
||||
tag
|
||||
description
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const savedSurveys = response?.data?.data?.savedSurveys;
|
||||
dispatch({
|
||||
type: "SAVED_SURVEYS",
|
||||
payload: {
|
||||
savedSurveys,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const savedSurveysFromSurveys = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
surveys(criteria: { deleted: false }){
|
||||
id
|
||||
tag
|
||||
description
|
||||
createdAt
|
||||
publishedSurveys {
|
||||
id
|
||||
participant_email
|
||||
participant_id
|
||||
created_at
|
||||
start_at
|
||||
expire_at
|
||||
savedSurveys{
|
||||
answerValue
|
||||
questionValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const savedSurveysFromSurveys = response?.data?.data?.surveys;
|
||||
dispatch({
|
||||
type: "SAVED_SURVEYS_FROM_SURVEYS",
|
||||
payload: {
|
||||
savedSurveysFromSurveys,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const addSurvey = (data) => {
|
||||
const dataToJSON = JSON.stringify(data);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
addSurvey(
|
||||
input: ${deleteQuotesFromKey}
|
||||
) {
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDefault
|
||||
isDeleted
|
||||
createdAt
|
||||
relationSurveyQuestions {
|
||||
id
|
||||
isDeleted
|
||||
question {
|
||||
question
|
||||
relationQuestionAnswers {
|
||||
answer {
|
||||
answer
|
||||
}
|
||||
}
|
||||
}
|
||||
orderNo
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "ADD_SURVEY",
|
||||
payload: {
|
||||
surveys: response.data.data.addSurvey,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const addQuestionToSurvey = (data) => {
|
||||
let deleteIdFromData = { ...data };
|
||||
delete deleteIdFromData.id;
|
||||
const dataToJSON = JSON.stringify(deleteIdFromData);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
addQuestionToSurvey(surveyId: "` +
|
||||
data.id +
|
||||
`",
|
||||
input: ${deleteQuotesFromKey}
|
||||
) {
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDefault
|
||||
isDeleted
|
||||
createdAt
|
||||
relationSurveyQuestions {
|
||||
id
|
||||
isDeleted
|
||||
question {
|
||||
question
|
||||
relationQuestionAnswers {
|
||||
answer {
|
||||
answer
|
||||
}
|
||||
}
|
||||
}
|
||||
orderNo
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "ADD_QUESTION_TO_SURVEY",
|
||||
payload: {
|
||||
surveys: response.data.data.addQuestionToSurvey,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const publishedSurvey = (publishedId) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
publishedSurvey(id: "${publishedId}") {
|
||||
id
|
||||
q_link
|
||||
participant_email
|
||||
participant_id
|
||||
isDefault
|
||||
isDeleted
|
||||
isUsed
|
||||
created_at
|
||||
start_at
|
||||
expire_at
|
||||
survey {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const publishedSurvey = response.data.data.publishedSurvey;
|
||||
//const survey = survey1.filter((survey) => survey.isDeleted != true);
|
||||
dispatch({
|
||||
type: "PUBLİSHED_SURVEY",
|
||||
payload: {
|
||||
publishedSurvey,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
export const updateQuestion = (data) => {
|
||||
let deleteIdFromData = { ...data };
|
||||
delete deleteIdFromData.id;
|
||||
const dataToJSON = JSON.stringify(deleteIdFromData);
|
||||
const deleteQuotesFromKey = dataToJSON.replace(/"([^(")"]+)":/g, "$1:");
|
||||
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
updateQuestion(id: "` +
|
||||
data.id +
|
||||
`", input: ${deleteQuotesFromKey}) {
|
||||
id
|
||||
tag
|
||||
question
|
||||
isDeleted
|
||||
isDefault
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "UPDATE_QUESTİON",
|
||||
payload: {
|
||||
questions: response.data.data.updateQuestion,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
*/
|
||||
export const deleteQuestionFromSurvey = ({ surveyId, deleteQuestionId }) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`mutation {
|
||||
deleteQuestionFromSurvey(surveyId: "` +
|
||||
surveyId +
|
||||
`",surveyQuestionRelationId: "` +
|
||||
deleteQuestionId +
|
||||
`"){
|
||||
id
|
||||
tag
|
||||
description
|
||||
isDefault
|
||||
isDeleted
|
||||
createdAt
|
||||
relationSurveyQuestions {
|
||||
id
|
||||
isDeleted
|
||||
question{
|
||||
question
|
||||
}
|
||||
orderNo
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "DELETE_QUESTİON_FROM_SURVEY",
|
||||
payload: {
|
||||
data: response.data.data.deleteQuestionFromSurvey,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
export const deleteSurvey = (id) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `mutation {
|
||||
deleteSurvey(id:"${id}")
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
dispatch({
|
||||
type: "DELETE_SURVEY",
|
||||
payload: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
37
sge-frontend/src/redux/actions/systemHistory/index.js
Normal file
37
sge-frontend/src/redux/actions/systemHistory/index.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getSystemHistory = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
systemHistories (sortBy: [{ direction: ASC, field: "createdDateTime" }]){
|
||||
id
|
||||
createdDateTime
|
||||
hash
|
||||
logMessage
|
||||
logType
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const systemHistories = response.data.data.systemHistories.reverse();
|
||||
dispatch({
|
||||
type: "GET_SYSTEMHISTORY",
|
||||
payload: {
|
||||
systemHistories,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
27
sge-frontend/src/redux/actions/upload/index.js
Normal file
27
sge-frontend/src/redux/actions/upload/index.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const excelUpload = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: ``,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const excelUpload = response.data.data.excelUpload;
|
||||
dispatch({
|
||||
type: "EXCEL_UPLOAD",
|
||||
payload: {
|
||||
excelUpload,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
138
sge-frontend/src/redux/actions/user/index.js
Normal file
138
sge-frontend/src/redux/actions/user/index.js
Normal file
@@ -0,0 +1,138 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getUser = (userId) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
user(id: "${userId}") {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
email
|
||||
phoneNumber
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const user = response.data.data.user;
|
||||
dispatch({
|
||||
type: "GET_USER",
|
||||
payload: {
|
||||
user,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const updateUserInfo = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
updateUser(id: "` +
|
||||
data.id +
|
||||
`", input: {firstName:"` +
|
||||
data.firstName +
|
||||
`",lastName:"` +
|
||||
data.lastName +
|
||||
`", email:"` +
|
||||
data.email +
|
||||
`",phoneNumber:"` +
|
||||
data.phoneNumber +
|
||||
`"}) {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
email
|
||||
phoneNumber
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const user = response.data.data.updateUser;
|
||||
dispatch({
|
||||
type: "UPDATE_USERINFO",
|
||||
payload: {
|
||||
data: response.data.data.user,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const updatePassword = (data) => async (dispatch) => {
|
||||
try {
|
||||
const response = await ApplicationService.http().post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
updateUser(id: "` +
|
||||
data.userId +
|
||||
`", input: {password:"` +
|
||||
data.newPassword +
|
||||
`",oldPassword:"` +
|
||||
data.oldPassword +
|
||||
`"}) {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
email
|
||||
phoneNumber
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (response.data.errors) {
|
||||
const errorMessage = response.data.errors[0].extensions.ErrorCode;
|
||||
throw errorMessage;
|
||||
} else {
|
||||
dispatch({
|
||||
type: "UPDATE_PASSWORD",
|
||||
payload: {
|
||||
data: response.data.data.updateUser,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Network Error", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
53
sge-frontend/src/redux/actions/userHistory/index.js
Normal file
53
sge-frontend/src/redux/actions/userHistory/index.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
export const getUserHistory = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
|
||||
{
|
||||
paginateUserHistories(
|
||||
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
}
|
||||
}
|
||||
sortBy: [{ direction: DESC, field: "createdDateTime" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
numberOfElements
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
content {
|
||||
id
|
||||
createdDateTime
|
||||
hash
|
||||
logMessage
|
||||
logType
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const userhistories = response.data.data.paginateUserHistories;
|
||||
dispatch({
|
||||
type: "GET_USERHISTORY",
|
||||
payload: {
|
||||
userhistories,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
89
sge-frontend/src/redux/actions/userProfileSettings/index.js
Normal file
89
sge-frontend/src/redux/actions/userProfileSettings/index.js
Normal file
@@ -0,0 +1,89 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getUserProfileSettings = () => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
getUserProfileSettings {
|
||||
id
|
||||
user
|
||||
infoMail
|
||||
errorMail
|
||||
infoNotification
|
||||
errorNotification
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const getUserProfileSettings =
|
||||
response.data.data.getUserProfileSettings;
|
||||
|
||||
dispatch({
|
||||
type: "GET_USERPROFILESETTING",
|
||||
payload: {
|
||||
getUserProfileSettings,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error -- responsee", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const updateUserProfileSettings = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
mutation {
|
||||
updateUserProfileSettings(
|
||||
input: {
|
||||
infoMail: ${data.infoMail}
|
||||
errorMail: ${data.errorMail}
|
||||
infoNotification: ${data.infoNotification}
|
||||
errorNotification: ${data.errorNotification}
|
||||
}
|
||||
) {
|
||||
id
|
||||
user
|
||||
infoMail
|
||||
errorMail
|
||||
infoNotification
|
||||
errorNotification
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "UPDATE_USERPROFILESETTING",
|
||||
payload: {
|
||||
data: response.data.data.updateUserProfileSettings,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
233
sge-frontend/src/redux/actions/users/index.js
Normal file
233
sge-frontend/src/redux/actions/users/index.js
Normal file
@@ -0,0 +1,233 @@
|
||||
import ApplicationService from "../../../services/ApplicationService";
|
||||
|
||||
export const getUsersHttp = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query: `
|
||||
{
|
||||
paginateUsers(
|
||||
pagination: { page: ${data.currentPage - 1}, rowsPerPage: ${
|
||||
data.rowsPerPage
|
||||
} }
|
||||
criteria: {organizations:"${
|
||||
data?.selectedOrganization?.value
|
||||
? data?.selectedOrganization?.value
|
||||
: data?.selectedOrganization
|
||||
}",delete:${data.showDeletedUsers}}
|
||||
sortBy: [{ direction: ASC, field: "firstName" }]
|
||||
) {
|
||||
pageInfo {
|
||||
totalElements
|
||||
totalPages
|
||||
numberOfElements
|
||||
pageNumber
|
||||
pageSize
|
||||
}
|
||||
content {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
email
|
||||
phoneNumber
|
||||
lastLoginTime
|
||||
status
|
||||
delete
|
||||
role {
|
||||
id
|
||||
tag
|
||||
}
|
||||
organizations{
|
||||
id
|
||||
tag
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
const users = response.data.data.paginateUsers;
|
||||
dispatch({
|
||||
type: "GET_USERS",
|
||||
payload: {
|
||||
users,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error -- responsee", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const addUser = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
createUser(input: {
|
||||
email:"` +
|
||||
data.email +
|
||||
`",firstName:"` +
|
||||
data.firstName +
|
||||
`",lastName:"` +
|
||||
data.lastName +
|
||||
`",password:"` +
|
||||
data.password +
|
||||
`",phoneNumber:"` +
|
||||
data.phoneNumber +
|
||||
`",status:"` +
|
||||
data.status +
|
||||
`",role:"` +
|
||||
data.role +
|
||||
`",
|
||||
organizations:[${data.organizations}]}) {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
email
|
||||
phoneNumber
|
||||
status
|
||||
delete
|
||||
role {
|
||||
id
|
||||
tag
|
||||
default_role
|
||||
}
|
||||
organizations{
|
||||
id
|
||||
tag
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "ADD_USER",
|
||||
payload: {
|
||||
data: response.data.data.createUser,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const updateUser = (data) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
updateUser(id: "` +
|
||||
data.id +
|
||||
`", input: {firstName:"` +
|
||||
data.firstName +
|
||||
`",lastName:"` +
|
||||
data.lastName +
|
||||
`", email:"` +
|
||||
data.email +
|
||||
`", role:"` +
|
||||
data.role +
|
||||
`",phoneNumber:"` +
|
||||
data.phoneNumber +
|
||||
`",organizations:[${data.organizations}]}) {
|
||||
id
|
||||
firstName
|
||||
lastName
|
||||
email
|
||||
phoneNumber
|
||||
status
|
||||
delete
|
||||
role {
|
||||
id
|
||||
tag
|
||||
default_role
|
||||
}
|
||||
organizations{
|
||||
id
|
||||
tag
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "UPDATE_USER",
|
||||
payload: {
|
||||
data: response.data.data.updateUser,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const deleteUser = (userId) => {
|
||||
return async (dispatch) => {
|
||||
ApplicationService.http()
|
||||
.post(
|
||||
"/graphql",
|
||||
{
|
||||
query:
|
||||
`
|
||||
mutation {
|
||||
deleteUser(id: "` +
|
||||
userId +
|
||||
`")
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer " + localStorage.getItem("accessToken"),
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: "DELETE_USER",
|
||||
payload: {
|
||||
id: userId,
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("error -- responsee", error);
|
||||
});
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user