Skip to content

Commit

Permalink
Merge pull request #2630 from ita-social-projects/tech-task/merge-end…
Browse files Browse the repository at this point in the history
…point-for-not-taken-out-reason

Tech task/merge endpoint for not taken out reason
  • Loading branch information
hnativlyubomyr authored Aug 18, 2023
2 parents 080ea8e + 8580034 commit 3fb3e7e
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
import { Router } from '@angular/router';
import { OrderService } from '../../services/order.service';
import { CancellationReasonList } from '../../services/cancellation-reason-list-mock';
import { CancellationReason } from 'src/app/ubs/ubs/order-status.enum';

@Component({
selector: 'app-add-order-cancellation-reason',
Expand All @@ -19,31 +21,9 @@ export class AddOrderCancellationReasonComponent implements OnInit {
public cancellationReason: string;
public cancellationComment: string;
public orderID: number;
orderInfo: any;
public isHistory: boolean;
reasonList: any[] = [
{
value: 'DELIVERED_HIMSELF',
translation: 'order-cancel.reason.delivered-himself'
},
{
value: 'MOVING_OUT',
translation: 'order-cancel.reason.moving-out'
},
{
value: 'OUT_OF_CITY',
translation: 'order-cancel.reason.out-of-city'
},
{
value: 'DISLIKED_SERVICE',
translation: 'order-cancel.reason.disliked-service'
},
{
value: 'OTHER',
translation: 'order-cancel.reason.other'
}
];
public adminName;
public reasonList = CancellationReasonList;
private destroySub: Subject<boolean> = new Subject<boolean>();

constructor(
Expand Down Expand Up @@ -90,13 +70,11 @@ export class AddOrderCancellationReasonComponent implements OnInit {
}

public disableButton(): boolean {
const isCancelReasonOther = this.cancellationReason === CancellationReason.OTHER;
const isFormUntouched = this.commentForm.untouched && !this.cancellationReason;
const isInvalidCommentForm = this.commentForm.invalid && this.commentForm.touched && this.cancellationReason === 'OTHER';
const isOtherCancellationReasonInvalid = this.cancellationReason === 'OTHER' && !this.commentForm.get('cancellationComment').value;
const isInvalidCommentForm = this.commentForm.invalid && this.commentForm.touched && isCancelReasonOther;
const isOtherCancellationReasonInvalid = isCancelReasonOther && !this.commentForm.get('cancellationComment').value;

if (isInvalidCommentForm || isOtherCancellationReasonInvalid || isFormUntouched) {
return true;
}
return false;
return isInvalidCommentForm || isOtherCancellationReasonInvalid || isFormUntouched;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { MAT_DIALOG_DATA, MatDialogRef, MatDialog } from '@angular/material/dial
import { LocalStorageService } from '@global-service/localstorage/local-storage.service';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { FileHandle } from '../../models/file-handle.model';
import { of, Subject } from 'rxjs';
import { switchMap, takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { OrderService } from '../../services/order.service';
import { ShowImgsPopUpComponent } from '../../../../shared/show-imgs-pop-up/show-imgs-pop-up.component';
import { NotTakenOutReasonImage } from '../../models/not-taken-out-reason.model';
Expand Down Expand Up @@ -121,29 +121,9 @@ export class AddOrderNotTakenOutReasonComponent implements OnInit, OnDestroy {
this.images = this.images.filter((image) => image !== imageToDelete);
}

prepareDataToSend(): FormData {
const notTakenOutReason = JSON.stringify(this.addNotTakenOutForm.value.notTakenOutReason);
const formData: FormData = new FormData();
formData.append('description', notTakenOutReason);
this.images.forEach((image) => {
if (image.file) {
formData.append('images', image.file);
}
});
return formData;
}

public send(): void {
this.isUploading = true;
const dataToSend = this.prepareDataToSend();
of(true)
.pipe(
switchMap(() => this.orderService.addReasonForNotTakenOutOrder(dataToSend, this.id)),
takeUntil(this.onDestroy$)
)
.subscribe(() => {
this.dialogRef.close(true);
});
this.dialogRef.close({ description: JSON.stringify(this.addNotTakenOutForm.value.notTakenOutReason), images: this.images });
}

public close(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { MatDialog } from '@angular/material/dialog';
import { AddOrderCancellationReasonComponent } from '../add-order-cancellation-reason/add-order-cancellation-reason.component';
import { AddOrderNotTakenOutReasonComponent } from '../add-order-not-taken-out-reason/add-order-not-taken-out-reason.component';
import { LanguageService } from 'src/app/main/i18n/language.service';
import { OrderStatus, PaymnetStatus } from 'src/app/ubs/ubs/order-status.enum';
import { OrderStatus, PaymnetStatus, CancellationReason } from 'src/app/ubs/ubs/order-status.enum';
import { OrderStatusEn, PaymentStatusEn } from 'src/app/ubs/ubs-user/ubs-user-orders-list/models/UserOrder.interface';

@Component({
selector: 'app-ubs-admin-order-status',
Expand All @@ -26,6 +27,7 @@ export class UbsAdminOrderStatusComponent implements OnChanges, OnInit, OnDestro
@Input() isEmployeeCanEditOrder: boolean;
@Output() changedOrderStatus = new EventEmitter<string>();
@Output() cancelReason = new EventEmitter<string>();
@Output() notTakenOutReason = new EventEmitter<FormData>();

constructor(public orderService: OrderService, private dialog: MatDialog, private langService: LanguageService) {}
private destroy$: Subject<boolean> = new Subject<boolean>();
Expand All @@ -48,7 +50,7 @@ export class UbsAdminOrderStatusComponent implements OnChanges, OnInit, OnDestro
}

if (changes.generalInfo) {
if (changes.generalInfo.currentValue.orderPaymentStatusNameEng === 'Unpaid') {
if (changes.generalInfo.currentValue.orderPaymentStatusNameEng === PaymentStatusEn.UNPAID) {
this.generalInfo.orderPaymentStatus = PaymnetStatus.UNPAID;
}
this.availableOrderStatuses = this.orderService.getAvailableOrderStatuses(
Expand Down Expand Up @@ -98,7 +100,7 @@ export class UbsAdminOrderStatusComponent implements OnChanges, OnInit, OnDestro
}
this.generalOrderInfo.get('cancellationReason').setValue(res.reason);
this.generalOrderInfo.get('cancellationReason').markAsDirty();
if (res.reason === 'OTHER') {
if (res.reason === CancellationReason.OTHER) {
this.generalOrderInfo.get('cancellationComment').setValue(res.comment);
this.generalOrderInfo.get('cancellationComment').markAsDirty();
}
Expand All @@ -117,25 +119,24 @@ export class UbsAdminOrderStatusComponent implements OnChanges, OnInit, OnDestro
.afterClosed()
.pipe(take(1))
.subscribe((res) => {
if (res.action === 'cancel') {
if (res) {
this.notTakenOutReason.emit(res);
} else {
this.onChangedOrderStatus(this.generalInfo.orderStatus);
this.generalOrderInfo.get('orderStatus').setValue(this.generalInfo.orderStatus);
return;
}
this.generalOrderInfo.get('notTakenOutReason').setValue(res.reason);
this.generalOrderInfo.get('notTakenOutReason').markAsDirty();
});
}

public setOrderPaymentStatus() {
let orderState: string;
this.generalInfo.orderStatusesDtos.find((status) => {
if (status.key === this.generalInfo.orderStatus) {
orderState = status.ableActualChange ? 'actual' : 'confirmed';
orderState = status.ableActualChange ? 'actual' : OrderStatusEn.CONFIRMED;
}
});

if (orderState === 'confirmed') {
if (orderState === OrderStatusEn.CONFIRMED) {
const confirmedPaidCondition1 =
this.currentOrderPrice > 0 && this.totalPaid > 0 && this.currentOrderPrice <= this.totalPaid && !this.unPaidAmount;
const confirmedPaidCondition2 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
[isEmployeeCanEditOrder]="isEmployeeCanEditOrder"
(changedOrderStatus)="onChangedOrderStatus($event)"
(cancelReason)="onCancelReason($event)"
(notTakenOutReason)="onNotTakenOutReason($event)"
>
</app-ubs-admin-order-status>
<app-ubs-admin-order-client-info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
IUpdateResponsibleEmployee,
IUserInfo,
ResponsibleEmployee,
abilityEditAuthorities
abilityEditAuthorities,
NotTakenOutReasonImages
} from '../../models/ubs-admin.interface';
import { IAppState } from 'src/app/store/state/app.state';
import { ChangingOrderData } from 'src/app/store/actions/bigOrderTable.actions';
Expand Down Expand Up @@ -78,6 +79,9 @@ export class UbsAdminOrderComponent implements OnInit, OnDestroy, AfterContentCh
public arrowIcon = 'assets/img/icon/arrows/arrow-left.svg';
private employeeAuthorities: string[];
public isEmployeeCanEditOrder = false;
notTakenOutReasonDescription: string;
notTakenOutReasonImages: NotTakenOutReasonImages[];

public permissions$ = this.store.select((state): Array<string> => state.employees?.employeesPermissions);
constructor(
private translate: TranslateService,
Expand Down Expand Up @@ -137,6 +141,11 @@ export class UbsAdminOrderComponent implements OnInit, OnDestroy, AfterContentCh
this.setOrderDetails();
}

onNotTakenOutReason(value: { description: string; images: NotTakenOutReasonImages[] }): void {
this.notTakenOutReasonDescription = value.description;
this.notTakenOutReasonImages = value.images;
}

public getOrderInfo(orderId: number, submitMode: boolean): void {
this.orderService
.getOrderInfo(orderId)
Expand Down Expand Up @@ -477,10 +486,14 @@ export class UbsAdminOrderComponent implements OnInit, OnDestroy, AfterContentCh
changedValues.responsiblePersonsForm = this.orderForm.get('responsiblePersonsForm').value;
}

if (this.notTakenOutReasonDescription) {
changedValues.notTakenOutReason = this.notTakenOutReasonDescription;
}

this.addIdForUserAndAdress(changedValues);

this.orderService
.updateOrderInfo(this.orderId, this.currentLanguage, changedValues)
.updateOrderInfo(this.orderId, this.currentLanguage, changedValues, this.notTakenOutReasonImages)
.pipe(takeUntil(this.destroy$))
.subscribe((response) => {
response.ok ? this.matSnackBar.snackType.changesSaved() : this.matSnackBar.snackType.error();
Expand Down
6 changes: 6 additions & 0 deletions src/app/ubs/ubs-admin/models/ubs-admin.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,9 @@ export interface EmployeePositionsAuthorities {
authorities: string[];
positionId: number[];
}

export interface NotTakenOutReasonImages {
name: string;
src: string;
file: File;
}
24 changes: 24 additions & 0 deletions src/app/ubs/ubs-admin/services/cancellation-reason-list-mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { CancellationReason } from '../../ubs/order-status.enum';

export const CancellationReasonList: any[] = [
{
value: CancellationReason.DELIVERED_HIMSELF,
translation: 'order-cancel.reason.delivered-himself'
},
{
value: CancellationReason.MOVING_OUT,
translation: 'order-cancel.reason.moving-out'
},
{
value: CancellationReason.OUT_OF_CITY,
translation: 'order-cancel.reason.out-of-city'
},
{
value: CancellationReason.DISLIKED_SERVICE,
translation: 'order-cancel.reason.disliked-service'
},
{
value: CancellationReason.OTHER,
translation: 'order-cancel.reason.other'
}
];
20 changes: 13 additions & 7 deletions src/app/ubs/ubs-admin/services/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
IPaymentInfoDto,
FormFieldsName,
ResponsibleEmployee,
INotTakenOutReason
INotTakenOutReason,
NotTakenOutReasonImages
} from '../models/ubs-admin.interface';
import { environment } from '@environment/environment';
import { IViolation } from '../models/violation.model';
Expand Down Expand Up @@ -97,8 +98,17 @@ export class OrderService {
return this.http.get(`${this.backend}/management/get-data-for-order/${orderId}`);
}

public updateOrderInfo(orderId: number, lang: string, data: {}) {
return this.http.patch(`${this.backend}/management/update-order-page-admin-info/${orderId}?lang=${lang}`, data, {
public updateOrderInfo(orderId: number, lang: string, data: {}, images?: NotTakenOutReasonImages[]) {
const formData: FormData = new FormData();
formData.append('updateOrderPageAdminDto', JSON.stringify(data));

if (images.length) {
images.forEach((img) => {
formData.append('images', img.src);
});
}

return this.http.patch(`${this.backend}/management/update-order-page-admin-info/${orderId}?language=${lang}`, formData, {
observe: 'response'
});
}
Expand Down Expand Up @@ -201,10 +211,6 @@ export class OrderService {
return this.http.post(`${this.backend}/management/addViolationToUser`, violation);
}

public addReasonForNotTakenOutOrder(reason, id) {
return this.http.put(`${this.backend}/management/save-reason/${id}`, reason);
}

public updateViolationOfCurrentOrder(violation) {
return this.http.put(`${this.backend}/management/updateViolationToUser`, violation);
}
Expand Down
8 changes: 8 additions & 0 deletions src/app/ubs/ubs/order-status.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ export enum PaymnetStatus {
HALF_PAID = 'HALF_PAID',
UNPAID = 'UNPAID'
}

export enum CancellationReason {
DELIVERED_HIMSELF = 'DELIVERED_HIMSELF',
MOVING_OUT = 'MOVING_OUT',
OUT_OF_CITY = 'OUT_OF_CITY',
DISLIKED_SERVICE = 'DISLIKED_SERVICE',
OTHER = 'OTHER'
}

0 comments on commit 3fb3e7e

Please sign in to comment.