@@ -6,17 +6,20 @@ import {
6
6
} from "../utils/pagination" ;
7
7
import { validateFilterRequest } from "../utils/validate" ;
8
8
import { errorResponse } from "./utils" ;
9
- import { GradingJobRequestError } from "./exceptions" ;
10
- import getAllGradingJobs from "../grading-queue/queries/get-grading-jobs" ;
11
9
import {
12
10
GradingJob ,
13
- GradingQueueOperationError ,
14
11
filterGradingJobs ,
15
12
getFilterInfo ,
16
13
getGradingQueueStats ,
17
14
validations ,
18
15
} from "@codegrade-orca/common" ;
19
- import mutations from "../grading-queue/mutations" ;
16
+ import {
17
+ deleteJob as deleteJobInQueue ,
18
+ createOrUpdateJob as putJobInQueue ,
19
+ getAllGradingJobs ,
20
+ GradingQueueOperationException
21
+ } from "@codegrade-orca/db" ;
22
+ import { isNaN } from "lodash" ;
20
23
21
24
export const getGradingJobs = async ( req : Request , res : Response ) => {
22
25
if (
@@ -89,7 +92,7 @@ export const getGradingJobs = async (req: Request, res: Response) => {
89
92
filter_info : filterInfo ,
90
93
} ) ;
91
94
} catch ( err ) {
92
- if ( err instanceof GradingQueueOperationError ) {
95
+ if ( err instanceof GradingQueueOperationException ) {
93
96
return errorResponse ( res , 400 , [ err . message ] ) ;
94
97
}
95
98
return errorResponse ( res , 500 , [
@@ -108,11 +111,11 @@ export const createOrUpdateImmediateJob = async (
108
111
const gradingJobConfig = req . body ;
109
112
110
113
try {
111
- await mutations . createOrUpdateJob ( gradingJobConfig , Date . now ( ) , true ) ;
114
+ await putJobInQueue ( req . body , true ) ;
112
115
return res . status ( 200 ) . json ( { message : "OK" } ) ;
113
116
} catch ( error ) {
114
117
console . error ( error ) ;
115
- if ( error instanceof GradingQueueOperationError ) {
118
+ if ( error instanceof GradingQueueOperationException ) {
116
119
return errorResponse ( res , 400 , [ error . message ] ) ;
117
120
}
118
121
return errorResponse ( res , 500 , [
@@ -127,13 +130,12 @@ export const createOrUpdateJob = async (req: Request, res: Response) => {
127
130
return errorResponse ( res , 400 , [ "The given grading job was invalid." ] ) ;
128
131
}
129
132
130
- const gradingJobConfig = req . body ;
131
-
132
133
try {
133
- await mutations . createOrUpdateJob ( gradingJobConfig , Date . now ( ) , false ) ;
134
+ await putJobInQueue ( req . body , false ) ;
134
135
return res . status ( 200 ) . json ( { message : "OK" } ) ;
135
136
} catch ( err ) {
136
- if ( err instanceof GradingQueueOperationError ) {
137
+ console . error ( err ) ;
138
+ if ( err instanceof GradingQueueOperationException ) {
137
139
return errorResponse ( res , 400 , [ err . message ] ) ;
138
140
} else {
139
141
return errorResponse ( res , 500 , [
@@ -143,34 +145,27 @@ export const createOrUpdateJob = async (req: Request, res: Response) => {
143
145
}
144
146
} ;
145
147
146
- export const moveJob = async ( req : Request , res : Response ) => {
147
- if ( ! validations . moveJobRequest ( req . body ) ) {
148
- errorResponse ( res , 400 , [ "Invalid move request." ] ) ;
149
- return ;
150
- }
151
- try {
152
- await mutations . moveJob ( req . body ) ;
153
- return res . status ( 200 ) . json ( "OK" ) ;
154
- } catch ( err ) {
155
- if ( err instanceof GradingQueueOperationError ) {
156
- return errorResponse ( res , 500 , [ err . message ] ) ;
157
- }
158
- return errorResponse ( res , 500 , [
159
- `An error occurred while trying to move job with key ${ req . body . orcaKey } .` ,
160
- ] ) ;
161
- }
148
+ export const moveJob = async ( _req : Request , res : Response ) => {
149
+ return errorResponse ( res , 500 , [ "Functionality to move a job remains to be implemented. " +
150
+ "Please contact [email protected] for more info." ] ) ;
151
+ // if (!validations.moveJobRequest(req.body)) {
152
+ // errorResponse(res, 400, ["Invalid move request."]);
153
+ // return;
154
+ // }
162
155
} ;
163
156
164
157
export const deleteJob = async ( req : Request , res : Response ) => {
165
- if ( ! validations . deleteJobRequest ( req . body ) ) {
166
- return errorResponse ( res , 400 , [ "Invalid delete request." ] ) ;
167
- }
158
+ const { jobID : rawJobID } = req . params ;
168
159
try {
169
- await mutations . deleteJob ( req . body ) ;
160
+ const jobID = parseInt ( rawJobID ) ;
161
+ if ( isNaN ( jobID ) ) {
162
+ return errorResponse ( res , 400 , [ "Given job ID is not a number." ] ) ;
163
+ }
164
+ await deleteJobInQueue ( jobID ) ;
170
165
return res . status ( 200 ) . json ( { message : "OK" } ) ;
171
166
} catch ( err ) {
172
- if ( err instanceof GradingQueueOperationError ) {
173
- return errorResponse ( res , 500 , [ err . message ] ) ;
167
+ if ( err instanceof GradingQueueOperationException ) {
168
+ return errorResponse ( res , 400 , [ err . message ] ) ;
174
169
} else {
175
170
return errorResponse ( res , 500 , [
176
171
`Something went wrong when trying to delete job with key ${ req . body . orcaKey } .` ,
0 commit comments