Commit b5c6d78e authored by RAHUL RATHORE's avatar RAHUL RATHORE
Browse files

fix: single order schema populate mongoose 6.0.11 issue

parent 86119336
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ export class OrderComponent implements OnDestroy {
			details.push(warehouse.contactPhone);
			details.push(warehouse.contactEmail);
		}
		if (warehouse.geoLocation) {
		if (warehouse && warehouse.geoLocation) {
			details.push(this.getFullAddress(warehouse.geoLocation));
		}
		return details.filter((d) => d);
@@ -96,7 +96,7 @@ export class OrderComponent implements OnDestroy {
			details.push(user.phone);
			details.push(user.email);
		}
		if (user.geoLocation) {
		if (user && user.geoLocation) {
			details.push(user.fullAddress);

			user.geoLocation.notes =
@@ -119,7 +119,7 @@ export class OrderComponent implements OnDestroy {
			);
			details.push(carrier.phone);
		}
		if (carrier.geoLocation) {
		if (carrier && carrier.geoLocation) {
			details.push(this.getFullAddress(carrier.geoLocation));
		}
		return details.filter((d) => d);
+1 −1
Original line number Diff line number Diff line
@@ -3,6 +3,6 @@ import { Component } from '@angular/core';
@Component({
	selector: 'ea-orders',
	templateUrl: './orders.component.html',
	styleUrls: ['/orders.component.scss'],
	styleUrls: ['./orders.component.scss'],
})
export class OrdersComponent {}
+4 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import Product from '@modules/server.common/entities/Product';
import * as _ from 'lodash';
import { ObjectId } from 'bson';
import { FakeOrdersService } from '../../services/fake-data/FakeOrdersService';
import { firstValueFrom } from 'rxjs';

@Resolver('Order')
export class OrderResolver {
@@ -612,7 +613,9 @@ export class OrderResolver {

	@Query('getOrder')
	async getOrder(_context, { id }: { id: string }): Promise<Order> {
		return this._ordersService.get(id).pipe(first()).toPromise();
		return firstValueFrom(
			this._ordersService.get(id)
		);
	}

	@Query('orders')
+9 −11
Original line number Diff line number Diff line
@@ -930,22 +930,20 @@ export class OrdersService extends DBService<Order>
		id: string,
		options: { populateWarehouse?: boolean; populateCarrier?: boolean } = {}
	): Promise<Order> {
		let toPopulate = '';

		const query = this.Model.findById(id);
		if (options.populateCarrier) {
			toPopulate += 'carrier ';
			query.populate('carrier');
		}

		if (options.populateWarehouse) {
			toPopulate += 'warehouse ';
			query.populate('warehouse');
		}

		return new Order(
			(await this.Model.findById(id)
				.populate(toPopulate)
			(
				await query
					.sort({ _createdAt: -1, orderNumber: -1 })
					.lean()
				.exec()) as IOrder
					.exec()
			) as IOrder
		);
	}