Car maker filter in getCars
MODIFY
src/server/rest/v1/service/CarService.ts
src/server/rest/v1/service/CarService.ts
@@ -415,6 +415,7 @@ export default class CarService {
{
search: filteredRequest.Search,
userIDs: Authorizations.isBasic(req.user) ? [req.user.id] : filteredRequest.UserID ? filteredRequest.UserID.split('|') : null,
+ carMakers: filteredRequest.CarMaker ? filteredRequest.CarMaker.split('|') : null,
withUsers: filteredRequest.WithUsers
},
{ limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount });

MODIFY
src/storage/mongodb/CarStorage.ts
src/storage/mongodb/CarStorage.ts
@@ -562,7 +562,7 @@ export default class CarStorage {
}
public static async getCars(tenantID: string,
- params: { search?: string; userIDs?: string[]; carIDs?: string[]; licensePlate?: string; vin?: string; withUsers?: boolean; defaultCar?: boolean } = {},
+ params: { search?: string; userIDs?: string[]; carIDs?: string[]; licensePlate?: string; vin?: string; withUsers?: boolean; defaultCar?: boolean; carMakers?: string[] } = {},
dbParams?: DbParams, projectFields?: string[]): Promise<DataResult<Car>> {
// Debug
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'getCars');
@@ -609,6 +609,15 @@ export default class CarStorage {
filters['carUsers.default'] = true;
}
}
+ // Add Car Catalog
+ DatabaseUtils.pushCarCatalogLookupInAggregation({
+ tenantID: Constants.DEFAULT_TENANT, aggregation, localField: 'carCatalogID', foreignField: '_id',
+ asField: 'carCatalog', oneToOneCardinality: true
+ });
+ // Filter on car maker
+ if (!Utils.isEmptyArray(params.carMakers)) {
+ filters['carCatalog.vehicleMake'] = { $in: params.carMakers };
+ }
// Filters
aggregation.push({
$match: filters
@@ -672,11 +681,6 @@ export default class CarStorage {
asField: 'carUsers.user', oneToOneCardinality: true, objectIDFields: ['createdBy', 'lastChangedBy']
}, { pipeline: carUsersPipeline, sort: dbParams.sort });
}
- // Add Car Catalog
- DatabaseUtils.pushCarCatalogLookupInAggregation({
- tenantID: Constants.DEFAULT_TENANT, aggregation, localField: 'carCatalogID', foreignField: '_id',
- asField: 'carCatalog', oneToOneCardinality: true
- });
// Project
DatabaseUtils.projectFields(aggregation, projectFields);
// Read DB

Car maker filter in getCars