Skip to content

Commit

Permalink
Removed: logic to fetch user-profile(#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymaheshwari1 committed Jan 12, 2024
1 parent 64db543 commit ef3a5e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 50 deletions.
7 changes: 0 additions & 7 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ const login = async (username: string, password: string): Promise <any> => {
});
}

const getProfile = async (): Promise <any> => {
return api({
url: "user-profile",
method: "get",
});
}
const getAvailableTimeZones = async (): Promise <any> => {
return api({
url: "getAvailableTimeZones",
Expand Down Expand Up @@ -47,7 +41,6 @@ const checkPermission = async (payload: any): Promise <any> => {
export const UserService = {
login,
getAvailableTimeZones,
getProfile,
setUserTimeZone,
checkPermission
}
50 changes: 7 additions & 43 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,16 @@ const actions: ActionTree<UserState, RootState> = {
/**
* Login user and return token
*/
async login ({ commit, dispatch }, { username, password }) {
async login({ commit }, { username, password }) {
try {
// TODO: implement support for fetching user-profile
// TODO: implement support for permission check
// TODO: implement support for fetching product stores for user
const resp = await UserService.login(username, password)
if (resp.status === 200 && resp.data) {
if (resp.data.token) {
const permissionId = process.env.VUE_APP_PERMISSION_ID;
if (permissionId) {
const checkPermissionResponse = await UserService.checkPermission({
data: {
permissionId
},
headers: {
Authorization: "Bearer " + resp.data.token,
"Content-Type": "application/json"
}
});

if (checkPermissionResponse.status === 200 && !hasError(checkPermissionResponse) && checkPermissionResponse.data && checkPermissionResponse.data.hasPermission) {
commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token })
dispatch("getProfile")
if (resp.data._EVENT_MESSAGE_ && resp.data._EVENT_MESSAGE_.startsWith("Alert:")) {
// TODO Internationalise text
showToast(translate(resp.data._EVENT_MESSAGE_));
}
return resp.data;
} else {
const permissionError = "You do not have permission to access the app.";
showToast(translate(permissionError));
console.error("error", permissionError);
return Promise.reject(new Error(permissionError));
}
} else {
commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token })
dispatch("getProfile")
return resp.data;
}
commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token })
return resp.data;
} else if (hasError(resp)) {
showToast(translate("Sorry, your username or password is incorrect. Please try again."));
console.error("error", resp.data._ERROR_MESSAGE_);

Check warning on line 26 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

Unexpected console statement

Check warning on line 26 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

Unexpected console statement
Expand Down Expand Up @@ -74,16 +48,6 @@ const actions: ActionTree<UserState, RootState> = {

},

/**
* Get User profile
*/
async getProfile ( { commit }) {
const resp = await UserService.getProfile()
if (resp.status === 200) {
commit(types.USER_INFO_UPDATED, resp.data);
}
},

/**
* update current facility information
*/
Expand All @@ -107,7 +71,7 @@ const actions: ActionTree<UserState, RootState> = {
/**
* Set User Instance Url
*/
setUserInstanceUrl ({ state, commit }, payload){
setUserInstanceUrl ({ commit }, payload){
commit(types.USER_INSTANCE_URL_UPDATED, payload)
}
}
Expand Down

0 comments on commit ef3a5e3

Please sign in to comment.