Add Users Filter to getCars
MODIFY
src/server/rest/service/CarService.ts
src/server/rest/service/CarService.ts
+import { Action, Entity } from '../../../types/Authorization';
+import { Car, CarType } from '../../../types/Car';
+import { HTTPAuthError, HTTPError } from '../../../types/HTTPError';
import { NextFunction, Request, Response } from 'express';
-import Authorizations from '../../../authorization/Authorizations';
+
import AppAuthError from '../../../exception/AppAuthError';
import AppError from '../../../exception/AppError';
+import Authorizations from '../../../authorization/Authorizations';
import BackendError from '../../../exception/BackendError';
import CarFactory from '../../../integration/car/CarFactory';
+import CarSecurity from './security/CarSecurity';
import CarStorage from '../../../storage/mongodb/CarStorage';
-import UserStorage from '../../../storage/mongodb/UserStorage';
-import { Action, Entity } from '../../../types/Authorization';
-import { Car, CarType } from '../../../types/Car';
-import { HTTPAuthError, HTTPError } from '../../../types/HTTPError';
+import Constants from '../../../utils/Constants';
+import Logging from '../../../utils/Logging';
import { ServerAction } from '../../../types/Server';
import TenantComponents from '../../../types/TenantComponents';
import { UserCar } from '../../../types/User';
+import UserStorage from '../../../storage/mongodb/UserStorage';
import UserToken from '../../../types/UserToken';
-import Constants from '../../../utils/Constants';
-import Logging from '../../../utils/Logging';
import Utils from '../../../utils/Utils';
-import CarSecurity from './security/CarSecurity';
import UtilsService from './UtilsService';
-
const MODULE_NAME = 'CarService';
export default class CarService {
@@ -395,7 +395,7 @@ export default class CarService {
const cars = await CarStorage.getCars(req.user.tenantID,
{
search: filteredRequest.Search,
- userIDs: Authorizations.isBasic(req.user) ? [req.user.id] : null,
+ userIDs: Authorizations.isBasic(req.user) ? [req.user.id] : filteredRequest.UserID ? filteredRequest.UserID.split('|') : null,
withUsers: filteredRequest.WithUsers
},
{ limit: filteredRequest.Limit, skip: filteredRequest.Skip, sort: filteredRequest.Sort, onlyRecordCount: filteredRequest.OnlyRecordCount });

MODIFY
src/server/rest/service/security/CarSecurity.ts
src/server/rest/service/security/CarSecurity.ts
-import sanitize from 'mongo-sanitize';
-import Authorizations from '../../../../authorization/Authorizations';
import { Car, CarCatalog, CarMaker } from '../../../../types/Car';
-import { DataResult } from '../../../../types/DataResult';
import { HttpCarByIDRequest, HttpCarCatalogByIDRequest, HttpCarCatalogImagesRequest, HttpCarCatalogsRequest, HttpCarCreateRequest, HttpCarMakersRequest, HttpCarUpdateRequest, HttpCarsRequest, HttpUsersCarsRequest } from '../../../../types/requests/HttpCarRequest';
+
+import Authorizations from '../../../../authorization/Authorizations';
+import { DataResult } from '../../../../types/DataResult';
import { UserCar } from '../../../../types/User';
+import UserSecurity from './UserSecurity';
import UserToken from '../../../../types/UserToken';
import Utils from '../../../../utils/Utils';
-import UserSecurity from './UserSecurity';
import UtilsSecurity from './UtilsSecurity';
-
+import sanitize from 'mongo-sanitize';
export default class CarSecurity {
@@ -297,6 +297,7 @@ export default class CarSecurity {
Search: sanitize(request.Search),
CarMaker: sanitize(request.CarMaker),
WithUsers: UtilsSecurity.filterBoolean(request.WithUsers),
+ UserID: sanitize(request.UserID)
} as HttpCarsRequest;
UtilsSecurity.filterSkipAndLimit(request, filteredRequest);
UtilsSecurity.filterSort(request, filteredRequest);

MODIFY
src/types/requests/HttpCarRequest.ts
src/types/requests/HttpCarRequest.ts
import { CarType } from '../Car';
-import { UserCar } from '../User';
import HttpDatabaseRequest from './HttpDatabaseRequest';
-
+import { UserCar } from '../User';
export interface HttpCarCatalogsRequest extends HttpDatabaseRequest {
Search?: string;
@@ -51,6 +50,7 @@ export interface HttpCarsRequest extends HttpDatabaseRequest {
Search: string;
CarMaker: string;
WithUsers: boolean;
+ UserID: string;
}
export interface HttpUsersCarsRequest extends HttpDatabaseRequest {

Add Users Filter to getCars