Skip to content

Commit

Permalink
fix(mis-web): 修复账户添加用户提示语 (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
OYX-1 authored Aug 26, 2023
1 parent 8f0e51b commit ffefb17
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changeset/honest-spies-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@scow/mis-server": patch
"@scow/mis-web": patch
---

修复账户添加用户提示语
13 changes: 11 additions & 2 deletions apps/mis-server/src/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,19 @@ export const userServiceServer = plugin((server) => {
userId, tenant: { name: tenantName },
});

if (!account || !user) {
if (!user) {
throw <ServiceError>{
code: Status.NOT_FOUND,
message: `User ${userId} or tenant ${tenantName} is not found.`,
details:"USER_OR_TENANT_NOT_FOUND",
};
}

if (!account) {
throw <ServiceError>{
code: Status.NOT_FOUND,
message: `Account ${accountName} or user ${userId}, tenant ${tenantName} is not found.`,
message: `Account ${accountName} or tenant ${tenantName} is not found.`,
details:"ACCOUNT_OR_TENANT_NOT_FOUND",
};
}

Expand Down
10 changes: 7 additions & 3 deletions apps/mis-web/src/pageComponents/users/AddUserButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ export const AddUserButton: React.FC<Props> = ({ refresh, accountName, token })
}
})
.httpError(404, ({ code }) => {
if (code === "ACCOUNT_NOT_FOUND") {
message.error("账户不存在");
} else if (code === "USER_NOT_FOUND") {
if (code === "USER_ALREADY_EXIST_IN_OTHER_TENANT") {
message.error(`用户${name}已属于其他租户`);
}
else if (code === "ACCOUNT_OR_TENANT_NOT_FOUND") {
message.error("租户或账户不存在");
}
else if (code === "USER_NOT_FOUND") {
if (useBuiltinCreateUser()) {
setModalShow(false);
setNewUserInfo({ identityId, name });
Expand Down
21 changes: 19 additions & 2 deletions apps/mis-web/src/pages/api/users/addToAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export const AddUserToAccountSchema = typeboxRouteSchema({

404: Type.Object({
code: Type.Union([
Type.Literal("ACCOUNT_NOT_FOUND"),
Type.Literal("ACCOUNT_OR_TENANT_NOT_FOUND"),
Type.Literal("USER_ALREADY_EXIST_IN_OTHER_TENANT"),
Type.Literal("USER_NOT_FOUND"),
]),
}),
Expand Down Expand Up @@ -93,7 +94,23 @@ export default /* #__PURE__*/typeboxRoute(AddUserToAccountSchema, async (req, re
}).then(() => ({ 204: null }))
.catch(handlegRPCError({
[Status.ALREADY_EXISTS]: () => ({ 409: { code: "ACCOUNT_OR_USER_ERROR" as const, message:"用户已经存在于此账户中!" } }),
[Status.NOT_FOUND]: () => ({ 404: { code: "ACCOUNT_NOT_FOUND" as const } }),
[Status.INTERNAL]: (e) => { return ({ 409: { code: "ACCOUNT_OR_USER_ERROR" as const, message: e.details } }); },
[Status.NOT_FOUND]: (e) => {

if (e.details === "USER_OR_TENANT_NOT_FOUND") {

/**
* 后端接口addUserToAccount返回USER_OR_TENANT_NOT_FOUND
* 说明操作者的租户下的不存在要添加的这个用户
* 该用户存不存在于scow系统中在上面的checkNameMatch函数中已通过检查
* */

return { 404: { code: "USER_ALREADY_EXIST_IN_OTHER_TENANT" as const } };
} else {

return { 404: { code: "ACCOUNT_OR_TENANT_NOT_FOUND" as const } };
}
}
,
}));
});

0 comments on commit ffefb17

Please sign in to comment.