@@ -142,52 +142,86 @@ export class ProfileEditInfoService {
142142 : [ ] ,
143143 } ) ) ;
144144
145- const newProfile = {
146- ...this . profileForm . value ,
147- achievements,
148- [ this . userTypeMap [ this . profileForm . value . userType ] ] : this . typeSpecific . value ,
149- typeSpecific : undefined ,
150- birthday : this . profileForm . value . birthday
151- ? dayjs ( this . profileForm . value . birthday , "DD.MM.YYYY" ) . format ( "YYYY-MM-DD" )
152- : undefined ,
153- skillsIds : this . profileForm . value . skills . map ( ( s : Skill ) => s . id ) ,
154- phoneNumber :
145+ // Построение объекта профиля с только необходимыми полями
146+ const newProfile : any = {
147+ id : this . profileId ( ) ,
148+ first_name : this . profileForm . value . firstName ,
149+ last_name : this . profileForm . value . lastName ,
150+ email : this . profileForm . value . email ,
151+ user_type : this . profileForm . value . userType ,
152+ city : this . profileForm . value . city ,
153+ about_me : this . profileForm . value . aboutMe || "" ,
154+ avatar : this . profileForm . value . avatar || null ,
155+ cover_image_address : this . profileForm . value . coverImageAddress || null ,
156+ phone_number :
155157 typeof this . profileForm . value . phoneNumber === "string"
156158 ? this . profileForm . value . phoneNumber . replace ( / ^ ( [ 8 7 ] ) / , "+7" )
157159 : this . profileForm . value . phoneNumber ,
160+ speciality : this . profileForm . value . speciality ,
161+ skills_ids : this . profileForm . value . skills ?. map ( ( s : Skill ) => s . id ) || [ ] ,
158162 } ;
159163
164+ // Добавляем birthday если он указан
165+ if ( this . profileForm . value . birthday ) {
166+ newProfile . birthday = dayjs ( this . profileForm . value . birthday , "DD.MM.YYYY" ) . format (
167+ "YYYY-MM-DD"
168+ ) ;
169+ }
170+
171+ // Добавляем специфичные для типа пользователя поля
172+ if ( this . userTypeMap [ this . profileForm . value . userType ] ) {
173+ newProfile [ this . userTypeMap [ this . profileForm . value . userType ] ] = this . typeSpecific . value ;
174+ }
175+
176+ // Добавляем связанные данные если они были отредактированы
177+ if ( this . achievements . length > 0 ) {
178+ newProfile . achievements = achievements ;
179+ }
180+ if ( this . profileForm . value . education ?. length > 0 ) {
181+ newProfile . education = this . profileForm . value . education ;
182+ }
183+ if ( this . profileForm . value . workExperience ?. length > 0 ) {
184+ newProfile . work_experience = this . profileForm . value . workExperience ;
185+ }
186+ if ( this . profileForm . value . userLanguages ?. length > 0 ) {
187+ newProfile . user_languages = this . profileForm . value . userLanguages ;
188+ }
189+
190+ console . log ( "Saving profile:" , newProfile ) ;
191+
160192 this . authRepository
161193 . updateProfile ( newProfile )
162194 . pipe (
163195 concatMap ( ( ) => this . authRepository . fetchProfile ( ) ) ,
164196 takeUntil ( this . destroy$ )
165197 )
166198 . subscribe ( {
167- next : ( ) => {
199+ next : profile => {
168200 this . profileFormSubmitting$ . set ( success ( undefined ) ) ;
169- this . navigationService . profileRedirect ( this . profileId ( ) ) ;
201+ this . navigationService . profileRedirect ( profile . id ) ;
170202 } ,
171203 error : error => {
172204 this . profileFormSubmitting$ . set ( failure ( "profile_edit_error" ) ) ;
173205 this . isModalErrorSkillsChoose . set ( true ) ;
174- if ( error . error . phone_number ) {
206+ if ( error . error ? .phone_number ) {
175207 this . isModalErrorSkillChooseText . set ( error . error . phone_number [ 0 ] ) ;
176- } else if ( error . error . language ) {
208+ } else if ( error . error ? .language ) {
177209 this . isModalErrorSkillChooseText . set ( error . error . language ) ;
178- } else if ( error . error . achievements ) {
210+ } else if ( error . error ? .achievements ) {
179211 this . isModalErrorSkillChooseText . set ( error . error . achievements [ 0 ] ) ;
180- } else if ( error . error . work_experience ?. [ 2 ] ) {
212+ } else if ( error . error ? .work_experience ?. [ 2 ] ) {
181213 const errorText = error . error . work_experience [ 2 ] . entry_year
182214 ? error . error . work_experience [ 2 ] . entry_year
183215 : error . error . work_experience [ 2 ] . completion_year ;
184216 this . isModalErrorSkillChooseText . set ( errorText ) ;
185- } else if ( error . error . first_name ?. [ 0 ] ) {
217+ } else if ( error . error ? .first_name ?. [ 0 ] ) {
186218 this . isModalErrorSkillChooseText . set ( error . error . first_name ?. [ 0 ] ) ;
187- } else if ( error . error . last_name ?. [ 0 ] ) {
219+ } else if ( error . error ? .last_name ?. [ 0 ] ) {
188220 this . isModalErrorSkillChooseText . set ( error . error . last_name ?. [ 0 ] ) ;
189- } else {
221+ } else if ( error . error ?. [ 0 ] ) {
190222 this . isModalErrorSkillChooseText . set ( error . error [ 0 ] ) ;
223+ } else {
224+ this . isModalErrorSkillChooseText . set ( "Ошибка при сохранении профиля" ) ;
191225 }
192226 } ,
193227 } ) ;
0 commit comments