@@ -8,10 +8,11 @@ import {
8
8
} from '@nestjs/common' ;
9
9
import { InjectRepository } from '@nestjs/typeorm' ;
10
10
import { Cache } from 'cache-manager' ;
11
- import { isUUID } from 'class-validator' ;
12
11
import { TypedJSON } from 'typedjson' ;
13
12
import { Repository } from 'typeorm' ;
14
13
import { BenchmarkService } from '../benchmarks/benchmark.service' ;
14
+ import { User } from '../users/user.entity' ;
15
+ import { FindLastSubmissionByLanguageDTO } from './dto/find-last-submission-by-language.dto' ;
15
16
import { FindSubmissionDTO } from './dto/find-submission.dto' ;
16
17
import { InsertSubmissionDTO } from './dto/insert-submission-dto' ;
17
18
import { JobStatusDTO } from './dto/job-status.dto' ;
@@ -31,21 +32,13 @@ export class SubmissionsService {
31
32
const submission = new Submission ( insertSubmissionDTO ) ;
32
33
submission . status = 'waiting' ;
33
34
34
- if ( ! isUUID ( insertSubmissionDTO . benchmarkId ) ) {
35
- throw new BadRequestException (
36
- `Invalid benchmark id: ${ insertSubmissionDTO . benchmarkId } ` ,
37
- ) ;
38
- }
39
- const benchmark = await this . benchmarkService . findOne ( {
40
- id : insertSubmissionDTO . benchmarkId ,
41
- } ) ;
35
+ const benchmark = await this . benchmarkService . findOne (
36
+ insertSubmissionDTO . benchmarkId ,
37
+ ) ;
42
38
43
- if ( ! benchmark ) {
44
- throw new BadRequestException (
45
- `Could not find benchmark: ${ insertSubmissionDTO . benchmarkId } ` ,
46
- ) ;
39
+ if ( benchmark ) {
40
+ submission . benchmark = benchmark ;
47
41
}
48
- submission . benchmark = benchmark ;
49
42
50
43
return submission . save ( ) ;
51
44
}
@@ -124,4 +117,36 @@ export class SubmissionsService {
124
117
}
125
118
}
126
119
}
120
+
121
+ async findLastByLanguage (
122
+ filter : FindLastSubmissionByLanguageDTO ,
123
+ requestUser : User ,
124
+ ) : Promise < Submission | undefined > {
125
+ const bench = await this . benchmarkService . findOne ( filter . benchmarkId ) ;
126
+ const matchedLanguage = await this . languageMatcher ( filter . language ) ;
127
+
128
+ if ( ! matchedLanguage ) {
129
+ throw new BadRequestException ( `Invalid language: ${ filter . language } ` ) ;
130
+ }
131
+
132
+ return this . submissionsRepository . findOne ( {
133
+ where : [
134
+ {
135
+ user : requestUser ,
136
+ benchmark : bench ,
137
+ language : matchedLanguage ,
138
+ } ,
139
+ ] ,
140
+ order : { createdAt : 'DESC' } ,
141
+ } ) ;
142
+ }
143
+
144
+ async languageMatcher ( language : string ) : Promise < string | undefined > {
145
+ switch ( language ) {
146
+ case 'python' :
147
+ return 'cpython3' ;
148
+ default :
149
+ return undefined ;
150
+ }
151
+ }
127
152
}
0 commit comments