Skip to content

Commit

Permalink
feat(next): display email of customer services and collaborators
Browse files Browse the repository at this point in the history
  • Loading branch information
sdjdd committed Sep 8, 2023
1 parent 2f22b34 commit dbc3568
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 28 deletions.
10 changes: 5 additions & 5 deletions next/api/src/controller/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { FindModelPipe, ParseCsvPipe, TrimPipe, ZodValidationPipe } from '@/common/pipe';
import { auth, customerServiceOnly, staffOnly, systemRoleMemberGuard } from '@/middleware';
import { transformToHttpError, User } from '@/model/User';
import { UserSearchResult } from '@/response/user';
import { UserResponse } from '@/response/user';
import { getVerifiedPayloadWithSubRequired, processKeys, signPayload } from '@/utils/jwt';
import { withAsyncSpan } from '@/utils/trace';
import { Context } from 'koa';
Expand Down Expand Up @@ -71,7 +71,7 @@ const TDSUserSigningKey = process.env.TDS_USER_SIGNING_KEY;
export class UserController {
@Get()
@UseMiddlewares(auth, systemRoleMemberGuard)
@ResponseBody(UserSearchResult)
@ResponseBody(UserResponse)
find(
@Pagination() [page, pageSize]: [number, number],
@Query('id', ParseCsvPipe) ids: string[] | undefined,
Expand Down Expand Up @@ -102,14 +102,14 @@ export class UserController {

@Get('me')
@UseMiddlewares(auth)
@ResponseBody(UserSearchResult)
@ResponseBody(UserResponse)
getMe(@CurrentUser() currentUser: User) {
return currentUser;
}

@Get(':id')
@UseMiddlewares(auth, staffOnly)
@ResponseBody(UserSearchResult)
@ResponseBody(UserResponse)
findOne(@Param('id', new FindModelPipe(User)) user: User) {
return user;
}
Expand Down Expand Up @@ -173,7 +173,7 @@ export class UserController {

@Post('pre-create')
@UseMiddlewares(auth, customerServiceOnly)
@ResponseBody(UserSearchResult)
@ResponseBody(UserResponse)
async preCreate(@Body(new ZodValidationPipe(preCraeteSchema)) data: PreCreateUserData) {
const { email, username } = data;
if (!email && !username) {
Expand Down
8 changes: 0 additions & 8 deletions next/api/src/response/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ export class UserResponse {
nickname: this.user.name ?? this.user.username,
active: !this.user.inactive,
avatarUrl: GravatarUrlManager.getUrl(this.user.email ?? this.user.username),
};
}
}

export class UserSearchResult extends UserResponse {
toJSON() {
return {
...super.toJSON(),
email: this.user.email,
};
}
Expand Down
4 changes: 2 additions & 2 deletions next/api/src/ticket/export/ExportTicket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { debug as d } from 'debug';
import { sub, format as dateFnsFormat } from 'date-fns';
import { Category } from '@/model/Category';
import { User } from '@/model/User';
import { UserSearchResult } from '@/response/user';
import { UserResponse } from '@/response/user';
import { Group } from '@/model/Group';
import { GroupResponse } from '@/response/group';
import { Reply } from '@/model/Reply';
Expand Down Expand Up @@ -191,7 +191,7 @@ const getCategoryPath = async (category: Category) => {
const getCustomerServices = async () => {
const customerServices = await User.getCustomerServices();
return _(customerServices)
.map((user) => new UserSearchResult(user).toJSON())
.map((user) => new UserResponse(user).toJSON())
.keyBy('id')
.valueOf();
};
Expand Down
1 change: 1 addition & 0 deletions next/web/src/App/Admin/Settings/Collaborators/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export function Collaborators() {

<Table dataSource={data} rowKey="id" pagination={false} loading={isFetching}>
<Column key="id" title="协作者" render={(user) => <UserLabel user={user} />} />
<Table.Column key="email" title="邮箱" render={(user) => user.email || '-'} />
<Column
key="actions"
title="操作"
Expand Down
11 changes: 5 additions & 6 deletions next/web/src/App/Admin/Settings/Members/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,10 @@ interface CustomerService extends CustomerServiceSchema {
roles: CSRole[];
}

const appendRoles =
(roles: CSRole[]) =>
(user: CustomerServiceSchema): CustomerService => ({
...user,
roles: roles,
});
const appendRoles = (roles: CSRole[]) => (user: CustomerServiceSchema): CustomerService => ({
...user,
roles: roles,
});

export function Members() {
const customerServiceResult = useCustomerServices();
Expand Down Expand Up @@ -244,6 +242,7 @@ export function Members() {
title="客服"
render={(user) => <UserLabel user={user} />}
/>
<Table.Column key="email" title="邮箱" render={(user) => user.email || '-'} />
<Table.Column
dataIndex="roles"
title="角色"
Expand Down
11 changes: 4 additions & 7 deletions next/web/src/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ export interface UserSchema {
active: boolean;
nickname: string;
avatarUrl: string;
}

export interface UserSearchResult extends UserSchema {
email?: string;
}

Expand All @@ -21,7 +18,7 @@ interface FetchUserOptions {
q?: string;
}

async function fetchUsers({ id, q }: FetchUserOptions = {}): Promise<UserSearchResult[]> {
async function fetchUsers({ id, q }: FetchUserOptions = {}): Promise<UserSchema[]> {
const params: Record<string, string | undefined> = { q };
if (id) {
if (Array.isArray(id)) {
Expand All @@ -35,13 +32,13 @@ async function fetchUsers({ id, q }: FetchUserOptions = {}): Promise<UserSearchR
return data;
}

async function fetchUser(id: string): Promise<UserSearchResult> {
async function fetchUser(id: string): Promise<UserSchema> {
const { data } = await http.get(`/api/2/users/${id}`);
return data;
}

export interface UseUsersOptions extends FetchUserOptions {
queryOptions?: UseQueryOptions<UserSearchResult[], Error>;
queryOptions?: UseQueryOptions<UserSchema[], Error>;
}

export const useUsers = ({ queryOptions, ...options }: UseUsersOptions = {}) =>
Expand All @@ -51,7 +48,7 @@ export const useUsers = ({ queryOptions, ...options }: UseUsersOptions = {}) =>
...queryOptions,
});

export const useUser = (id: string, options?: UseQueryOptions<UserSearchResult, Error>) =>
export const useUser = (id: string, options?: UseQueryOptions<UserSchema, Error>) =>
useQuery({
queryKey: ['user', id],
queryFn: () => fetchUser(id),
Expand Down

0 comments on commit dbc3568

Please sign in to comment.