mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
Merge branch 'feature/189-Warenausgabe/957-Show-Error-On-Edit-Page-Submit-Failure' into feature/189-Warenausgabe/main
This commit is contained in:
9
apps/sales/src/app/core/models/action-result.model.ts
Normal file
9
apps/sales/src/app/core/models/action-result.model.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface ActionResult<T> {
|
||||
error?: boolean;
|
||||
errorReasons?: { [key: string]: string };
|
||||
http?: {
|
||||
code: number;
|
||||
};
|
||||
message?: string;
|
||||
result?: T;
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
ChangeDetectorRef,
|
||||
} from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable, from } from 'rxjs';
|
||||
import { Observable } from 'rxjs';
|
||||
import {
|
||||
filter,
|
||||
map,
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { ShelfNavigationService } from '../../shared/services';
|
||||
import { OrderItemProcessingStatusValue } from '@swagger/oms/lib';
|
||||
import { ErrorService } from 'apps/sales/src/app/core/error/component/error.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-shelf-edit-compartment',
|
||||
@@ -49,6 +50,7 @@ export class ShelfEditCompartmentComponent implements OnInit {
|
||||
private activatedRoute: ActivatedRoute,
|
||||
protected formService: ShelfEditFormService,
|
||||
private shelfNavigationService: ShelfNavigationService,
|
||||
private errorService: ErrorService,
|
||||
private cdr: ChangeDetectorRef
|
||||
) {}
|
||||
|
||||
@@ -99,8 +101,12 @@ export class ShelfEditCompartmentComponent implements OnInit {
|
||||
processingStatus
|
||||
);
|
||||
|
||||
let newValues;
|
||||
if (submitResult) {
|
||||
let newValues: {
|
||||
orderNumber?: string;
|
||||
compartmentCode?: string;
|
||||
processingStatus?: number;
|
||||
};
|
||||
if (submitResult.result) {
|
||||
newValues = {
|
||||
compartmentCode:
|
||||
this.form.get('compartmentCode').value || compartmentCode,
|
||||
@@ -113,6 +119,14 @@ export class ShelfEditCompartmentComponent implements OnInit {
|
||||
processingStatus,
|
||||
});
|
||||
}
|
||||
|
||||
if (!submitResult.result) {
|
||||
this.showSubmitError({
|
||||
message: submitResult.message,
|
||||
code: submitResult.http ? submitResult.http.code : 500,
|
||||
invalidProperties: submitResult.errorReasons,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onAbortEdit() {
|
||||
@@ -138,4 +152,15 @@ export class ShelfEditCompartmentComponent implements OnInit {
|
||||
this.customerName = this.formService.getCustomerName(compartmentCode);
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
|
||||
private showSubmitError(error: {
|
||||
message: string;
|
||||
code: number;
|
||||
invalidProperties: { [key: string]: string };
|
||||
}) {
|
||||
const invalidProperties =
|
||||
Object.values(error.invalidProperties).join(', ') || undefined;
|
||||
|
||||
this.errorService.addErrors(error.code, error.message, invalidProperties);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
ProcessingStatusPipe,
|
||||
PickUpDateOptionsToDisplayValuesPipe,
|
||||
} from '../../pipes';
|
||||
import { ErrorService } from 'apps/sales/src/app/core/error/component/error.service';
|
||||
@Component({
|
||||
selector: 'app-shelf-edit-order',
|
||||
templateUrl: './shelf-edit-order.component.html',
|
||||
@@ -47,6 +48,7 @@ export class ShelfEditOrderComponent implements OnInit {
|
||||
private activatedRoute: ActivatedRoute,
|
||||
protected formService: ShelfEditFormService,
|
||||
private shelfNavigationService: ShelfNavigationService,
|
||||
private errorService: ErrorService,
|
||||
private cdr: ChangeDetectorRef
|
||||
) {}
|
||||
|
||||
@@ -97,13 +99,21 @@ export class ShelfEditOrderComponent implements OnInit {
|
||||
processingStatus
|
||||
);
|
||||
|
||||
if (submitResult) {
|
||||
if (submitResult.result) {
|
||||
this.shelfNavigationService.navigateBackToDetails({
|
||||
orderNumber,
|
||||
processingStatus:
|
||||
this.form.get('processingStatus').value || processingStatus,
|
||||
});
|
||||
}
|
||||
|
||||
if (!submitResult.result) {
|
||||
this.showSubmitError({
|
||||
message: submitResult.message,
|
||||
code: submitResult.http ? submitResult.http.code : 500,
|
||||
invalidProperties: submitResult.errorReasons,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onAbortEdit() {
|
||||
@@ -126,10 +136,20 @@ export class ShelfEditOrderComponent implements OnInit {
|
||||
orderNumber,
|
||||
processingStatus
|
||||
);
|
||||
console.log({ form: this.form });
|
||||
|
||||
this.items = this.formService.getItemsForm(orderNumber);
|
||||
this.customerName = this.formService.getCustomerName(orderNumber);
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
|
||||
private showSubmitError(error: {
|
||||
message: string;
|
||||
code: number;
|
||||
invalidProperties: { [key: string]: string };
|
||||
}) {
|
||||
const invalidProperties =
|
||||
Object.values(error.invalidProperties).join(', ') || undefined;
|
||||
|
||||
this.errorService.addErrors(error.code, error.message, invalidProperties);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable, ɵbypassSanitizationTrustResourceUrl } from '@angular/core';
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
FormBuilder,
|
||||
FormGroup,
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
FormArray,
|
||||
AbstractControl,
|
||||
} from '@angular/forms';
|
||||
import { Observable, of, from } from 'rxjs';
|
||||
import { Observable } from 'rxjs';
|
||||
import {
|
||||
OrderItemListItemDTO,
|
||||
VATDTO,
|
||||
@@ -26,6 +26,7 @@ import { ProcessingStatusNameMap } from '../constants';
|
||||
import { Select } from '@ngxs/store';
|
||||
import { VatState } from '../../../core/store/state/vat.state';
|
||||
import { toDecimalPlaces } from '../../../core/utils/price.util';
|
||||
import { ActionResult } from '../../../core/models/action-result.model';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ShelfEditFormService {
|
||||
@@ -307,11 +308,9 @@ export class ShelfEditFormService {
|
||||
async submit(
|
||||
form: FormGroup,
|
||||
processingStatus: OrderItemProcessingStatusValue
|
||||
): Promise<boolean> {
|
||||
): Promise<ActionResult<boolean>> {
|
||||
const formData = this.getDataFromGeneralForm(form);
|
||||
|
||||
console.log({ formData });
|
||||
|
||||
const orderItemsToPatch = this.prepareOrderItems(form);
|
||||
const orderItemSubsetsToPatch = this.prepareOrderItemSubsets(form);
|
||||
|
||||
@@ -338,10 +337,21 @@ export class ShelfEditFormService {
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('%cSubmit Error: ', 'color: red; font-weight: bold', error);
|
||||
return false;
|
||||
return {
|
||||
error: true,
|
||||
errorReasons: error.invalidProperties || {},
|
||||
http: {
|
||||
code: error.status || 500,
|
||||
},
|
||||
message: 'Speichern fehlgeschlagen',
|
||||
result: false,
|
||||
};
|
||||
}
|
||||
|
||||
return true;
|
||||
return {
|
||||
error: false,
|
||||
result: true,
|
||||
};
|
||||
}
|
||||
|
||||
private prepareOrderItems(form: FormGroup) {
|
||||
@@ -371,12 +381,13 @@ export class ShelfEditFormService {
|
||||
) as FormArray).controls.map((control) =>
|
||||
this.getOrderItemSubsetFromItemForm(control, form)
|
||||
);
|
||||
const { pickUpDeadline } = this.getDataFromGeneralForm(form);
|
||||
|
||||
return subsetItems.map((item) => ({
|
||||
orderId: form.get('orderId').value,
|
||||
orderItemId: item.orderItemId,
|
||||
orderItemSubsetId: item.id,
|
||||
orderItemSubset: { ...item },
|
||||
orderItemSubset: { ...item, compartmentStop: pickUpDeadline },
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user