feat: refactor code to use responseOK everywhere (#2111)

* refactor: use responseOK return frontend format json data

* revert handle error

* revert handle error
This commit is contained in:
Yaodong Yu
2023-07-23 09:49:16 +08:00
committed by GitHub
parent fc9528be43
commit a6f803aff1
53 changed files with 178 additions and 218 deletions

View File

@ -50,7 +50,9 @@ class PermissionEditPage extends React.Component {
getPermission() {
PermissionBackend.getPermission(this.state.organizationName, this.state.permissionName)
.then((res) => {
if (res === null) {
const permission = res.data;
if (permission === null) {
this.props.history.push("/404");
return;
}
@ -61,14 +63,14 @@ class PermissionEditPage extends React.Component {
}
this.setState({
permission: res,
permission: permission,
});
this.getUsers(res.owner);
this.getRoles(res.owner);
this.getModels(res.owner);
this.getResources(res.owner);
this.getModel(res.owner, res.model);
this.getUsers(permission.owner);
this.getRoles(permission.owner);
this.getModels(permission.owner);
this.getResources(permission.owner);
this.getModel(permission.owner, permission.model);
});
}
@ -76,7 +78,7 @@ class PermissionEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin")
.then((res) => {
this.setState({
organizations: (res.msg === undefined) ? res : [],
organizations: res.data || [],
});
});
}
@ -88,8 +90,9 @@ class PermissionEditPage extends React.Component {
Setting.showMessage("error", res.msg);
return;
}
this.setState({
users: res,
users: res.data,
});
});
}
@ -101,8 +104,9 @@ class PermissionEditPage extends React.Component {
Setting.showMessage("error", res.msg);
return;
}
this.setState({
roles: res,
roles: res.data,
});
});
}
@ -114,21 +118,21 @@ class PermissionEditPage extends React.Component {
Setting.showMessage("error", res.msg);
return;
}
this.setState({
models: res,
models: res.data,
});
});
}
getModel(organizationName, modelName) {
if (modelName === "") {
return;
}
ModelBackend.getModel(organizationName, modelName)
.then((res) => {
if (res.status === "error") {
Setting.showMessage("error", res.msg);
return;
}
this.setState({
model: res,
model: res.data,
});
});
}
@ -137,7 +141,7 @@ class PermissionEditPage extends React.Component {
ApplicationBackend.getApplicationsByOrganization("admin", organizationName)
.then((res) => {
this.setState({
resources: (res.msg === undefined) ? res : [],
resources: res.data || [],
});
});
}