Skip to content

Commit 52575b6

Browse files
committed
[add] Evaluation Score test cases
1 parent c66503f commit 52575b6

File tree

5 files changed

+192
-142
lines changed

5 files changed

+192
-142
lines changed

source/controller/Evaluation.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
} from '../model';
2626
import { searchConditionOf } from '../utility';
2727
import { ActivityLogController } from './ActivityLog';
28-
import { HackathonController } from './Hackathon';
2928

3029
const store = dataSource.getRepository(Evaluation),
3130
teamStore = dataSource.getRepository(Team);
@@ -53,18 +52,20 @@ export class EvaluationController {
5352
if (now < +new Date(hackathon.judgeStartedAt) || now > +new Date(hackathon.judgeEndedAt))
5453
throw new ForbiddenError('Not in evaluation period');
5554

56-
await HackathonController.ensureJudge(createdBy.id, name);
57-
5855
const saved = await store.save({
5956
...evaluation,
6057
team,
6158
hackathon: team.hackathon,
6259
createdBy
6360
});
6461
await ActivityLogController.logCreate(createdBy, 'Evaluation', saved.id);
65-
const dimensions = groupBy(evaluation.scores, 'dimension');
6662

67-
const scores = Object.values(dimensions).map(
63+
const allScores = (await store.findBy({ team: { id: tid } }))
64+
.map(({ scores }) => scores)
65+
.flat();
66+
const dimensionGroup = groupBy(allScores, 'dimension');
67+
68+
const scores = Object.values(dimensionGroup).map(
6869
(scores): Score => ({
6970
dimension: scores[0].dimension,
7071
score: sum(...scores.map(({ score }) => score)) / scores.length

source/controller/PlatformAdmin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
PlatformAdmin,
2121
PlatformAdminListChunk,
2222
Role,
23-
User} from '../model';
23+
User
24+
} from '../model';
2425
import { searchConditionOf } from '../utility';
2526
import { ActivityLogController } from './ActivityLog';
2627

source/model/Survey.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Column, Entity } from 'typeorm';
1212

1313
import { ListChunk } from './Base';
1414
import { HackathonBase } from './Hackathon';
15-
import { TeamBase } from './Team';
15+
import { Score, TeamBase } from './Team';
1616

1717
export enum QuestionType {
1818
Text = 'text',
@@ -82,19 +82,6 @@ export class Standard extends HackathonBase {
8282
dimensions: Dimension[];
8383
}
8484

85-
export class Score {
86-
@IsString()
87-
dimension: string;
88-
89-
@IsInt()
90-
@Min(0)
91-
score: number;
92-
93-
@IsString()
94-
@IsOptional()
95-
reason?: string;
96-
}
97-
9885
@Entity()
9986
export class Evaluation extends TeamBase {
10087
@Type(() => Score)

source/model/Team.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Transform, Type } from 'class-transformer';
22
import {
33
IsBoolean,
44
IsInt,
5+
IsNumber,
56
IsOptional,
6-
IsPositive,
77
IsString,
88
Min,
99
ValidateNested
@@ -12,7 +12,6 @@ import { Column, Entity, ManyToOne, VirtualColumn } from 'typeorm';
1212

1313
import { ListChunk } from './Base';
1414
import { HackathonBase } from './Hackathon';
15-
import { Score } from './Survey';
1615

1716
@Entity()
1817
export class Team extends HackathonBase {
@@ -41,10 +40,11 @@ export class Team extends HackathonBase {
4140
@Type(() => Score)
4241
@ValidateNested({ each: true })
4342
@IsOptional()
44-
@Column('simple-json', { default: [] })
43+
@Column('simple-json', { nullable: true })
4544
scores?: Score[] = [];
4645

47-
@IsPositive()
46+
@IsNumber()
47+
@Min(0)
4848
@IsOptional()
4949
@Column('float', { default: 0 })
5050
score?: number = 0;
@@ -68,3 +68,16 @@ export class TeamListChunk implements ListChunk<Team> {
6868
@ValidateNested({ each: true })
6969
list: Team[];
7070
}
71+
72+
export class Score {
73+
@IsString()
74+
dimension: string;
75+
76+
@IsInt()
77+
@Min(0)
78+
score: number;
79+
80+
@IsString()
81+
@IsOptional()
82+
reason?: string;
83+
}

0 commit comments

Comments
 (0)