Commit 6949ca50 authored by Almouhannad's avatar Almouhannad

(F) complete update features

parent f89e1817
...@@ -7,6 +7,10 @@ import { GetAllDoctorUsersResponse } from '../list-doctor-users/classes/get-all- ...@@ -7,6 +7,10 @@ import { GetAllDoctorUsersResponse } from '../list-doctor-users/classes/get-all-
import { CreateDoctorUserCommand } from '../create-doctor-user/classes/create-doctor-user-command'; import { CreateDoctorUserCommand } from '../create-doctor-user/classes/create-doctor-user-command';
import { CreateDoctorUserResult } from '../create-doctor-user/classes/create-doctor-user-result'; import { CreateDoctorUserResult } from '../create-doctor-user/classes/create-doctor-user-result';
import { DoctorUserResponse } from '../update-doctor-user/classes/doctor-user-response'; import { DoctorUserResponse } from '../update-doctor-user/classes/doctor-user-response';
import { UpdateDoctorPersonalDataQuery } from '../update-doctor-user/update-doctor-personal-data/classes/update-doctor-personal-data-query';
import { UpdateDoctorPersonalDataResult } from '../update-doctor-user/update-doctor-personal-data/classes/update-doctor-personal-data-result';
import { updateDoctorUserQuery } from '../update-doctor-user/update-doctor-user-data/classes/update-doctor-user-query';
import { UpdateDoctorUserDataResult } from '../update-doctor-user/update-doctor-user-data/classes/update-doctor-user-data-result';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
...@@ -67,5 +71,34 @@ export class DoctorUsersService { ...@@ -67,5 +71,34 @@ export class DoctorUsersService {
} }
// #endregion // #endregion
// #region Update doctor peronsal info
updateDoctorPersonalInfo(query: UpdateDoctorPersonalDataQuery) : Observable<UpdateDoctorPersonalDataResult> {
return this.http.put(this.DOCTORUSERS_ENDPOINT, query)
.pipe(
map(_ => {
return new UpdateDoctorPersonalDataResult(true);
}),
catchError((error: HttpErrorResponse) => {
return of (new UpdateDoctorPersonalDataResult(false, error.error.detail))
})
)
}
// #endregion
// #region Update doctor user data
updateDoctorUserData(query: updateDoctorUserQuery): Observable<UpdateDoctorUserDataResult> {
return this.http.put(`${this.DOCTORUSERS_ENDPOINT}/Users`, query)
.pipe(
map (_ => {
return new UpdateDoctorUserDataResult(true);
}),
catchError((error: HttpErrorResponse) => {
return of (new UpdateDoctorUserDataResult(false, error.error.detail))
})
)
}
// #endregion
// #endregion // #endregion
} }
\ No newline at end of file
...@@ -3,7 +3,7 @@ import { DoctorUsersService } from '../../../services/doctor-users.service'; ...@@ -3,7 +3,7 @@ import { DoctorUsersService } from '../../../services/doctor-users.service';
import { DoctorUserResponse } from '../../classes/doctor-user-response'; import { DoctorUserResponse } from '../../classes/doctor-user-response';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { UpdateDoctorPersonalDataQuery } from '../../update-doctor-personal-data/classes/update-doctor-personal-data-query'; import { UpdateDoctorPersonalDataQuery } from '../../update-doctor-personal-data/classes/update-doctor-personal-data-query';
import { updateDoctorUserQuery } from '../../update-doctor-user-data/classes/updateDoctorUserQuery'; import { updateDoctorUserQuery } from '../../update-doctor-user-data/classes/update-doctor-user-query';
@Component({ @Component({
selector: 'app-update-doctor-user', selector: 'app-update-doctor-user',
...@@ -24,11 +24,11 @@ export class UpdateDoctorUserComponent implements OnInit{ ...@@ -24,11 +24,11 @@ export class UpdateDoctorUserComponent implements OnInit{
this.doctorUsersService.getDoctorUserById(this.doctorUserId) this.doctorUsersService.getDoctorUserById(this.doctorUserId)
.subscribe( doctorUser => { .subscribe( doctorUser => {
this.doctorUser = doctorUser!; this.doctorUser = doctorUser!;
this.editPersonalDataQuery = new UpdateDoctorPersonalDataQuery( this.editPersonalDataQuery = new UpdateDoctorPersonalDataQuery(doctorUser!.id,
this.doctorUser.firstName, this.doctorUser.middleName, this.doctorUser.firstName, this.doctorUser.middleName,
this.doctorUser.lastName this.doctorUser.lastName
); );
this.editUserDataQuery = new updateDoctorUserQuery(doctorUser!.userName); this.editUserDataQuery = new updateDoctorUserQuery(doctorUser!.id, doctorUser!.userName);
} }
) )
} }
......
export class UpdateDoctorPersonalDataQuery { export class UpdateDoctorPersonalDataQuery {
public id: number;
public firstName: string; public firstName: string;
public middleName: string; public middleName: string;
public lastName: string; public lastName: string;
constructor(firstName: string, middleName: string, lastName:string) { constructor(id: number, firstName: string, middleName: string, lastName:string) {
this.id = id;
this.firstName = firstName; this.firstName = firstName;
this.middleName = middleName; this.middleName = middleName;
this.lastName = lastName; this.lastName = lastName;
......
export class UpdateDoctorPersonalDataResult {
public status: boolean;
public errorMessage: string | null = null;
constructor (status: boolean, errorMessage: string | null = null)
{
this.status = status;
this.errorMessage = errorMessage;
}
}
\ No newline at end of file
...@@ -3,6 +3,7 @@ import { DoctorUsersService } from '../../../../services/doctor-users.service'; ...@@ -3,6 +3,7 @@ import { DoctorUsersService } from '../../../../services/doctor-users.service';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { NgForm } from '@angular/forms'; import { NgForm } from '@angular/forms';
import { UpdateDoctorPersonalDataQuery } from '../../classes/update-doctor-personal-data-query'; import { UpdateDoctorPersonalDataQuery } from '../../classes/update-doctor-personal-data-query';
import { Router } from '@angular/router';
@Component({ @Component({
selector: 'app-update-doctor-personal-data-form', selector: 'app-update-doctor-personal-data-form',
...@@ -13,17 +14,18 @@ export class UpdateDoctorPersonalDataFormComponent { ...@@ -13,17 +14,18 @@ export class UpdateDoctorPersonalDataFormComponent {
//#region CTOR DI //#region CTOR DI
constructor(private doctorUsersService: DoctorUsersService, constructor(private doctorUsersService: DoctorUsersService,
private toastrService: ToastrService private toastrService: ToastrService,
private router: Router
) {} ) {}
//#endregion //#endregion
// #region Inputs // #region Inputs
@Input("formModel") formModel: UpdateDoctorPersonalDataQuery = new UpdateDoctorPersonalDataQuery('','',''); @Input("formModel") formModel: UpdateDoctorPersonalDataQuery = new UpdateDoctorPersonalDataQuery(1,'','','');
// #endregion // #endregion
//#region Variables //#region Variables
@ViewChild("form") updateDoctorPseronalDataForm: NgForm; @ViewChild("form") form: NgForm;
isFailure: boolean = false; isFailure: boolean = false;
errorMessage: string; errorMessage: string;
...@@ -31,7 +33,25 @@ export class UpdateDoctorPersonalDataFormComponent { ...@@ -31,7 +33,25 @@ export class UpdateDoctorPersonalDataFormComponent {
// #region On submut // #region On submut
onSubmit(): void{ onSubmit(): void{
this.isFailure = false;
if(this.form.valid)
{
this.doctorUsersService.updateDoctorPersonalInfo(this.formModel)
.subscribe(
result => {
if (result.status === true)
{
this.toastrService.success('تم تعديل البيانات بنجاح');
this.router.navigateByUrl('admin/doctors');
}
else {
this.isFailure = true;
this.errorMessage = result.errorMessage!;
this.form.form.markAsPristine();
}
}
)
}
} }
// #endregion // #endregion
......
export class UpdateDoctorUserDataResult {
status: boolean;
errorMessage: string | null = null;
constructor(status: boolean, errorMessage: string | null = null) {
this.status = status;
this.errorMessage = errorMessage;
}
}
\ No newline at end of file
export class updateDoctorUserQuery { export class updateDoctorUserQuery {
public id: number;
public userName: string; public userName: string;
public password: string | null = null; public password: string | null = null;
constructor(userName: string, password: string | null = null) { constructor(id:number, userName: string, password: string | null = null) {
this.id = id;
this.userName = userName; this.userName = userName;
this.password = password; this.password = password;
} }
......
import { Component, Input } from '@angular/core'; import { Component, Input, ViewChild } from '@angular/core';
import { updateDoctorUserQuery } from '../../classes/updateDoctorUserQuery'; import { updateDoctorUserQuery } from '../../classes/update-doctor-user-query';
import { DoctorUsersService } from '../../../../services/doctor-users.service';
import { ToastrService } from 'ngx-toastr';
import { Router } from '@angular/router';
import { NgForm } from '@angular/forms';
@Component({ @Component({
selector: 'app-update-doctor-user-data-form', selector: 'app-update-doctor-user-data-form',
...@@ -8,12 +12,39 @@ import { updateDoctorUserQuery } from '../../classes/updateDoctorUserQuery'; ...@@ -8,12 +12,39 @@ import { updateDoctorUserQuery } from '../../classes/updateDoctorUserQuery';
}) })
export class UpdateDoctorUserDataFormComponent { export class UpdateDoctorUserDataFormComponent {
// #region CTOR DI
constructor(private doctorUsersService: DoctorUsersService,
private toastrService: ToastrService,
private router: Router
) {}
// #endregion
@ViewChild('form') form: NgForm;
isFailure: boolean = false; isFailure: boolean = false;
errorMessage: string; errorMessage: string;
@Input("formModel") formModel: updateDoctorUserQuery; @Input("formModel") formModel: updateDoctorUserQuery;
onSubmit(): void { onSubmit(): void {
if (this.form.valid)
{
this.isFailure = false;
this.doctorUsersService.updateDoctorUserData(this.formModel)
.subscribe(
result => {
if (result.status === true) {
this.toastrService.success('تم تحديث البيانات بنجاح');
this.router.navigateByUrl('admin/doctors');
}
else {
this.isFailure = true;
this.errorMessage = result.errorMessage!;
this.form.form.markAsPristine();
}
}
)
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment