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-
import { CreateDoctorUserCommand } from '../create-doctor-user/classes/create-doctor-user-command';
import { CreateDoctorUserResult } from '../create-doctor-user/classes/create-doctor-user-result';
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({
providedIn: 'root'
......@@ -67,5 +71,34 @@ export class DoctorUsersService {
}
// #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
}
\ No newline at end of file
......@@ -3,7 +3,7 @@ import { DoctorUsersService } from '../../../services/doctor-users.service';
import { DoctorUserResponse } from '../../classes/doctor-user-response';
import { ActivatedRoute } from '@angular/router';
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({
selector: 'app-update-doctor-user',
......@@ -24,11 +24,11 @@ export class UpdateDoctorUserComponent implements OnInit{
this.doctorUsersService.getDoctorUserById(this.doctorUserId)
.subscribe( doctorUser => {
this.doctorUser = doctorUser!;
this.editPersonalDataQuery = new UpdateDoctorPersonalDataQuery(
this.editPersonalDataQuery = new UpdateDoctorPersonalDataQuery(doctorUser!.id,
this.doctorUser.firstName, this.doctorUser.middleName,
this.doctorUser.lastName
);
this.editUserDataQuery = new updateDoctorUserQuery(doctorUser!.userName);
this.editUserDataQuery = new updateDoctorUserQuery(doctorUser!.id, doctorUser!.userName);
}
)
}
......
export class UpdateDoctorPersonalDataQuery {
public id: number;
public firstName: string;
public middleName: 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.middleName = middleName;
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';
import { ToastrService } from 'ngx-toastr';
import { NgForm } from '@angular/forms';
import { UpdateDoctorPersonalDataQuery } from '../../classes/update-doctor-personal-data-query';
import { Router } from '@angular/router';
@Component({
selector: 'app-update-doctor-personal-data-form',
......@@ -13,17 +14,18 @@ export class UpdateDoctorPersonalDataFormComponent {
//#region CTOR DI
constructor(private doctorUsersService: DoctorUsersService,
private toastrService: ToastrService
private toastrService: ToastrService,
private router: Router
) {}
//#endregion
// #region Inputs
@Input("formModel") formModel: UpdateDoctorPersonalDataQuery = new UpdateDoctorPersonalDataQuery('','','');
@Input("formModel") formModel: UpdateDoctorPersonalDataQuery = new UpdateDoctorPersonalDataQuery(1,'','','');
// #endregion
//#region Variables
@ViewChild("form") updateDoctorPseronalDataForm: NgForm;
@ViewChild("form") form: NgForm;
isFailure: boolean = false;
errorMessage: string;
......@@ -31,7 +33,25 @@ export class UpdateDoctorPersonalDataFormComponent {
// #region On submut
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
......
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 {
public id: number;
public userName: string;
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.password = password;
}
......
import { Component, Input } from '@angular/core';
import { updateDoctorUserQuery } from '../../classes/updateDoctorUserQuery';
import { Component, Input, ViewChild } from '@angular/core';
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({
selector: 'app-update-doctor-user-data-form',
......@@ -8,12 +12,39 @@ import { updateDoctorUserQuery } from '../../classes/updateDoctorUserQuery';
})
export class UpdateDoctorUserDataFormComponent {
// #region CTOR DI
constructor(private doctorUsersService: DoctorUsersService,
private toastrService: ToastrService,
private router: Router
) {}
// #endregion
@ViewChild('form') form: NgForm;
isFailure: boolean = false;
errorMessage: string;
@Input("formModel") formModel: updateDoctorUserQuery;
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