diff --git a/packages/admin-web-angular/src/app/pages/+carriers/+carrier/carrier-orders-status/carrier-orders-status.component.ts b/packages/admin-web-angular/src/app/pages/+carriers/+carrier/carrier-orders-status/carrier-orders-status.component.ts index 6fc13dbe3..0fa8783a8 100644 --- a/packages/admin-web-angular/src/app/pages/+carriers/+carrier/carrier-orders-status/carrier-orders-status.component.ts +++ b/packages/admin-web-angular/src/app/pages/+carriers/+carrier/carrier-orders-status/carrier-orders-status.component.ts @@ -11,6 +11,9 @@ import { CarrierOrdersRouter } from '@modules/client.common.angular2/routers/car import OrderCarrierStatus from '@modules/server.common/enums/OrderCarrierStatus'; import _ from 'lodash'; import { OrderRouter } from '@modules/client.common.angular2/routers/order-router.service'; +import Warehouse from '@modules/server.common/entities/Warehouse'; +import { WarehouseRouter } from '@modules/client.common.angular2/routers/warehouse-router.service'; +import { first } from 'rxjs/operators'; @Component({ selector: 'ea-carrier-orders-status', @@ -39,7 +42,8 @@ export class CarrierOrdersStatusComponent implements OnDestroy { constructor( private carrierOrdersRouter: CarrierOrdersRouter, - private orderRouter: OrderRouter + private orderRouter: OrderRouter, + public warehouseRouter: WarehouseRouter ) { this.enumOrderCarrierStatus = OrderCarrierStatus; } @@ -54,6 +58,14 @@ export class CarrierOrdersStatusComponent implements OnDestroy { } async selectOrdersForDelivery() { + const warehouse: Warehouse = await this.warehouseRouter + .get(this.selectedOrder.warehouse['id']) + .pipe(first()) + .toPromise(); + + warehouse.usedCarriersIds.push(this.selectedCarrier.id); + this.warehouseRouter.save(warehouse); + this.pageBtnStates.isSelectOrdersForDeliveryAvailable = false; this.selectedOrder.carrierStatus = this.enumOrderCarrierStatus.CarrierSelectedOrder; diff --git a/packages/admin-web-angular/src/app/pages/+warehouses/+warehouse/+warehouse-manage/warehouse-manage.component.ts b/packages/admin-web-angular/src/app/pages/+warehouses/+warehouse/+warehouse-manage/warehouse-manage.component.ts index d12c604e6..1a0454c9b 100644 --- a/packages/admin-web-angular/src/app/pages/+warehouses/+warehouse/+warehouse-manage/warehouse-manage.component.ts +++ b/packages/admin-web-angular/src/app/pages/+warehouses/+warehouse/+warehouse-manage/warehouse-manage.component.ts @@ -72,6 +72,7 @@ export class WarehouseManageComponent implements OnInit { ...this._currentWarehouse, ...tabsInfoRaw.basicInfo, ...tabsInfoRaw.contactInfo, + usedCarriersIds: this._currentWarehouse.usedCarriersIds, geoLocation: tabsInfoRaw.location, deliveryAreas: tabsInfoRaw.deliveryAreas, isPaymentEnabled: tabsInfoRaw.isPaymentEnabled, diff --git a/packages/carrier-mobile-ionic/src/pages/main/drive-to-warehouse/drive-to-warehouse.ts b/packages/carrier-mobile-ionic/src/pages/main/drive-to-warehouse/drive-to-warehouse.ts index 5019a3bbd..0ac8c9cd0 100644 --- a/packages/carrier-mobile-ionic/src/pages/main/drive-to-warehouse/drive-to-warehouse.ts +++ b/packages/carrier-mobile-ionic/src/pages/main/drive-to-warehouse/drive-to-warehouse.ts @@ -16,6 +16,9 @@ import { MapComponent } from '../common/map/map.component'; import { Router } from '@angular/router'; import { NavController, Platform } from '@ionic/angular'; import { getIdFromTheDate } from '@modules/server.common/utils'; +import Warehouse from '@modules/server.common/entities/Warehouse'; +import { WarehouseRouter } from '@modules/client.common.angular2/routers/warehouse-router.service'; +import { first } from 'rxjs/operators'; declare var google: any; @@ -36,6 +39,7 @@ export class DriveToWarehousePage implements OnInit { selectedOrderID: string; orderCarrierCompetition: boolean; isTakenFromAnotherCarrier: boolean = false; + warehouseId: string; carrier$; order$; @@ -49,7 +53,8 @@ export class DriveToWarehousePage implements OnInit { private geolocation: Geolocation, private router: Router, private navCtrl: NavController, - public platform: Platform + public platform: Platform, + public warehouseRouter: WarehouseRouter ) {} ngOnInit(): void { @@ -88,6 +93,7 @@ export class DriveToWarehousePage implements OnInit { populateWarehouse: true, }) .subscribe((order) => { + this.warehouseId = order.warehouseId; this.orderCarrierCompetition = order.warehouse['carrierCompetition']; @@ -135,6 +141,14 @@ export class DriveToWarehousePage implements OnInit { async takeWork() { if (this.carrier && this.selectedOrder) { + const warehouse: Warehouse = await this.warehouseRouter + .get(this.warehouseId) + .pipe(first()) + .toPromise(); + + warehouse.usedCarriersIds.push(this.carrier['id']); + this.warehouseRouter.save(warehouse); + return await this.carrierOrdersRouter.selectedForDelivery( this.carrier['id'], [this.selectedOrder['id']] diff --git a/packages/common-angular/package.json b/packages/common-angular/package.json index 33c6eb923..5234bc486 100644 --- a/packages/common-angular/package.json +++ b/packages/common-angular/package.json @@ -2,7 +2,7 @@ "name": "@ever-platform/common-angular", "description": "Ever Platform Shared Angular Core", "license": "AGPL-3.0", - "version": "0.3.6", + "version": "0.3.7", "homepage": "https://ever.co", "repository": { "type": "git", diff --git a/packages/common-angular/src/routers/warehouse-carriers-router.service.ts b/packages/common-angular/src/routers/warehouse-carriers-router.service.ts index 6b88af229..7a2424fd2 100644 --- a/packages/common-angular/src/routers/warehouse-carriers-router.service.ts +++ b/packages/common-angular/src/routers/warehouse-carriers-router.service.ts @@ -25,6 +25,16 @@ export class WarehouseCarriersRouter implements IWarehouseCarriersRouter { ); } + getUsedCarriers(warehouseId: string): Observable { + return this.router + .runAndObserve('getUsedCarriers', warehouseId) + .pipe( + map((carriers) => + _.map(carriers, (carrier) => this._carrierFactory(carrier)) + ) + ); + } + async updatePassword(id: string, password: string): Promise { await this.router.run('updatePassword', id, password); } diff --git a/packages/common/package.json b/packages/common/package.json index 9571b660c..5eebcb1ae 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -2,7 +2,7 @@ "name": "@ever-platform/common", "description": "Ever Platform Shared Core", "license": "AGPL-3.0", - "version": "0.3.24", + "version": "0.3.25", "homepage": "https://ever.co", "repository": { "type": "git", diff --git a/packages/common/src/routers/IWarehouseCarriersRouter.ts b/packages/common/src/routers/IWarehouseCarriersRouter.ts index d8f88e799..bc160fe50 100644 --- a/packages/common/src/routers/IWarehouseCarriersRouter.ts +++ b/packages/common/src/routers/IWarehouseCarriersRouter.ts @@ -4,6 +4,7 @@ import Carrier from '../entities/Carrier'; interface IWarehouseCarriersRouter { get(warehouseId: Warehouse['id']): Observable; + getUsedCarriers(warehouseId: Warehouse['id']): Observable; updatePassword(id: Carrier['id'], password: string): Promise; } diff --git a/packages/core/package.json b/packages/core/package.json index 1668a5eca..d8124f9dc 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -2,7 +2,7 @@ "name": "@ever-platform/core", "description": "Ever Platform Headless Framework", "license": "AGPL-3.0", - "version": "0.3.29", + "version": "0.3.30", "homepage": "https://ever.co", "repository": { "type": "git", diff --git a/packages/core/src/graphql/warehouses-carriers/warehouses-carriers.types.graphql b/packages/core/src/graphql/warehouses-carriers/warehouses-carriers.types.graphql index ef89662dc..e0050393c 100644 --- a/packages/core/src/graphql/warehouses-carriers/warehouses-carriers.types.graphql +++ b/packages/core/src/graphql/warehouses-carriers/warehouses-carriers.types.graphql @@ -1,3 +1,4 @@ type Query { getStoreCarriers(storeId: String!): [Carrier!] + getUsedCarriers(storeId: String!): [Carrier!] } diff --git a/packages/core/src/services/warehouses/WarehousesCarriersService.ts b/packages/core/src/services/warehouses/WarehousesCarriersService.ts index 3eda29eba..6cc5edbf0 100644 --- a/packages/core/src/services/warehouses/WarehousesCarriersService.ts +++ b/packages/core/src/services/warehouses/WarehousesCarriersService.ts @@ -83,6 +83,45 @@ export class WarehousesCarriersService implements IWarehouseCarriersRouter { ); } + /** + * Get Carriers assigned to given Store + * Returns all used if warehouse.hasRestrictedCarriers + * @param {String} warehouseId + * @returns {Observable} + */ + @observableListener() + getUsedCarriers( + warehouseId: Warehouse['id'] + ): Observable { + return this.warehousesService.get(warehouseId).pipe( + map((warehouse) => { + if (!warehouse.hasRestrictedCarriers) { + throw new NoWarehouseRestrictedCarriersError(); + } + const usedCarriers = []; + + usedCarriers.push(...warehouse.carriersIds); + usedCarriers.push(...warehouse.usedCarriersIds); + + return usedCarriers; + }), + distinctUntilChanged((carrierIds1, carrierIds2) => { + return _.isEqual(carrierIds1.sort(), carrierIds2.sort()); + }), + exhaustMap((carrierIds) => { + return this.carriersService.getMultipleByIds(carrierIds); + }), + switchMap((carriers) => carriers), + catchError((err) => { + if (!(err instanceof NoWarehouseRestrictedCarriersError)) { + throw err; + } + + return of(null); + }) + ); + } + /** * Update carrier password * diff --git a/packages/merchant-tablet-ionic/src/pages/+carriers/add-carriers-popup/add-carriers-popup.ts b/packages/merchant-tablet-ionic/src/pages/+carriers/add-carriers-popup/add-carriers-popup.ts index 5bc55f713..2d45f30be 100644 --- a/packages/merchant-tablet-ionic/src/pages/+carriers/add-carriers-popup/add-carriers-popup.ts +++ b/packages/merchant-tablet-ionic/src/pages/+carriers/add-carriers-popup/add-carriers-popup.ts @@ -144,10 +144,10 @@ export class AddCarriersPopupPage implements OnInit, OnDestroy { }); warehouse.hasRestrictedCarriers = true; - warehouse.usedCarriersIds.push(carrier.id); + warehouse.carriersIds.push(carrier.id); } else if (this.choiced === 'existing') { warehouse.hasRestrictedCarriers = true; - warehouse.usedCarriersIds.push( + warehouse.carriersIds.push( ...this.carriersCatalog.selecteCarriers.map((c) => c.id) ); } diff --git a/packages/merchant-tablet-ionic/src/pages/+carriers/carriers.ts b/packages/merchant-tablet-ionic/src/pages/+carriers/carriers.ts index b6aceb8c8..5b517cc92 100644 --- a/packages/merchant-tablet-ionic/src/pages/+carriers/carriers.ts +++ b/packages/merchant-tablet-ionic/src/pages/+carriers/carriers.ts @@ -9,7 +9,6 @@ import { AddressesComponent } from '../../components/carriers-table/addresses'; import { StatusComponent } from '../../components/carriers-table/status'; import { DeliveriesComponent } from '../../components/carriers-table/deliveries'; import { ImageComponent } from '../../components/carriers-table/image'; -import { WarehouseCarriersRouter } from '@modules/client.common.angular2/routers/warehouse-carriers-router.service'; import { Store } from '../../../src/services/store.service'; import { ModalController } from '@ionic/angular'; import { AddCarriersPopupPage } from './add-carriers-popup/add-carriers-popup'; @@ -18,6 +17,10 @@ import { CarrierTrackPopup } from './carrier-track-popup/carrier-track-popup'; import { Router } from '@angular/router'; import { ConfirmDeletePopupPage } from 'components/confirm-delete-popup/confirm-delete-popup'; import { WarehouseRouter } from '@modules/client.common.angular2/routers/warehouse-router.service'; +import { CarrierRouter } from '@modules/client.common.angular2/routers/carrier-router.service'; +import { WarehouseOrdersRouter } from '@modules/client.common.angular2/routers/warehouse-orders-router.service'; +import { WarehouseCarriersRouter } from '@modules/client.common.angular2/routers/warehouse-carriers-router.service'; +import { CarrierService } from 'services/carrier.service'; @Component({ selector: 'page-carriers', @@ -35,10 +38,13 @@ export class CarriersPage implements OnInit, OnDestroy { constructor( private readonly router: Router, public modalCtrl: ModalController, - private readonly warehouseCarriersRouter: WarehouseCarriersRouter, private readonly _translateService: TranslateService, private readonly store: Store, - private warehouseRouter: WarehouseRouter + private warehouseRouter: WarehouseRouter, + private readonly carrierRouter: CarrierRouter, + private readonly carrierService: CarrierService, + private warehouseOrdersRouter: WarehouseOrdersRouter, + private readonly warehouseCarriersRouter: WarehouseCarriersRouter ) {} get deviceId() { @@ -127,17 +133,30 @@ export class CarriersPage implements OnInit, OnDestroy { this.sourceSmartTable.load(carriersVM); }; - this.warehouseCarriersRouter + this.warehouseRouter .get(this.warehouseId) - .pipe(takeUntil(this._ngDestroy$)) - .subscribe((carriers) => { - this.carriers = carriers; - - loadData(this.carriers); - - this.carriers.length === 0 - ? (this.showNoDeliveryIcon = true) - : (this.showNoDeliveryIcon = false); + .subscribe(async (warehouse) => { + if (warehouse.hasRestrictedCarriers) { + this.carriers = await this.warehouseCarriersRouter + .getUsedCarriers(this.warehouseId) + .pipe(first()) + .toPromise(); + + loadData(this.carriers); + this.carriers.length === 0 + ? (this.showNoDeliveryIcon = true) + : (this.showNoDeliveryIcon = false); + } else { + this.carrierRouter + .getAllActive() + .subscribe((carriers: Carrier[]) => { + this.carriers = carriers; + loadData(this.carriers); + this.carriers.length === 0 + ? (this.showNoDeliveryIcon = true) + : (this.showNoDeliveryIcon = false); + }); + } }); }