hange car url types
MODIFY
src/integration/car/ev-database/EVDatabaseCarIntegration.ts
src/integration/car/ev-database/EVDatabaseCarIntegration.ts
@@ -7,6 +7,7 @@ import Configuration from '../../../utils/Configuration';
import Constants from '../../../utils/Constants';
import Logging from '../../../utils/Logging';
import { ServerAction } from '../../../types/Server';
+import Utils from '../../../utils/Utils';
const MODULE_NAME = 'EVDatabaseCarIntegration';
@@ -199,7 +200,7 @@ export default class EVDatabaseCarIntegration extends CarIntegration {
euroNCAPSA: data.EuroNCAP_SA,
relatedVehicleIDSuccesor: data.Related_Vehicle_ID_Succesor,
eVDBDetailURL: data.EVDB_Detail_URL,
- imageURLs: data.Images,
+ imageURLs: data.Images ? (!Utils.isEmptyArray(data.Images) ? data.Images : [data.Images]) : [],
images: [],
videos: data.Videos,
};
@@ -211,7 +212,7 @@ export default class EVDatabaseCarIntegration extends CarIntegration {
public async getCarCatalogThumb(carCatalog: CarCatalog): Promise<string> {
let image: string;
// Create the car thumb using the first image URL
- if (carCatalog.imageURLs && carCatalog.imageURLs.length > 0) {
+ if (!Utils.isEmptyArray(carCatalog.imageURLs)) {
try {
const imageURL = this.convertToThumbImage(carCatalog.imageURLs[0]);
const response = await this.axiosInstance.get(imageURL, { responseType: 'arraybuffer' });

MODIFY
src/storage/mongodb/CarStorage.ts
src/storage/mongodb/CarStorage.ts
@@ -106,12 +106,17 @@ export default class CarStorage {
aggregation.push({
$addFields: {
image: {
+ $cond: {
+ if: { $gt: ['$image', null] }, then: {
$concat: [
`${Utils.buildRestServerURL()}/client/util/CarCatalogImage?ID=`,
{ $toString: '$_id' },
'&LastChangedOn=',
{ $toString: '$lastChangedOn' }
]
+ }, else: null
+ }
+
}
}
});
@@ -598,8 +603,10 @@ 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; carMakers?: string[] } = {},
+ 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');
@@ -703,12 +710,17 @@ export default class CarStorage {
aggregation.push({
$addFields: {
'carCatalog.image': {
+ $cond: {
+ if: { $gt: ['$carCatalog.image', null] }, then: {
$concat: [
`${Utils.buildRestServerURL()}/client/util/CarCatalogImage?ID=`,
'$carCatalog.id',
'&LastChangedOn=',
{ $toString: '$carCatalog.lastChangedOn' }
]
+ }, else: null
+ }
+
}
}
});

hange car url types