diff --git a/client/src/api/api.ts b/client/src/api/api.ts index 10d9cbad19..5600c339e8 100644 --- a/client/src/api/api.ts +++ b/client/src/api/api.ts @@ -487,91 +487,6 @@ export interface CommentMentorRegistryDto { */ 'comment': string | null; } -/** - * - * @export - * @interface ConfigurableProfilePermissions - */ -export interface ConfigurableProfilePermissions { - /** - * - * @type {PublicVisibilitySettings} - * @memberof ConfigurableProfilePermissions - */ - 'isProfileVisible'?: PublicVisibilitySettings; - /** - * - * @type {VisibilitySettings} - * @memberof ConfigurableProfilePermissions - */ - 'isAboutVisible'?: VisibilitySettings; - /** - * - * @type {VisibilitySettings} - * @memberof ConfigurableProfilePermissions - */ - 'isEducationVisible'?: VisibilitySettings; - /** - * - * @type {PartialStudentVisibilitySettings} - * @memberof ConfigurableProfilePermissions - */ - 'isEnglishVisible'?: PartialStudentVisibilitySettings; - /** - * - * @type {ContactsVisibilitySettings} - * @memberof ConfigurableProfilePermissions - */ - 'isEmailVisible'?: ContactsVisibilitySettings; - /** - * - * @type {ContactsVisibilitySettings} - * @memberof ConfigurableProfilePermissions - */ - 'isTelegramVisible'?: ContactsVisibilitySettings; - /** - * - * @type {ContactsVisibilitySettings} - * @memberof ConfigurableProfilePermissions - */ - 'isSkypeVisible'?: ContactsVisibilitySettings; - /** - * - * @type {ContactsVisibilitySettings} - * @memberof ConfigurableProfilePermissions - */ - 'isPhoneVisible'?: ContactsVisibilitySettings; - /** - * - * @type {ContactsVisibilitySettings} - * @memberof ConfigurableProfilePermissions - */ - 'isContactsNotesVisible'?: ContactsVisibilitySettings; - /** - * - * @type {VisibilitySettings} - * @memberof ConfigurableProfilePermissions - */ - 'isLinkedInVisible'?: VisibilitySettings; - /** - * - * @type {VisibilitySettings} - * @memberof ConfigurableProfilePermissions - */ - 'isPublicFeedbackVisible'?: VisibilitySettings; - /** - * - * @type {VisibilitySettings} - * @memberof ConfigurableProfilePermissions - */ - 'isMentorStatsVisible'?: VisibilitySettings; - /** - * - * @type {PartialStudentVisibilitySettings} - * @memberof ConfigurableProfilePermissions - */ - 'isStudentStatsVisible'?: PartialStudentVisibilitySettings; -} /** * * @export @@ -646,25 +561,6 @@ export interface ContactsDto { */ 'discord'?: string | null; } -/** - * - * @export - * @interface ContactsVisibilitySettings - */ -export interface ContactsVisibilitySettings { - /** - * - * @type {boolean} - * @memberof ContactsVisibilitySettings - */ - 'all': boolean; - /** - * - * @type {boolean} - * @memberof ContactsVisibilitySettings - */ - 'student': boolean; -} /** * * @export @@ -2998,49 +2894,6 @@ export const FormDataDtoMilitaryServiceEnum = { export type FormDataDtoMilitaryServiceEnum = typeof FormDataDtoMilitaryServiceEnum[keyof typeof FormDataDtoMilitaryServiceEnum]; -/** - * - * @export - * @interface GeneralInfo - */ -export interface GeneralInfo { - /** - * - * @type {string} - * @memberof GeneralInfo - */ - 'name': string; - /** - * - * @type {string} - * @memberof GeneralInfo - */ - 'githubId': string; - /** - * - * @type {string} - * @memberof GeneralInfo - */ - 'aboutMyself'?: string | null; - /** - * - * @type {Location} - * @memberof GeneralInfo - */ - 'location': Location; - /** - * - * @type {Array} - * @memberof GeneralInfo - */ - 'educationHistory'?: Array | null; - /** - * - * @type {string} - * @memberof GeneralInfo - */ - 'englishLevel'?: string | null; -} /** * * @export @@ -3364,25 +3217,6 @@ export interface LeaveCourseRequestDto { */ 'comment'?: string; } -/** - * - * @export - * @interface Location - */ -export interface Location { - /** - * - * @type {string} - * @memberof Location - */ - 'cityName'?: string | null; - /** - * - * @type {string} - * @memberof Location - */ - 'countryName'?: string | null; -} /** * * @export @@ -4029,25 +3863,6 @@ export interface PaginationMetaDto { */ 'totalPages': number; } -/** - * - * @export - * @interface PartialStudentVisibilitySettings - */ -export interface PartialStudentVisibilitySettings { - /** - * - * @type {boolean} - * @memberof PartialStudentVisibilitySettings - */ - 'all': boolean; - /** - * - * @type {boolean} - * @memberof PartialStudentVisibilitySettings - */ - 'student': boolean; -} /** * * @export @@ -4268,49 +4083,6 @@ export interface ProfileDto { */ 'publicCvUrl': string | null; } -/** - * - * @export - * @interface ProfileInfoDto - */ -export interface ProfileInfoDto { - /** - * - * @type {ConfigurableProfilePermissions} - * @memberof ProfileInfoDto - */ - 'permissionsSettings': ConfigurableProfilePermissions; - /** - * - * @type {GeneralInfo} - * @memberof ProfileInfoDto - */ - 'generalInfo': GeneralInfo; - /** - * - * @type {ContactsDto} - * @memberof ProfileInfoDto - */ - 'contacts': ContactsDto; - /** - * - * @type {Discord} - * @memberof ProfileInfoDto - */ - 'discord'?: Discord | null; - /** - * - * @type {boolean} - * @memberof ProfileInfoDto - */ - 'isPermissionsSettingsChanged': boolean; - /** - * - * @type {boolean} - * @memberof ProfileInfoDto - */ - 'isProfileSettingsChanged': boolean; -} /** * * @export @@ -4342,19 +4114,6 @@ export interface PromptDto { */ 'temperature': number; } -/** - * - * @export - * @interface PublicVisibilitySettings - */ -export interface PublicVisibilitySettings { - /** - * - * @type {boolean} - * @memberof PublicVisibilitySettings - */ - 'all': boolean; -} /** * * @export @@ -6929,31 +6688,6 @@ export interface VisibilityDto { */ 'isHidden': boolean; } -/** - * - * @export - * @interface VisibilitySettings - */ -export interface VisibilitySettings { - /** - * - * @type {boolean} - * @memberof VisibilitySettings - */ - 'all': boolean; - /** - * - * @type {boolean} - * @memberof VisibilitySettings - */ - 'mentor': boolean; - /** - * - * @type {boolean} - * @memberof VisibilitySettings - */ - 'student': boolean; -} /** * ActivityApi - axios parameter creator @@ -13966,41 +13700,6 @@ export const ProfileApiAxiosParamCreator = function (configuration?: Configurati options: localVarRequestOptions, }; }, - /** - * - * @param {ProfileInfoDto} profileInfoDto - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - updateProfileInfo: async (profileInfoDto: ProfileInfoDto, options: AxiosRequestConfig = {}): Promise => { - // verify required parameter 'profileInfoDto' is not null or undefined - assertParamExists('updateProfileInfo', 'profileInfoDto', profileInfoDto) - const localVarPath = `/profile/info`; - // 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: 'POST', ...baseOptions, ...options}; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - - - localVarHeaderParameter['Content-Type'] = 'application/json'; - - setSearchParams(localVarUrlObj, localVarQueryParameter); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(profileInfoDto, localVarRequestOptions, configuration) - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, /** * * @param {UpdateProfileInfoDto} updateProfileInfoDto @@ -14131,16 +13830,6 @@ export const ProfileApiFp = function(configuration?: Configuration) { const localVarAxiosArgs = await localVarAxiosParamCreator.obfuscateProfile(username, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, - /** - * - * @param {ProfileInfoDto} profileInfoDto - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async updateProfileInfo(profileInfoDto: ProfileInfoDto, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.updateProfileInfo(profileInfoDto, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, /** * * @param {UpdateProfileInfoDto} updateProfileInfoDto @@ -14216,15 +13905,6 @@ export const ProfileApiFactory = function (configuration?: Configuration, basePa obfuscateProfile(username: string, options?: any): AxiosPromise { return localVarFp.obfuscateProfile(username, options).then((request) => request(axios, basePath)); }, - /** - * - * @param {ProfileInfoDto} profileInfoDto - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - updateProfileInfo(profileInfoDto: ProfileInfoDto, options?: any): AxiosPromise { - return localVarFp.updateProfileInfo(profileInfoDto, options).then((request) => request(axios, basePath)); - }, /** * * @param {UpdateProfileInfoDto} updateProfileInfoDto @@ -14308,17 +13988,6 @@ export class ProfileApi extends BaseAPI { return ProfileApiFp(this.configuration).obfuscateProfile(username, options).then((request) => request(this.axios, this.basePath)); } - /** - * - * @param {ProfileInfoDto} profileInfoDto - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof ProfileApi - */ - public updateProfileInfo(profileInfoDto: ProfileInfoDto, options?: AxiosRequestConfig) { - return ProfileApiFp(this.configuration).updateProfileInfo(profileInfoDto, options).then((request) => request(this.axios, this.basePath)); - } - /** * * @param {UpdateProfileInfoDto} updateProfileInfoDto diff --git a/client/src/services/user.ts b/client/src/services/user.ts index ac23564afa..ef2e89ccf9 100644 --- a/client/src/services/user.ts +++ b/client/src/services/user.ts @@ -1,7 +1,7 @@ import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'; import { getApiConfiguration, getServerAxiosProps } from 'utils/axios'; import { EnglishLevel } from 'common/models'; -import { ProfileApi, ProfileDto, ProfileInfoDto, UsersNotificationsApi, UpdateUserDtoLanguagesEnum } from 'api'; +import { ProfileApi, ProfileDto, UsersNotificationsApi, UpdateUserDtoLanguagesEnum } from 'api'; import discordIntegration from '../configs/discord-integration'; import type { ConfigurableProfilePermissions, @@ -107,10 +107,6 @@ export class UserService { return response.data.data; } - async saveProfileInfo(profile: ProfileInfoDto) { - await this.profileApi.updateProfileInfo(profile); - } - async sendEmailConfirmationLink() { return this.usersApi.sendEmailConfirmationLink(); } diff --git a/nestjs/src/profile/profile.controller.ts b/nestjs/src/profile/profile.controller.ts index 96512b3605..ac831a2bdd 100644 --- a/nestjs/src/profile/profile.controller.ts +++ b/nestjs/src/profile/profile.controller.ts @@ -3,7 +3,7 @@ import { ApiBody, ApiOkResponse, ApiOperation, ApiResponse, ApiTags } from '@nes import { DefaultGuard, RequiredRoles, Role, RoleGuard } from 'src/auth'; import { CoursesService } from 'src/courses/courses.service'; import { CurrentRequest } from '../auth/auth.service'; -import { ProfileInfoDto, ProfileCourseDto, UpdateUserDto, UpdateProfileInfoDto } from './dto'; +import { ProfileCourseDto, UpdateUserDto, UpdateProfileInfoDto } from './dto'; import { ProfileDto } from './dto/profile.dto'; import { ProfileService } from './profile.service'; import { PersonalProfileDto } from './dto/personal-profile.dto'; @@ -48,17 +48,6 @@ export class ProfileController { await this.profileService.updateUser(user.id, dto); } - @Post('/info') - @ApiOperation({ operationId: 'updateProfileInfo' }) - @ApiBody({ type: ProfileInfoDto }) - public async updateProfileInfo(@Req() req: CurrentRequest, @Body() dto: ProfileInfoDto) { - const { - user: { id }, - } = req; - - await this.profileService.updateProfile(id, dto); - } - @Patch('/info') @ApiOperation({ operationId: 'updateProfileInfoFlat' }) @ApiBody({ type: UpdateProfileInfoDto }) diff --git a/nestjs/src/profile/profile.service.ts b/nestjs/src/profile/profile.service.ts index 725e39f127..600fdbd102 100644 --- a/nestjs/src/profile/profile.service.ts +++ b/nestjs/src/profile/profile.service.ts @@ -170,32 +170,44 @@ export class ProfileService { languages, } = profileInfo; + if (contactsEmail && !isEmail(contactsEmail)) { + throw new BadRequestException('Email is invalid.'); + } + if (contactsEpamEmail && !isEmail(contactsEpamEmail)) { + throw new BadRequestException('Epam email is invalid.'); + } + const [firstName, lastName] = name?.split(' ') ?? []; - const user = await this.userRepository.update( - { id: userId }, - omitBy>( - { - firstName, - lastName: firstName ? lastName ?? '' : undefined, - countryName, - cityName, - educationHistory, - discord, - englishLevel, - aboutMyself, - contactsTelegram, - contactsPhone, - contactsEmail, - contactsNotes, - contactsSkype, - contactsWhatsApp, - contactsLinkedIn, - contactsEpamEmail, - languages, - }, - isUndefined, - ), - ); + const user = await this.userRepository + .createQueryBuilder() + .update(User) + .set( + omitBy>( + { + firstName, + lastName: firstName ? lastName ?? '' : undefined, + countryName, + cityName, + educationHistory, + discord, + englishLevel, + aboutMyself, + contactsTelegram, + contactsPhone, + contactsEmail, + contactsNotes, + contactsSkype, + contactsWhatsApp, + contactsLinkedIn, + contactsEpamEmail, + languages, + }, + isUndefined, + ), + ) + .returning('*') + .where('id = :id', { id: userId }) + .execute(); await Promise.all([this.updateEmailChannel(userId, user), this.updateDiscordChannel(userId, user)]); } diff --git a/nestjs/src/spec.json b/nestjs/src/spec.json index d4c4b9ce06..ae29ea2c32 100644 --- a/nestjs/src/spec.json +++ b/nestjs/src/spec.json @@ -1584,17 +1584,6 @@ } }, "/profile/info": { - "post": { - "operationId": "updateProfileInfo", - "summary": "", - "parameters": [], - "requestBody": { - "required": true, - "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ProfileInfoDto" } } } - }, - "responses": { "201": { "description": "" } }, - "tags": ["profile"] - }, "patch": { "operationId": "updateProfileInfoFlat", "summary": "", @@ -3838,55 +3827,6 @@ } } }, - "PublicVisibilitySettings": { - "type": "object", - "properties": { "all": { "type": "boolean" } }, - "required": ["all"] - }, - "VisibilitySettings": { - "type": "object", - "properties": { - "all": { "type": "boolean" }, - "mentor": { "type": "boolean" }, - "student": { "type": "boolean" } - }, - "required": ["all", "mentor", "student"] - }, - "PartialStudentVisibilitySettings": { - "type": "object", - "properties": { "all": { "type": "boolean" }, "student": { "type": "boolean" } }, - "required": ["all", "student"] - }, - "ContactsVisibilitySettings": { - "type": "object", - "properties": { "all": { "type": "boolean" }, "student": { "type": "boolean" } }, - "required": ["all", "student"] - }, - "ConfigurableProfilePermissions": { - "type": "object", - "properties": { - "isProfileVisible": { "$ref": "#/components/schemas/PublicVisibilitySettings" }, - "isAboutVisible": { "$ref": "#/components/schemas/VisibilitySettings" }, - "isEducationVisible": { "$ref": "#/components/schemas/VisibilitySettings" }, - "isEnglishVisible": { "$ref": "#/components/schemas/PartialStudentVisibilitySettings" }, - "isEmailVisible": { "$ref": "#/components/schemas/ContactsVisibilitySettings" }, - "isTelegramVisible": { "$ref": "#/components/schemas/ContactsVisibilitySettings" }, - "isSkypeVisible": { "$ref": "#/components/schemas/ContactsVisibilitySettings" }, - "isPhoneVisible": { "$ref": "#/components/schemas/ContactsVisibilitySettings" }, - "isContactsNotesVisible": { "$ref": "#/components/schemas/ContactsVisibilitySettings" }, - "isLinkedInVisible": { "$ref": "#/components/schemas/VisibilitySettings" }, - "isPublicFeedbackVisible": { "$ref": "#/components/schemas/VisibilitySettings" }, - "isMentorStatsVisible": { "$ref": "#/components/schemas/VisibilitySettings" }, - "isStudentStatsVisible": { "$ref": "#/components/schemas/PartialStudentVisibilitySettings" } - } - }, - "Location": { - "type": "object", - "properties": { - "cityName": { "type": "string", "nullable": true }, - "countryName": { "type": "string", "nullable": true } - } - }, "Education": { "type": "object", "properties": { @@ -3896,40 +3836,6 @@ }, "required": ["university", "faculty", "graduationYear"] }, - "GeneralInfo": { - "type": "object", - "properties": { - "name": { "type": "string" }, - "githubId": { "type": "string" }, - "aboutMyself": { "type": "string", "nullable": true }, - "location": { "$ref": "#/components/schemas/Location" }, - "educationHistory": { - "nullable": true, - "type": "array", - "items": { "$ref": "#/components/schemas/Education" } - }, - "englishLevel": { "type": "string", "nullable": true } - }, - "required": ["name", "githubId", "location"] - }, - "ProfileInfoDto": { - "type": "object", - "properties": { - "permissionsSettings": { "$ref": "#/components/schemas/ConfigurableProfilePermissions" }, - "generalInfo": { "$ref": "#/components/schemas/GeneralInfo" }, - "contacts": { "$ref": "#/components/schemas/ContactsDto" }, - "discord": { "nullable": true, "allOf": [{ "$ref": "#/components/schemas/Discord" }] }, - "isPermissionsSettingsChanged": { "type": "boolean" }, - "isProfileSettingsChanged": { "type": "boolean" } - }, - "required": [ - "permissionsSettings", - "generalInfo", - "contacts", - "isPermissionsSettingsChanged", - "isProfileSettingsChanged" - ] - }, "UpdateProfileInfoDto": { "type": "object", "properties": {