Skip to content

Commit

Permalink
feat: extend user search with information about being student or mentor
Browse files Browse the repository at this point in the history
  • Loading branch information
apalchys committed Dec 11, 2024
1 parent 08945ea commit feda30b
Show file tree
Hide file tree
Showing 9 changed files with 425 additions and 19 deletions.
202 changes: 202 additions & 0 deletions client/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,25 @@ export interface CourseMentorsStatsDto {
*/
'epamMentorsCount': number;
}
/**
*
* @export
* @interface CourseRecord
*/
export interface CourseRecord {
/**
*
* @type {string}
* @memberof CourseRecord
*/
'courseName': string;
/**
*
* @type {number}
* @memberof CourseRecord
*/
'id': number;
}
/**
*
* @export
Expand Down Expand Up @@ -7374,6 +7393,85 @@ export interface UserNotificationsDto {
*/
'connections': object;
}
/**
*
* @export
* @interface UserSearchDto
*/
export interface UserSearchDto {
/**
*
* @type {number}
* @memberof UserSearchDto
*/
'id': number;
/**
*
* @type {string}
* @memberof UserSearchDto
*/
'githubId': string;
/**
*
* @type {string}
* @memberof UserSearchDto
*/
'name': string;
/**
*
* @type {string}
* @memberof UserSearchDto
*/
'cityName': string | null;
/**
*
* @type {string}
* @memberof UserSearchDto
*/
'countryName': string | null;
/**
*
* @type {string}
* @memberof UserSearchDto
*/
'contactsEmail': string | null;
/**
*
* @type {string}
* @memberof UserSearchDto
*/
'contactsEpamEmail': string | null;
/**
*
* @type {string}
* @memberof UserSearchDto
*/
'primaryEmail': string | null;
/**
*
* @type {string}
* @memberof UserSearchDto
*/
'contactsDiscord': string | null;
/**
*
* @type {string}
* @memberof UserSearchDto
*/
'contactsTelegram': string | null;
/**
*
* @type {Array<CourseRecord>}
* @memberof UserSearchDto
*/
'mentors': Array<CourseRecord> | null;
/**
*
* @type {Array<CourseRecord>}
* @memberof UserSearchDto
*/
'students': Array<CourseRecord> | null;
}
/**
*
* @export
Expand Down Expand Up @@ -19605,6 +19703,110 @@ export class UserGroupApi extends BaseAPI {
}


/**
* UsersApi - axios parameter creator
* @export
*/
export const UsersApiAxiosParamCreator = function (configuration?: Configuration) {
return {
/**
*
* @param {string} query
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
searchUsers: async (query: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'query' is not null or undefined
assertParamExists('searchUsers', 'query', query)
const localVarPath = `/users/search`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

if (query !== undefined) {
localVarQueryParameter['query'] = query;
}



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
}
};

/**
* UsersApi - functional programming interface
* @export
*/
export const UsersApiFp = function(configuration?: Configuration) {
const localVarAxiosParamCreator = UsersApiAxiosParamCreator(configuration)
return {
/**
*
* @param {string} query
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async searchUsers(query: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<UserSearchDto>>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.searchUsers(query, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
}
};

/**
* UsersApi - factory interface
* @export
*/
export const UsersApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
const localVarFp = UsersApiFp(configuration)
return {
/**
*
* @param {string} query
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
searchUsers(query: string, options?: any): AxiosPromise<Array<UserSearchDto>> {
return localVarFp.searchUsers(query, options).then((request) => request(axios, basePath));
},
};
};

/**
* UsersApi - object-oriented interface
* @export
* @class UsersApi
* @extends {BaseAPI}
*/
export class UsersApi extends BaseAPI {
/**
*
* @param {string} query
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof UsersApi
*/
public searchUsers(query: string, options?: AxiosRequestConfig) {
return UsersApiFp(this.configuration).searchUsers(query, options).then((request) => request(this.axios, this.basePath));
}
}


/**
* UsersNotificationsApi - axios parameter creator
* @export
Expand Down
46 changes: 31 additions & 15 deletions client/src/pages/admin/users.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { useState, useMemo } from 'react';
import { useState } from 'react';
import { Button, Col, Input, List, Row, Layout, Form } from 'antd';
import { GithubAvatar } from 'components/GithubAvatar';
import { UserService, UserFull } from 'services/user';
import { AdminPageLayout } from 'components/PageLayout';
import { CourseRole } from 'services/models';
import { ActiveCourseProvider, SessionProvider, useActiveCourseContext } from 'modules/Course/contexts';
import { UsersApi, UserSearchDto } from 'api';

const { Content } = Layout;

const userApi = new UsersApi();

function Page() {
const { courses } = useActiveCourseContext();
const [users, setUsers] = useState(null as any[] | null);
const userService = useMemo(() => new UserService(), []);
const [users, setUsers] = useState(null as UserSearchDto[] | null);

const handleSearch = async (values: any) => {
if (!values.searchText) {
return;
}
const users = await userService.extendedUserSearch(values.searchText);
setUsers(users);
const users = await userApi.searchUsers(values.searchText);
setUsers(users.data);
};

return (
Expand Down Expand Up @@ -48,20 +49,22 @@ function Page() {
rowKey="id"
locale={{ emptyText: 'No results' }}
dataSource={users}
renderItem={(user: UserFull) => (
renderItem={user => (
<List.Item>
<List.Item.Meta
avatar={<GithubAvatar size={48} githubId={user.githubId} />}
title={<a href={`/profile?githubId=${user.githubId}`}>{user.githubId}</a>}
description={
<div>
<div>{user.name}</div>
<div>{`Primary email: ${user.primaryEmail || ''}`}</div>
<div>{`EPAM email: ${user.contactsEpamEmail || ''}`}</div>
<div>{`Skype: ${user.contactsSkype || ''}`}</div>
<div>{`Telegram: ${user.contactsTelegram || ''}`}</div>
<div>{`Discord: ${user.discord || ''}`}</div>
</div>
<>
<UserField value={user.name} />
<UserField label="Primary Email" value={user.primaryEmail} />
<UserField label="Contacts Email" value={user.contactsEmail} />
<UserField label="Contacts EPAM Email" value={user.contactsEpamEmail} />
<UserField label="Contacts Telegram" value={user.contactsTelegram} />
<UserField label="Contacts Discord" value={user.contactsDiscord} />
<UserField label="Mentor" value={user.mentors?.map(({ courseName }) => courseName)} />
<UserField label="Student" value={user.students?.map(({ courseName }) => courseName)} />
</>
}
/>
</List.Item>
Expand All @@ -76,6 +79,19 @@ function Page() {
);
}

function UserField({ label, value }: { label?: string; value: string | string[] | null | undefined }) {
const valueStr = Array.isArray(value) ? value.join(', ') : value;
if (!valueStr) {
return null;
}
return (
<div>
{label ? <span>{label}: </span> : null}
<span>{valueStr}</span>
</div>
);
}

export default function () {
return (
<ActiveCourseProvider>
Expand Down
5 changes: 2 additions & 3 deletions nestjs/src/courses/interviews/interviews.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class InterviewsService {
readonly taskInterviewStudentRepository: Repository<TaskInterviewStudent>,
@InjectRepository(Student)
readonly studentRepository: Repository<Student>,
readonly userService: UsersService,
) {}

public getAll(
Expand Down Expand Up @@ -84,7 +83,7 @@ export class InterviewsService {

return records.map(record => ({
id: record.student.id,
name: this.userService.getFullName(record.student.user),
name: UsersService.getFullName(record.student.user),
githubId: record.student.user.githubId,
cityName: record.student.user.cityName,
countryName: record.student.user.countryName,
Expand Down Expand Up @@ -143,7 +142,7 @@ export class InterviewsService {
id,
totalScore,
githubId: user.githubId,
name: this.userService.getFullName(student.user),
name: UsersService.getFullName(student.user),
cityName: user.cityName,
countryName: user.countryName,
isGoodCandidate: this.isGoodCandidate(stageInterviews),
Expand Down
Loading

0 comments on commit feda30b

Please sign in to comment.