Skip to content

Commit 57e5b89

Browse files
committed
Code cleanup to remove redundancy
1 parent a519ee8 commit 57e5b89

2 files changed

Lines changed: 5 additions & 116 deletions

File tree

server/dimo-service.ts

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ export class DimoService {
2626
// Get Vehicle JWT for specific vehicle access (using new preferred method)
2727
async getVehicleJwt(developerJwt: any, tokenId: number) {
2828
try {
29-
return await this.dimo.tokenexchange.exchange({
29+
return await this.dimo.tokenexchange.getVehicleJwt({
3030
...developerJwt,
31-
privileges: [1, 3, 4, 5, 6],
3231
tokenId: tokenId,
3332
});
3433
} catch (error) {
@@ -72,21 +71,7 @@ export class DimoService {
7271
}
7372
}
7473

75-
async getVehicleData(vehicleId: string, userToken: string) {
76-
try {
77-
// Get vehicle information using the data SDK
78-
const vehicleData = await this.dimo.identity.getVehicle({
79-
tokenId: parseInt(vehicleId),
80-
});
81-
82-
return vehicleData;
83-
} catch (error) {
84-
console.error("Error fetching DIMO vehicle data:", error);
85-
throw error;
86-
}
87-
}
88-
89-
async getVehicleLocation(vehicleId: string, userToken: string) {
74+
async getVehicleLocation(vehicleId: string) {
9075
try {
9176
const tokenId = parseInt(vehicleId);
9277

@@ -144,7 +129,7 @@ export class DimoService {
144129
}
145130
}
146131

147-
async getVehicleWeeklyHistory(vehicleId: string, userToken: string) {
132+
async getVehicleWeeklyHistory(vehicleId: string) {
148133
try {
149134
const tokenId = parseInt(vehicleId);
150135

@@ -209,31 +194,6 @@ export class DimoService {
209194
throw error;
210195
}
211196
}
212-
213-
async getVehicleTelemetry(vehicleId: string, signals: string[] = []) {
214-
try {
215-
// Get telemetry data for specified signals
216-
const defaultSignals = [
217-
"location.latitude",
218-
"location.longitude",
219-
"location.accuracy",
220-
"speed",
221-
"odometer",
222-
];
223-
224-
const requestedSignals = signals.length > 0 ? signals : defaultSignals;
225-
226-
const telemetryData = await this.dimo.telemetry.getLatest({
227-
tokenId: parseInt(vehicleId),
228-
signals: requestedSignals,
229-
});
230-
231-
return telemetryData;
232-
} catch (error) {
233-
console.error("Error fetching DIMO vehicle telemetry:", error);
234-
throw error;
235-
}
236-
}
237197
}
238198

239199
export const dimoService = new DimoService();

server/routes.ts

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,10 @@ export async function registerRoutes(app: Express): Promise<Server> {
9595
return;
9696
}
9797

98-
const userToken = authHeader.substring(7);
99-
10098
console.log("Fetching real-time location for vehicle:", vehicleId);
10199

102100
// Use the real DIMO service to get vehicle location
103-
const locationData = await dimoService.getVehicleLocation(
104-
vehicleId,
105-
userToken,
106-
);
101+
const locationData = await dimoService.getVehicleLocation(vehicleId);
107102

108103
// Automatically save to GPS storage for visualization
109104
const savedData = await storage.saveGpsData(locationData);
@@ -133,15 +128,10 @@ export async function registerRoutes(app: Express): Promise<Server> {
133128
return;
134129
}
135130

136-
const userToken = authHeader.substring(7);
137-
138131
console.log("Fetching weekly location for vehicle:", vehicleId);
139132

140133
// Use the real DIMO service to get vehicle location
141-
const locationData = await dimoService.getVehicleWeeklyHistory(
142-
vehicleId,
143-
userToken,
144-
);
134+
const locationData = await dimoService.getVehicleWeeklyHistory(vehicleId);
145135
console.log("Weekly location data:", locationData);
146136
// Automatically save to GPS storage for visualization
147137
const savedData = await storage.saveGpsData(locationData);
@@ -158,67 +148,6 @@ export async function registerRoutes(app: Express): Promise<Server> {
158148
}
159149
});
160150

161-
app.get("/api/dimo/vehicles/:vehicleId/data", async (req, res) => {
162-
try {
163-
const { vehicleId } = req.params;
164-
const authHeader = req.headers.authorization;
165-
166-
if (!authHeader || !authHeader.startsWith("Bearer ")) {
167-
res
168-
.status(401)
169-
.json({ message: "Missing or invalid authorization token" });
170-
return;
171-
}
172-
173-
const userToken = authHeader.substring(7);
174-
const vehicleData = await dimoService.getVehicleData(
175-
vehicleId,
176-
userToken,
177-
);
178-
res.json(vehicleData);
179-
} catch (error) {
180-
console.error("Error fetching DIMO vehicle data:", error);
181-
res
182-
.status(500)
183-
.json({ message: "Failed to fetch vehicle data from DIMO" });
184-
}
185-
});
186-
187-
app.get("/api/dimo/vehicles/:vehicleId/telemetry", async (req, res) => {
188-
try {
189-
const { vehicleId } = req.params;
190-
const { signals } = req.query;
191-
const authHeader = req.headers.authorization;
192-
193-
if (!authHeader || !authHeader.startsWith("Bearer ")) {
194-
res
195-
.status(401)
196-
.json({ message: "Missing or invalid authorization token" });
197-
return;
198-
}
199-
200-
const requestedSignals = signals ? (signals as string).split(",") : [];
201-
const telemetryData = await dimoService.getVehicleTelemetry(
202-
vehicleId,
203-
requestedSignals,
204-
);
205-
res.json(telemetryData);
206-
} catch (error) {
207-
console.error("Error fetching DIMO vehicle telemetry:", error);
208-
res
209-
.status(500)
210-
.json({ message: "Failed to fetch vehicle telemetry from DIMO" });
211-
}
212-
});
213-
214-
// Legacy route - redirects to new endpoint
215-
app.get("/api/dimo/shared-vehicles", async (req, res) => {
216-
res.status(410).json({
217-
message:
218-
"This endpoint has been deprecated. Please use /api/dimo/vehicles with proper authentication.",
219-
});
220-
});
221-
222151
const httpServer = createServer(app);
223152
return httpServer;
224153
}

0 commit comments

Comments
 (0)