diff --git a/.changeset/honest-spies-think.md b/.changeset/honest-spies-think.md new file mode 100644 index 0000000000..b55beaadc0 --- /dev/null +++ b/.changeset/honest-spies-think.md @@ -0,0 +1,6 @@ +--- +"@scow/mis-server": patch +"@scow/mis-web": patch +--- + +修复账户添加用户提示语 diff --git a/apps/mis-server/src/services/user.ts b/apps/mis-server/src/services/user.ts index 2d35590b8e..49bc2a8fd4 100644 --- a/apps/mis-server/src/services/user.ts +++ b/apps/mis-server/src/services/user.ts @@ -144,10 +144,19 @@ export const userServiceServer = plugin((server) => { userId, tenant: { name: tenantName }, }); - if (!account || !user) { + if (!user) { + throw { + code: Status.NOT_FOUND, + message: `User ${userId} or tenant ${tenantName} is not found.`, + details:"USER_OR_TENANT_NOT_FOUND", + }; + } + + if (!account) { throw { 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", }; } diff --git a/apps/mis-web/src/pageComponents/users/AddUserButton.tsx b/apps/mis-web/src/pageComponents/users/AddUserButton.tsx index d60269c087..4a34cbd664 100644 --- a/apps/mis-web/src/pageComponents/users/AddUserButton.tsx +++ b/apps/mis-web/src/pageComponents/users/AddUserButton.tsx @@ -95,9 +95,13 @@ export const AddUserButton: React.FC = ({ 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 }); diff --git a/apps/mis-web/src/pages/api/users/addToAccount.ts b/apps/mis-web/src/pages/api/users/addToAccount.ts index 2c865978dc..7128c3b661 100644 --- a/apps/mis-web/src/pages/api/users/addToAccount.ts +++ b/apps/mis-web/src/pages/api/users/addToAccount.ts @@ -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"), ]), }), @@ -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 } }; + } + } + , })); });