Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: carriers not showing on merchant #1253

Draft
wants to merge 10 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -36,6 +39,7 @@ export class DriveToWarehousePage implements OnInit {
selectedOrderID: string;
orderCarrierCompetition: boolean;
isTakenFromAnotherCarrier: boolean = false;
warehouseId: string;

carrier$;
order$;
Expand All @@ -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 {
Expand Down Expand Up @@ -88,6 +93,7 @@ export class DriveToWarehousePage implements OnInit {
populateWarehouse: true,
})
.subscribe((order) => {
this.warehouseId = order.warehouseId;
this.orderCarrierCompetition =
order.warehouse['carrierCompetition'];

Expand Down Expand Up @@ -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']]
Expand Down
2 changes: 1 addition & 1 deletion packages/common-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ export class WarehouseCarriersRouter implements IWarehouseCarriersRouter {
);
}

getUsedCarriers(warehouseId: string): Observable<Carrier[]> {
return this.router
.runAndObserve<ICarrier[]>('getUsedCarriers', warehouseId)
.pipe(
map((carriers) =>
_.map(carriers, (carrier) => this._carrierFactory(carrier))
)
);
}

async updatePassword(id: string, password: string): Promise<void> {
await this.router.run('updatePassword', id, password);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/routers/IWarehouseCarriersRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Carrier from '../entities/Carrier';

interface IWarehouseCarriersRouter {
get(warehouseId: Warehouse['id']): Observable<Carrier[] | null>;
getUsedCarriers(warehouseId: Warehouse['id']): Observable<Carrier[] | null>;
updatePassword(id: Carrier['id'], password: string): Promise<void>;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type Query {
getStoreCarriers(storeId: String!): [Carrier!]
getUsedCarriers(storeId: String!): [Carrier!]
}
39 changes: 39 additions & 0 deletions packages/core/src/services/warehouses/WarehousesCarriersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Carrier[] | null>}
*/
@observableListener()
getUsedCarriers(
warehouseId: Warehouse['id']
): Observable<Carrier[] | null> {
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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
Expand Down
45 changes: 32 additions & 13 deletions packages/merchant-tablet-ionic/src/pages/+carriers/carriers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
});
}
});
}

Expand Down