Skip to content

Commit 553af96

Browse files
fix linter errors not related to validation
1 parent d0ebe8d commit 553af96

24 files changed

+270
-334
lines changed

server/eslint.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import tseslint from 'typescript-eslint';
55

66
export default tseslint.config(
77
{
8-
ignores: ['dist', 'node_modules'],
8+
ignores: ['dist', 'node_modules', 'scripts', 'eslint.config.js'],
99
},
1010
eslint.configs.recommended,
1111
tseslint.configs.strictTypeChecked,
@@ -22,7 +22,7 @@ export default tseslint.config(
2222
rules: {
2323
'@typescript-eslint/restrict-template-expressions': ['error', { allowNumber: true }],
2424
'no-unused-vars': 'off',
25-
'@typescript-eslint/no-unused-vars': 'error',
25+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
2626
},
2727
}
2828
);

server/src/api-docs/swagger.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import swaggerUi from 'swagger-ui-express';
1+
import swaggerUi, { JsonObject } from 'swagger-ui-express';
22
import fs from 'fs';
33
import YAML from 'yaml';
44
import { RequestHandler } from 'express';
@@ -9,8 +9,8 @@ import { RequestHandler } from 'express';
99
* @param {string} documentPath The file path to the Swagger YAML document.
1010
* @returns {Array<RequestHandler>} An array for serving and setting up Swagger UI.
1111
* */
12-
export default (documentPath: string): Array<RequestHandler> => {
12+
export default (documentPath: string): RequestHandler[] => {
1313
const file = fs.readFileSync(documentPath, 'utf8');
14-
const swaggerDocument = YAML.parse(file);
14+
const swaggerDocument = YAML.parse(file) as JsonObject;
1515
return swaggerUi.serve.concat(swaggerUi.setup(swaggerDocument));
1616
};

server/src/controllers/AuthenticationController.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ export class AuthenticationController implements AuthenticationControllerType {
6060

6161
// 3. Revoke Google OAuth token - we don't use it anymore.
6262
// Do not wait for the response. Continue with login process.
63-
this.googleOAuthService.revokeToken(googleAccessToken);
63+
await this.googleOAuthService.revokeToken(googleAccessToken);
6464
googleAccessToken = '';
6565

66-
if (!oauthUser || !oauthUser.emailVerified) {
66+
if (!oauthUser?.emailVerified) {
6767
throw new Error('Could not verify google auth code');
6868
}
6969
} catch (error) {
@@ -74,7 +74,7 @@ export class AuthenticationController implements AuthenticationControllerType {
7474

7575
// Check if the user is allowed to access to the system
7676
const user = await this.userRepository.findUserByEmail(oauthUser.email);
77-
if (!user || !user.isActive) {
77+
if (!user?.isActive) {
7878
res.status(403).json(new ResponseError('Not allowed to login'));
7979
Sentry.setUser({ email: oauthUser.email });
8080
Sentry.captureMessage(`Attempt to login with unauthorized user`, 'warning');
@@ -96,11 +96,13 @@ export class AuthenticationController implements AuthenticationControllerType {
9696
res.status(200).json(user);
9797
}
9898

99+
// eslint-disable-next-line @typescript-eslint/require-await
99100
async getSession(req: Request, res: Response): Promise<void> {
100101
const user = res.locals.user as AuthenticatedUser;
101102
res.status(200).json(user);
102103
}
103104

105+
// eslint-disable-next-line @typescript-eslint/require-await
104106
async logout(req: Request, res: Response): Promise<void> {
105107
res.clearCookie(TOKEN_COOKIE_NAME);
106108
res.status(204).end();
@@ -112,7 +114,7 @@ export class AuthenticationController implements AuthenticationControllerType {
112114
try {
113115
const url = new URL(redirectURI);
114116
return allowedHosts.includes(url.hostname);
115-
} catch (error) {
117+
} catch {
116118
return false;
117119
}
118120
}

server/src/controllers/DashboardController.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class DashboardController implements DashboardControllerType {
1515
/**
1616
* Retrieve the dashboard data.
1717
*/
18+
// eslint-disable-next-line @typescript-eslint/require-await
1819
async getDashboard(req: Request, res: Response) {
1920
const response = {
2021
demographics: {

server/src/controllers/GeographyController.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,23 @@ export class GeographyController implements GeographyControllerType {
1212
this.geographyRepository = geographyRepository;
1313
}
1414

15-
async getCountries(req: Request, res: Response, next: NextFunction): Promise<void> {
15+
async getCountries(req: Request, res: Response): Promise<void> {
1616
const query = (req.query.q as string) ?? '';
1717
const limit = Number.parseInt(req.query.limit as string) || null;
18-
try {
19-
const countries = await this.geographyRepository.searchCountry(query, limit);
20-
const jsonResponse = countries.map(({ name, flag }) => {
21-
return { name, flag };
22-
});
23-
res.json(jsonResponse);
24-
} catch (error) {
25-
next(error);
26-
}
18+
19+
const countries = await this.geographyRepository.searchCountry(query, limit);
20+
const jsonResponse = countries.map(({ name, flag }) => {
21+
return { name, flag };
22+
});
23+
res.json(jsonResponse);
2724
}
2825

29-
async getCities(req: Request, res: Response, next: NextFunction): Promise<void> {
26+
async getCities(req: Request, res: Response): Promise<void> {
3027
const query = (req.query.q as string) ?? '';
3128
const limit = Number.parseInt(req.query.limit as string) || null;
32-
try {
33-
const cities = await this.geographyRepository.searchCity(query, limit);
34-
const jsonResponse = cities.map((city) => city.name);
35-
res.json(jsonResponse);
36-
} catch (error) {
37-
next(error);
38-
}
29+
30+
const cities = await this.geographyRepository.searchCity(query, limit);
31+
const jsonResponse = cities.map((city) => city.name);
32+
res.json(jsonResponse);
3933
}
4034
}

server/src/controllers/SearchController.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,15 @@ export class SearchController implements SearchControllerType {
3131
this.traineesRepository = traineesRepository;
3232
}
3333

34-
async search(req: Request, res: Response, next: NextFunction) {
34+
async search(req: Request, res: Response) {
3535
const maxAllowedLimit = 50;
3636
const inputLimit = Number(req.query.limit) || 20;
3737
const limit = Math.min(inputLimit, maxAllowedLimit);
3838
const searchQuery: string = (req.query.q as string) ?? '';
3939

4040
let results: SearchResult[] = [];
41-
try {
42-
results = await this.getSearchResults(searchQuery, limit);
43-
} catch (error) {
44-
next(error);
45-
return;
46-
}
41+
42+
results = await this.getSearchResults(searchQuery, limit);
4743

4844
const response: SearchResponse = {
4945
hits: {
@@ -76,7 +72,7 @@ export class SearchController implements SearchControllerType {
7672
.map((trainee) => {
7773
return {
7874
id: trainee.id,
79-
name: `${trainee.displayName}`,
75+
name: trainee.displayName,
8076
thumbnail: trainee.thumbnailURL ?? null,
8177
cohort: trainee.educationInfo.currentCohort ?? null,
8278
profileURL: trainee.profileURL,

server/src/controllers/Trainee/EmploymentHistoryController.ts

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,27 @@ export interface EmploymentHistoryControllerType {
1212
export class EmploymentHistoryController implements EmploymentHistoryControllerType {
1313
constructor(private readonly traineesRepository: TraineesRepository) {}
1414

15-
async getEmploymentHistory(req: Request, res: Response, next: NextFunction): Promise<void> {
16-
try {
17-
const traineeID = req.params.id;
18-
const employmentHistory = await this.traineesRepository.getEmploymentHistory(traineeID);
19-
res.json(employmentHistory);
20-
} catch (error: any) {
21-
next(error);
22-
}
15+
async getEmploymentHistory(req: Request, res: Response): Promise<void> {
16+
const traineeID = req.params.id;
17+
const employmentHistory = await this.traineesRepository.getEmploymentHistory(traineeID);
18+
res.json(employmentHistory);
2319
}
2420

25-
async addEmploymentHistory(req: Request, res: Response, next: NextFunction): Promise<void> {
21+
async addEmploymentHistory(req: Request, res: Response): Promise<void> {
2622
const traineeID = req.params.id;
2723
const employmentHistoryData: EmploymentHistory = req.body;
2824
try {
2925
validateEmploymentHistory(employmentHistoryData);
30-
} catch (error: any) {
31-
res.status(400).send(new ResponseError(error.message));
26+
} catch (error) {
27+
if (error instanceof Error) res.status(400).send(new ResponseError(error.message));
3228
return;
3329
}
3430

35-
try {
36-
const newEmploymentHistory = await this.traineesRepository.addEmploymentHistory(traineeID, employmentHistoryData);
37-
res.status(201).json(newEmploymentHistory);
38-
} catch (error: any) {
39-
next(error);
40-
}
31+
const newEmploymentHistory = await this.traineesRepository.addEmploymentHistory(traineeID, employmentHistoryData);
32+
res.status(201).json(newEmploymentHistory);
4133
}
4234

43-
async updateEmploymentHistory(req: Request, res: Response, next: NextFunction): Promise<void> {
35+
async updateEmploymentHistory(req: Request, res: Response): Promise<void> {
4436
const trainee = await this.traineesRepository.getTrainee(req.params.id);
4537
if (!trainee) {
4638
res.status(404).send(new ResponseError('Trainee not found'));
@@ -69,41 +61,30 @@ export class EmploymentHistoryController implements EmploymentHistoryControllerT
6961

7062
try {
7163
validateEmploymentHistory(historyToUpdate);
72-
} catch (error: any) {
73-
res.status(400).send(new ResponseError(error.message));
64+
} catch (error) {
65+
if (error instanceof Error) res.status(400).send(new ResponseError(error.message));
7466
return;
7567
}
7668

77-
try {
78-
const updatedEmploymentHistory = await this.traineesRepository.updateEmploymentHistory(
79-
trainee.id,
80-
historyToUpdate
81-
);
69+
const updatedEmploymentHistory = await this.traineesRepository.updateEmploymentHistory(trainee.id, historyToUpdate);
8270

83-
res.json(updatedEmploymentHistory);
84-
} catch (error: any) {
85-
next(error);
86-
}
71+
res.json(updatedEmploymentHistory);
8772
}
8873

89-
async deleteEmploymentHistory(req: Request, res: Response, next: NextFunction): Promise<void> {
90-
try {
91-
const trainee = await this.traineesRepository.getTrainee(req.params.id);
92-
if (!trainee) {
93-
res.status(404).send(new ResponseError('Trainee not found'));
94-
return;
95-
}
96-
97-
const employmentHistoryID = req.params.employmentHistoryID;
98-
if (!trainee.employmentInfo.employmentHistory.find((history) => history.id === employmentHistoryID)) {
99-
res.status(404).send(new ResponseError('Employment history not found'));
100-
return;
101-
}
74+
async deleteEmploymentHistory(req: Request, res: Response): Promise<void> {
75+
const trainee = await this.traineesRepository.getTrainee(req.params.id);
76+
if (!trainee) {
77+
res.status(404).send(new ResponseError('Trainee not found'));
78+
return;
79+
}
10280

103-
await this.traineesRepository.deleteEmploymentHistory(trainee.id, employmentHistoryID);
104-
res.status(204).send();
105-
} catch (error: any) {
106-
next(error);
81+
const employmentHistoryID = req.params.employmentHistoryID;
82+
if (!trainee.employmentInfo.employmentHistory.find((history) => history.id === employmentHistoryID)) {
83+
res.status(404).send(new ResponseError('Employment history not found'));
84+
return;
10785
}
86+
87+
await this.traineesRepository.deleteEmploymentHistory(trainee.id, employmentHistoryID);
88+
res.status(204).send();
10889
}
10990
}

server/src/controllers/Trainee/InteractionController.ts

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,18 @@ export class InteractionController implements InteractionControllerType {
1717
private notificationService: NotificationService
1818
) {}
1919

20-
async getInteractions(req: Request, res: Response, next: NextFunction): Promise<void> {
20+
async getInteractions(req: Request, res: Response): Promise<void> {
2121
const trainee = await this.traineesRepository.getTrainee(req.params.id);
2222
if (!trainee) {
2323
res.status(404).send(new ResponseError('Trainee not found'));
2424
return;
2525
}
2626

27-
try {
28-
const interactions = await this.traineesRepository.getInteractions(trainee.id);
29-
res.status(200).json(interactions);
30-
} catch (error: any) {
31-
next(error);
32-
}
27+
const interactions = await this.traineesRepository.getInteractions(trainee.id);
28+
res.status(200).json(interactions);
3329
}
3430

35-
async addInteraction(req: Request, res: Response, next: NextFunction): Promise<void> {
31+
async addInteraction(req: Request, res: Response): Promise<void> {
3632
const trainee = await this.traineesRepository.getTrainee(req.params.id);
3733
if (!trainee) {
3834
res.status(404).send(new ResponseError('Trainee not found'));
@@ -51,21 +47,17 @@ export class InteractionController implements InteractionControllerType {
5147
if (!reporter) {
5248
throw new Error(`Invalid reporter ID ${reporterID}. User not found.`);
5349
}
54-
} catch (error: any) {
55-
res.status(400).send(new ResponseError(error.message));
50+
} catch (error) {
51+
if (error instanceof Error) res.status(400).send(new ResponseError(error.message));
5652
return;
5753
}
5854

59-
try {
60-
const interaction = await this.traineesRepository.addInteraction(req.params.id, newInteraction);
61-
res.status(201).json(interaction);
62-
this.notificationService.interactionCreated(trainee, interaction);
63-
} catch (error: any) {
64-
next(error);
65-
}
55+
const interaction = await this.traineesRepository.addInteraction(req.params.id, newInteraction);
56+
res.status(201).json(interaction);
57+
await this.notificationService.interactionCreated(trainee, interaction);
6658
}
6759

68-
async updateInteraction(req: Request, res: Response, next: NextFunction): Promise<void> {
60+
async updateInteraction(req: Request, res: Response): Promise<void> {
6961
const trainee = await this.traineesRepository.getTrainee(req.params.id);
7062
if (!trainee) {
7163
res.status(404).send(new ResponseError('Trainee not found'));
@@ -91,22 +83,16 @@ export class InteractionController implements InteractionControllerType {
9183
// Validate new interaction model after applying the changes
9284
try {
9385
validateInteraction(interactionToUpdate);
94-
} catch (error: any) {
95-
res.status(400).send(new ResponseError(error.message));
86+
} catch (error) {
87+
if (error instanceof Error) res.status(400).send(new ResponseError(error.message));
9688
return;
9789
}
9890

99-
try {
100-
const updatedInteraction = await this.traineesRepository.updateInteraction(req.params.id, interactionToUpdate);
101-
res.status(200).json(updatedInteraction);
102-
} catch (error: any) {
103-
console.error(error);
104-
next(error);
105-
return;
106-
}
91+
const updatedInteraction = await this.traineesRepository.updateInteraction(req.params.id, interactionToUpdate);
92+
res.status(200).json(updatedInteraction);
10793
}
10894

109-
async deleteInteraction(req: Request, res: Response, next: NextFunction): Promise<void> {
95+
async deleteInteraction(req: Request, res: Response): Promise<void> {
11096
const trainee = await this.traineesRepository.getTrainee(req.params.id);
11197
if (!trainee) {
11298
res.status(404).send(new ResponseError('Trainee not found'));
@@ -118,12 +104,7 @@ export class InteractionController implements InteractionControllerType {
118104
return;
119105
}
120106

121-
try {
122-
await this.traineesRepository.deleteInteraction(req.params.id, req.params.interactionID);
123-
res.status(204).end();
124-
} catch (error: any) {
125-
next(error);
126-
return;
127-
}
107+
await this.traineesRepository.deleteInteraction(req.params.id, req.params.interactionID);
108+
res.status(204).end();
128109
}
129110
}

0 commit comments

Comments
 (0)