Photos for vehicles
This commit is contained in:
@@ -8,7 +8,8 @@ import {
|
||||
Vehicle,
|
||||
CreateVehicleRequest,
|
||||
UpdateVehicleRequest,
|
||||
VehicleResponse
|
||||
VehicleResponse,
|
||||
VehicleImageMeta
|
||||
} from './vehicles.types';
|
||||
import { logger } from '../../../core/logging/logger';
|
||||
import { cacheService } from '../../../core/config/redis';
|
||||
@@ -131,14 +132,31 @@ export class VehiclesService {
|
||||
if (existing.userId !== userId) {
|
||||
throw new Error('Unauthorized');
|
||||
}
|
||||
|
||||
|
||||
// Soft delete
|
||||
await this.repository.softDelete(id);
|
||||
|
||||
|
||||
// Invalidate cache
|
||||
await this.invalidateUserCache(userId);
|
||||
}
|
||||
|
||||
|
||||
async getVehicleRaw(id: string, userId: string): Promise<Vehicle | null> {
|
||||
const vehicle = await this.repository.findById(id);
|
||||
if (!vehicle || vehicle.userId !== userId) {
|
||||
return null;
|
||||
}
|
||||
return vehicle;
|
||||
}
|
||||
|
||||
async updateVehicleImage(id: string, userId: string, meta: VehicleImageMeta | null): Promise<VehicleResponse | null> {
|
||||
const updated = await this.repository.updateImageMeta(id, userId, meta);
|
||||
if (!updated) {
|
||||
return null;
|
||||
}
|
||||
await this.invalidateUserCache(userId);
|
||||
return this.toResponse(updated);
|
||||
}
|
||||
|
||||
private async invalidateUserCache(userId: string): Promise<void> {
|
||||
const cacheKey = `${this.cachePrefix}:user:${userId}`;
|
||||
await cacheService.del(cacheKey);
|
||||
@@ -227,6 +245,7 @@ export class VehiclesService {
|
||||
isActive: vehicle.isActive,
|
||||
createdAt: vehicle.createdAt.toISOString(),
|
||||
updatedAt: vehicle.updatedAt.toISOString(),
|
||||
imageUrl: vehicle.imageStorageKey ? `/api/vehicles/${vehicle.id}/image` : undefined,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user