Skip to content

Commit

Permalink
Update data center
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Dębowski committed Dec 2, 2024
1 parent e570a1b commit 1aea309
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/hiPower.Core/DataCenterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task<ErrorOr<DataCenter>> UpdateAsync (string id, DataCenter dataCe
var result = unit.DataCenterRepository
.Update(dataCenter.Adapt<ServerLocation>())
.ToErrorOr();

await unit.SaveAsync ();
return await Task.FromResult(result.Adapt<DataCenter> ());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
formControlName="description"
placeholder="description"
#description></textarea>
<mat-hint>{{ description.value.length}} / 250</mat-hint>
<mat-hint align="end">{{ description.value.length}} / 250</mat-hint>
</mat-form-field>
</form>
</mat-card-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class CreateNewComponent {
save$.subscribe({
complete: () => {
this.loadinService.loadingOff();
this.router.navigate(['..']);
this.router.navigate(['dashboard/datacenters']);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
formControlName="description"
placeholder="description"
#description></textarea>
<mat-hint>{{ description.value.length}} / 250</mat-hint>
<mat-hint align="end">{{ description.value.length}} / 250</mat-hint>
</mat-form-field>
</form>
</mat-card-content>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute, ActivatedRouteSnapshot } from '@angular/router';
import { ActivatedRoute, ActivatedRouteSnapshot, Router } from '@angular/router';
import { DataCenterService } from '../services/data-center.service';
import { DataCenter } from '../core/models/data-center';

@Component({
selector: 'app-edit-data-center',
Expand Down Expand Up @@ -38,6 +40,8 @@ export class EditDataCenterComponent implements OnInit {

constructor(private fb: FormBuilder,
private route: ActivatedRoute,
private dataCenterService: DataCenterService,
private router: Router
) {}

ngOnInit(): void {
Expand All @@ -46,6 +50,16 @@ export class EditDataCenterComponent implements OnInit {
}

onSubmit(): void {
if (this.form.valid) {
const data = this.form.value as Partial<DataCenter>;
const save$ = this.dataCenterService
.updateDataCenter(data.id!, data);

save$.subscribe({
complete: ()=> {
this.router.navigate(['dashboard/datacenters']);
}
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@ export class DataCenterService extends DataService {
map(x => x as DataCenter)
);
}

updateDataCenter(id: string, dataCenter: Partial<DataCenter>): Observable<DataCenter> {
return this.update<DataCenter>(`${this.apiUrl}/${id}`, dataCenter)
.pipe(
map(x => x as DataCenter)
);
}
}

0 comments on commit 1aea309

Please sign in to comment.