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

Beta 1 dev #1262

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
=Mobile app Core update
  • Loading branch information
Ngoussong Fonda committed Jul 16, 2020
commit 0fac6ca34e8486ccb799bca516d32abf60313669
10 changes: 10 additions & 0 deletions packages/common/src/interfaces/ICategory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// TODO: add other locales

/*
type ICategory = 'cake' | 'food' | 'mart' | 'pizza' | 'clean' | 'med' | 'me2u' | 'messenger';

export default ICategory;
*/
export default interface ICategory {
name: string;
}
27 changes: 27 additions & 0 deletions packages/core/src/graphql/geo-locations/geo-location.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ export class GeoLocationResolver {
searchText
);
}

@Query()
async geoLocationProductsByCategory(
_,
{
geoLocation,
options,
category,
pagingOptions = {},
searchText
}: {
geoLocation;
options?: IGetGeoLocationProductsOptions;
category?;
pagingOptions;
searchText?: string;
}
) {
return this.geoLocationsProductsService.geoLocationProductsByCategory(
geoLocation,
category,
pagingOptions,
options,
searchText
);
}

@Query()
async getCountOfGeoLocationProducts(
_,
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/graphql/geo-locations/geo-locations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ type Query {
searchText: String
): [ProductInfo]!

geoLocationProductsByCategory(
geoLocation: GeoLocationFindInput!
category: ProductsCategorySearchInput
pagingOptions: PagingOptionsInput
options: GetGeoLocationProductsOptions
searchText: String
): [ProductInfo]!

getCountOfGeoLocationProducts(
geoLocation: GeoLocationFindInput!
options: GetGeoLocationProductsOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
type Query {
getCoseMerchants(geoLocation: GeoLocationFindInput!): [Warehouse]!
getCloseMerchantsCategory(geoLocation: GeoLocationFindInput!, category: ProductsCategorySearchInput): [Warehouse]!
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import IGeoLocation from '@modules/server.common/interfaces/IGeoLocation';
import Warehouse from '@modules/server.common/entities/Warehouse';
import Utils from '@modules/server.common/utils';
import GeoLocation from '@modules/server.common/entities/GeoLocation';
import ICategory from '@modules/server.common/interfaces/ICategory';

const IN_STORE_DISTANCE = 50;

Expand Down Expand Up @@ -35,4 +36,29 @@ export class GeoLocationMerchantsResolver {

return merchants.map((m) => new Warehouse(m));
}

@Query('getCloseMerchantsCategory')
async getCloseMerchantsCategory(_, { geoLocation }: { geoLocation: IGeoLocation }, {category}: {category: ICategory} ) {
let merchants = await this.geoLocationsWarehousesService.getCloseMerchantsCategory(
geoLocation,
category,
IN_STORE_DISTANCE,
{ fullProducts: false, activeOnly: true }
);

merchants = merchants.sort(
(m1, m2) =>
Utils.getDistance(
new GeoLocation(m1.geoLocation),
new GeoLocation(geoLocation)
) -
Utils.getDistance(
new GeoLocation(m2.geoLocation),
new GeoLocation(geoLocation)
)
);

return merchants.map((m) => new Warehouse(m));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ type ProductsCategory {
_updatedAt: Date
}

input ProductsCategorySearchInput {
name: String!
}

input ProductsCategoryInput {
_id: String!
name: [TranslateInput!]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from '@modules/server.common/interfaces/IProduct';
import WarehouseProduct from '@modules/server.common/entities/WarehouseProduct';
import { IGetGeoLocationProductsOptions } from 'graphql/geo-locations/geo-location.resolver';
import ICategory from '@modules/server.common/interfaces/ICategory';

@injectable()
@routerName('geo-location-products')
Expand Down Expand Up @@ -132,6 +133,35 @@ export class GeoLocationsProductsService
return products.slice(pagingOptions.skip).slice(0, pagingOptions.limit);
}

@asyncListener()
async geoLocationProductsByCategory(
@serialization((g: IGeoLocation) => new GeoLocation(g))
geoLocation: GeoLocation,
category: ICategory,
pagingOptions,
options?: IGetGeoLocationProductsOptions,
searchText?: string
): Promise<ProductInfo[]> {
const merchants = await this.geoLocationsWarehousesService.getMerchants(
geoLocation,
GeoLocationsWarehousesService.TrackingDistance,
{
fullProducts: true,
activeOnly: true,
merchantsIds: options ? options.merchantIds : null
}
);

const products = this._getProductsFromWarehouses(
geoLocation,
merchants.map((m) => new Warehouse(m)),
options,
searchText
);

return products.slice(pagingOptions.skip).slice(0, pagingOptions.limit);
}

private _getProductsFromWarehouses(
geoLocation: GeoLocation,
warehouses: Warehouse[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
asyncListener,
} from '@pyro/io';
import IGeoLocation from '@modules/server.common/interfaces/IGeoLocation';
import ICategory from '@modules/server.common/interfaces/ICategory';
import IGeoLocationWarehousesRouter from '@modules/server.common/routers/IGeoLocationWarehousesRouter';
import IService from '../IService';
import { ExistenceEventType } from '@pyro/db-server';
Expand Down Expand Up @@ -175,6 +176,46 @@ export class GeoLocationsWarehousesService
return merchants;
}

@asyncListener()
async getCloseMerchantsCategory(
geoLocation: IGeoLocation,
category: ICategory,
maxDistance: number,
options: {
fullProducts: boolean;
activeOnly: boolean;
merchantsIds?: string[];
}
): Promise<IWarehouse[]> {
const merchantsIds = options.merchantsIds;
const merchants = (await this.warehousesService.Model.find(
_.assign(
{
'geoLocation.loc': {
$near: {
$geometry: {
type: 'Point',
coordinates: geoLocation.loc.coordinates
},
$maxDistance: maxDistance
}
}
},
options.activeOnly ? { isActive: true } : {},
merchantsIds && merchantsIds.length > 0
? {
_id: { $in: merchantsIds }
}
: {}
)
)
.populate(options.fullProducts ? 'products.product' : '')
.lean()
.exec()) as IWarehouse[];

return merchants;
}

/**
* Get warehouses available for given location
*
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/services/invites/InvitesRequestsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,11 @@ export class InvitesRequestsService extends DBService<InviteRequest>
},
},
};
case 'ru-RU':
case 'fr-FR':
return {
android: {
title: 'Ever только что запустился!',
alert: 'Кликните чтобы увидить доступные продукты.',
title: 'BellEm, c est lance!',
alert: 'Cliquez pour voir les produits disponibles.',
extra: {
event: launched,
invite: JSON.stringify(invite),
Expand Down