Skip to content

Commit e86031c

Browse files
committed
lint
1 parent 7d5554e commit e86031c

12 files changed

Lines changed: 51 additions & 33 deletions

File tree

backend/src/entities/longtext.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { Column } from "typeorm";
22

3+
/**
4+
* mariadb longtext, and for in-memory sqlite regular text
5+
*/
36
export function Longtext() {
47
// Sqlite doesn't support longtext. I hate this, but it is what it is if we want
58
// to keep backend tests and prepare tilt for the upcoming Hackaburg as quickly

backend/src/services/config-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ export class ConfigurationService implements IConfigurationService {
102102
const { error } = dotenv.config();
103103

104104
if (error) {
105-
// tslint:disable-next-line: no-console
106105
// Make sure your cwd is the backend directory, which contains the .env file,
107106
// and that .env.example has been copied to .env
107+
// tslint:disable-next-line: no-console
108108
console.warn(`error loading .env configuration: ${error}`);
109109
}
110110
}

backend/src/services/criterion-service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { DatabaseServiceToken, IDatabaseService } from "./database-service";
66
import { CriterionDTO, convertBetweenEntityAndDTO } from "../controllers/dto";
77
import { Criterion } from "../entities/criterion";
88

9+
/**
10+
* A service to handle criteria.
11+
*/
912
export interface ICriterionService extends IService {
1013
/**
1114
* Get all criteria

backend/src/services/project-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class ProjectService implements IProjectService {
7373

7474
const [settings] = await this._settings.find();
7575
const allowRatingProjects = settings.application.allowRatingProjects;
76-
const isAdmin = user.role == UserRole.Root;
76+
const isAdmin = user.role === UserRole.Root;
7777

7878
const projects = await this._projects.find();
7979
return projects.filter((project) => {

backend/src/services/rating-service.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import { Project } from "../entities/project";
1616
import { Criterion } from "../entities/criterion";
1717
import { UserRole } from "../entities/user-role";
1818

19+
/**
20+
* A service to handle rating entities.
21+
*/
1922
export interface IRatingService extends IService {
2023
/**
2124
* Get the ratings for a specific project, cast by a specific user.
@@ -49,7 +52,7 @@ export interface IRatingService extends IService {
4952
export const RatingServiceToken = new Token<IRatingService>();
5053

5154
/**
52-
* A service to handle users.
55+
* A service to handle rating entities.
5356
*/
5457
@Service(RatingServiceToken)
5558
export class RatingService implements IRatingService {
@@ -63,7 +66,7 @@ export class RatingService implements IRatingService {
6366
) {}
6467

6568
/**
66-
* Sets up the user service.
69+
* Sets up the rating service.
6770
*/
6871
public async bootstrap(): Promise<void> {
6972
this._ratings = this._database.getRepository(Rating);
@@ -172,12 +175,12 @@ export class RatingService implements IRatingService {
172175
const allProjects = await this._projects.find();
173176
const allRatings = await this._ratings.find();
174177

175-
const result = [];
178+
const result: ProjectRatingResultDTO[] = [];
176179

177180
const idToCriterion: Record<number, Criterion> = {};
178181

179182
for (const project of allProjects) {
180-
const averagesPerCriterion = [];
183+
const averagesPerCriterion: { criterion: Criterion, average: number }[] = [];
181184

182185
// Sum up
183186
const criterionIdToSum: Record<number, number> = {};
@@ -200,12 +203,17 @@ export class RatingService implements IRatingService {
200203
}
201204

202205
// Calculate average
203-
for (const criterionId in criterionIdToSum) {
204-
const average =
205-
criterionIdToSum[criterionId] / criterionIdToCount[criterionId];
206+
Object.keys(criterionIdToSum).map(Number).forEach(criterionId => {
207+
const count = criterionIdToCount[criterionId]
208+
if (count === 0) {
209+
return
210+
}
211+
212+
const sum = criterionIdToSum[criterionId]
213+
const average = sum / count;
206214
const criterion = idToCriterion[criterionId];
207215
averagesPerCriterion.push({ criterion, average });
208-
}
216+
});
209217

210218
result.push({
211219
project,

frontend/src/components/base/image.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import styled from "@emotion/styled";
22
import * as React from "react";
3+
import { borderRadius } from "../../config";
34

45
const Img = styled.img`
56
max-width: 100%;
@@ -17,6 +18,9 @@ export const Image = ({ src, label }: IImageProps) => (
1718
<Img src={src} alt={label} />
1819
);
1920

21+
/**
22+
* An image with rounded corners.
23+
*/
2024
export const RoundedImage = styled.img`
21-
border-radius: 5px;
25+
border-radius: ${borderRadius};
2226
`;

frontend/src/components/pages/projects.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ const RatingResults = () => {
3737
const [criteria, setCriteria] = React.useState<CriterionDTO[]>([]);
3838

3939
useEffect(() => {
40-
api.getRatingResults().then((stuff) => {
41-
setRatingResults([...stuff]);
40+
api.getRatingResults().then((ratingResults_) => {
41+
setRatingResults([...ratingResults_]);
4242
});
4343

44-
api.getAllCriteria().then((criteria) => {
45-
setCriteria([...criteria]);
44+
api.getAllCriteria().then((criteria_) => {
45+
setCriteria([...criteria_]);
4646
});
4747
}, []);
4848

@@ -77,7 +77,7 @@ const RatingResults = () => {
7777
<TableCell key={criterion.id} align="center">
7878
{
7979
resultForProject.averagesPerCriterion.find(
80-
(a) => a.criterion.id == criterion.id,
80+
(a) => a.criterion.id === criterion.id,
8181
)?.average
8282
}
8383
</TableCell>

frontend/src/components/pages/rating-form.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ export const RatingForm = ({
4848
setError(null);
4949

5050
await api.createRating({
51-
criterion: criterion,
52-
rating: parseInt(ratingValue ?? "0"),
51+
criterion,
52+
rating: parseInt(ratingValue ?? "0", 10),
5353
user: user!,
54-
project: project,
54+
project,
5555
} as unknown as RatingDTO);
5656

5757
setIsSubmitting(false);

frontend/src/components/pages/read-only-project.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export const ReadOnlyProject = ({ project }: { project: ProjectDTO }) => {
1515
const [ratings, setRatings] = React.useState<RatingDTO[]>([]);
1616

1717
React.useEffect(() => {
18-
api.getAllCriteria().then((criteria) => {
19-
setCriteria([...criteria]);
18+
api.getAllCriteria().then((criteria_) => {
19+
setCriteria([...criteria_]);
2020
});
2121

2222
if (project) {
23-
api.getUsersRatingsForProject(project).then((ratings) => {
24-
setRatings([...ratings]);
23+
api.getUsersRatingsForProject(project).then((ratings_) => {
24+
setRatings([...ratings_]);
2525
});
2626
}
2727
}, [project]);
@@ -49,7 +49,7 @@ export const ReadOnlyProject = ({ project }: { project: ProjectDTO }) => {
4949
think the project did well in this regard.
5050
{criteria.map((criterion) => (
5151
<RatingForm
52-
rating={ratings.find((r) => r.criterion.id == criterion.id)}
52+
rating={ratings.find((r) => r.criterion.id === criterion.id)}
5353
criterion={criterion}
5454
project={project}
5555
/>

frontend/src/components/pages/view-project.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const ViewProject = () => {
2323
const params = new URLSearchParams(document.location.search);
2424
const projectId = Number(params.get("id"));
2525
React.useEffect(() => {
26-
api.getProjectByID(projectId).then((project) => setProject(project));
26+
api.getProjectByID(projectId).then((project_) => setProject(project_));
2727
}, []);
2828

2929
const isTeamMember = React.useMemo(() => {
@@ -32,7 +32,7 @@ export const ViewProject = () => {
3232
);
3333
}, [project, user?.id]);
3434

35-
const isAdmin = user?.role == UserRole.Root;
35+
const isAdmin = user?.role === UserRole.Root;
3636

3737
if (!project) {
3838
return null;
@@ -82,7 +82,7 @@ const EditProject = ({ project }: { project: ProjectDTO }) => {
8282
event.preventDefault();
8383
}, []);
8484

85-
const isAdmin = user?.role == UserRole.Root;
85+
const isAdmin = user?.role === UserRole.Root;
8686

8787
return (
8888
<Page>

0 commit comments

Comments
 (0)