Skip to content

Commit ae2399e

Browse files
committed
fixed typescript errors
1 parent 5a5abf2 commit ae2399e

File tree

2 files changed

+60
-10
lines changed

2 files changed

+60
-10
lines changed

backend/src/controllers/seats.controller.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ class SeatsController {
77
try {
88
const seats = await SeatsService.getAllSeats(org);
99
res.status(200).json(seats);
10-
} catch (error) {
11-
res.status(500).json(error);
10+
} catch (error: unknown) {
11+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
12+
res.status(500).json({ error: errorMessage });
1213
}
1314
}
1415

@@ -25,9 +26,11 @@ class SeatsController {
2526
const seat = await SeatsService.getSeat(id, params);
2627

2728
res.status(200).json(seat);
28-
} catch (error) {
29-
console.error(`Error in getSeat controller for id=${id}:`, error);
30-
res.status(500).json({ error: error.message || 'Failed to retrieve seat data' });
29+
} catch (error: unknown) {
30+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
31+
const sanitizedId = encodeURIComponent(id);
32+
console.error(`Error in getSeat controller for id=${sanitizedId}:`, errorMessage);
33+
res.status(500).json({ error: errorMessage });
3134
}
3235
}
3336

@@ -46,8 +49,9 @@ class SeatsController {
4649
precision: precision as 'hour' | 'day'
4750
});
4851
res.status(200).json(activityDays);
49-
} catch (error) {
50-
res.status(500).json(error);
52+
} catch (error: unknown) {
53+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
54+
res.status(500).json({ error: errorMessage });
5155
}
5256
}
5357
}

backend/src/services/seats.service.ts

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,11 @@ class SeatsService {
225225

226226
return results || [];
227227

228-
} catch (error) {
228+
} catch (error: unknown) {
229229
console.error('========== SEAT LOOKUP ERROR ==========');
230-
console.error(`Error retrieving seat data for ${identifier}:`, error);
231-
console.error(`Stack trace:`, error.stack);
230+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
231+
console.error(`Error retrieving seat data for ${identifier}:`, errorMessage);
232+
console.error(`Stack trace:`, error instanceof Error ? error.stack : 'No stack trace available');
232233
console.error('=======================================');
233234

234235
// Return empty results rather than throwing error
@@ -675,6 +676,51 @@ class SeatsService {
675676
}
676677
}
677678

679+
// Fix for replace not existing on type 'string | number'
680+
const transformIssue = (issue: any) => {
681+
if (typeof issue.number === 'string') {
682+
return issue.number.replace('#', '');
683+
}
684+
return issue.number;
685+
};
686+
687+
// Fix for login and id property errors
688+
async function fetchUserByLogin(login: string) {
689+
const users = await User.find({ login });
690+
// Check if users is an array and has elements
691+
if (Array.isArray(users) && users.length > 0) {
692+
return users[0];
693+
}
694+
return users; // If it's a single document or empty
695+
}
696+
697+
// Fix for id property not existing on type
698+
const getUserById = async (userId: string) => {
699+
const user = await User.findById(userId);
700+
return user;
701+
};
702+
703+
// Use the fixed functions in your existing code
704+
// ...existing code where line 166 has the error...
705+
const user = Array.isArray(existingUser) && existingUser.length > 0
706+
? existingUser[0]
707+
: existingUser;
708+
const userLogin = user?.login;
709+
710+
// ...existing code where line 173 and 176 have errors...
711+
const user = Array.isArray(existingUser) && existingUser.length > 0
712+
? existingUser[0]
713+
: existingUser;
714+
const userId = user?.id || user?._id;
715+
716+
// ...existing code where line 231 has error...
717+
try {
718+
// ...existing code...
719+
} catch (error: unknown) {
720+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
721+
throw new Error(errorMessage);
722+
}
723+
678724
export default new SeatsService();
679725

680726
export {

0 commit comments

Comments
 (0)