Skip to content

Commit e3e5d63

Browse files
authored
Merge pull request #254 from makeopensource/revert-249-94-metadata-assigment-problem
Revert "94 metadata assignment problem"
2 parents a228a52 + 6dd562a commit e3e5d63

18 files changed

+44
-191
lines changed

devU-api/src/entities/assignment/assignment.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ async function processFiles(req: Request) {
114114
} else {
115115
console.warn(`Files where not in array format ${req.files}`)
116116
}
117+
} else {
118+
console.warn(`No files where processed`)
117119
}
118120

119121
return { fileHashes, fileNames }

devU-api/src/entities/assignmentProblem/assignmentProblem.controller.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NextFunction, Request, Response } from 'express'
1+
import { Request, Response, NextFunction } from 'express'
22

33
import AssignmentProblemService from './assignmentProblem.service'
44

@@ -33,21 +33,15 @@ export async function detail(req: Request, res: Response, next: NextFunction) {
3333
}
3434
}
3535

36-
export async function post(req: Request, res: Response, _: NextFunction) {
36+
export async function post(req: Request, res: Response, next: NextFunction) {
3737
try {
38-
req.body.assignmentId = parseInt(req.params.assignmentId)
39-
const assignmentProblem = await AssignmentProblemService.create(
40-
req.body.assignmentId,
41-
req.body.problemName,
42-
req.body.maxScore,
43-
req.body.metadata,
44-
)
38+
const assignmentProblem = await AssignmentProblemService.create(req.body)
4539
const response = serialize(assignmentProblem)
4640

4741
res.status(201).json(response)
4842
} catch (err) {
4943
if (err instanceof Error) {
50-
res.status(400).json(new GenericResponse(err.message))
44+
res.status(400).json(new GenericResponse(err.message))
5145
}
5246
}
5347
}

devU-api/src/entities/assignmentProblem/assignmentProblem.model.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ export default class AssignmentProblemModel {
2828
* type: integer
2929
* problemName:
3030
* type: string
31-
* metadata:
32-
* type: string
33-
* description: A json string containing additional problem metadata
3431
* maxScore:
3532
* type: integer
3633
*/
@@ -46,9 +43,6 @@ export default class AssignmentProblemModel {
4643
@Column({ name: 'problem_name', length: 128 })
4744
problemName: string
4845

49-
@Column({ name: 'metadata', type: 'jsonb', nullable: true, default: {} })
50-
metadata: any // use any since this can be any arbitrary structure
51-
5246
@Column({ name: 'max_score' })
5347
maxScore: number
5448

devU-api/src/entities/assignmentProblem/assignmentProblem.router.ts

Lines changed: 3 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,6 @@ const Router = express.Router({ mergeParams: true })
2121
* responses:
2222
* '200':
2323
* description: OK
24-
* content:
25-
* application/json:
26-
* schema:
27-
* type: array
28-
* items:
29-
* type: object
30-
* properties:
31-
* id:
32-
* type: integer
33-
* assignmentId:
34-
* type: integer
35-
* problemName:
36-
* type: string
37-
* metadata:
38-
* type: string
39-
* description: A json string containing additional problem metadata
40-
* maxScore:
41-
* type: integer
4224
* parameters:
4325
* - name: assignmentId
4426
* description: Enter Assignment Id
@@ -61,22 +43,6 @@ Router.get('/', isAuthorized('enrolled'), AssignmentProblemController.get)
6143
* responses:
6244
* '200':
6345
* description: OK
64-
* content:
65-
* application/json:
66-
* schema:
67-
* type: object
68-
* properties:
69-
* id:
70-
* type: integer
71-
* assignmentId:
72-
* type: integer
73-
* problemName:
74-
* type: string
75-
* metadata:
76-
* type: string
77-
* description: A json string containing additional problem metadata
78-
* maxScore:
79-
* type: integer
8046
* parameters:
8147
* - name: id
8248
* description: Enter AssignmentProblem Id
@@ -97,33 +63,8 @@ Router.get('/:id', isAuthorized('assignmentEditAll'), asInt(), AssignmentProblem
9763
* tags:
9864
* - AssignmentProblems
9965
* responses:
100-
* '201':
101-
* description: Created
102-
* content:
103-
* application/json:
104-
* schema:
105-
* type: object
106-
* properties:
107-
* id:
108-
* type: integer
109-
* assignmentId:
110-
* type: integer
111-
* problemName:
112-
* type: string
113-
* metadata:
114-
* type: string
115-
* description: A json string containing additional problem metadata
116-
* maxScore:
117-
* type: integer
118-
* '400':
119-
* description: Bad Request
120-
* content:
121-
* application/json:
122-
* schema:
123-
* type: object
124-
* properties:
125-
* message:
126-
* type: string
66+
* '200':
67+
* description: OK
12768
* requestBody:
12869
* content:
12970
* application/x-www-form-urlencoded:
@@ -134,37 +75,14 @@ Router.post('/', isAuthorized('assignmentEditAll'), validator, AssignmentProblem
13475

13576
/**
13677
* @swagger
137-
* /course/:courseId/assignment/:assignmentId/assignment-problems/{id}:
78+
* /course/:courseId/assignment/:assignmentId/assignment-problems:
13879
* put:
13980
* summary: Update an assignment problem
14081
* tags:
14182
* - AssignmentProblems
14283
* responses:
14384
* '200':
14485
* description: OK
145-
* content:
146-
* application/json:
147-
* schema:
148-
* type: object
149-
* properties:
150-
* message:
151-
* type: string
152-
* '404':
153-
* description: Not Found
154-
* content:
155-
* application/json:
156-
* schema:
157-
* type: object
158-
* properties:
159-
* message:
160-
* type: string
161-
* parameters:
162-
* - name: id
163-
* description: Enter AssignmentProblem Id
164-
* in: path
165-
* required: true
166-
* schema:
167-
* type: integer
16886
* requestBody:
16987
* content:
17088
* application/x-www-form-urlencoded:

devU-api/src/entities/assignmentProblem/assignmentProblem.serializer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export function serialize(assignmentProblem: AssignmentProblemModel): Assignment
88
assignmentId: assignmentProblem.assignmentId,
99
problemName: assignmentProblem.problemName,
1010
maxScore: assignmentProblem.maxScore,
11-
metadata: assignmentProblem.metadata,
1211
createdAt: assignmentProblem.createdAt.toISOString(),
1312
updatedAt: assignmentProblem.updatedAt.toISOString(),
1413
}

devU-api/src/entities/assignmentProblem/assignmentProblem.service.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { AssignmentProblem } from 'devu-shared-modules'
77

88
const connect = () => dataSource.getRepository(AssignmentProblemModel)
99

10+
export async function create(assignmentProblem: AssignmentProblem) {
11+
return await connect().save(assignmentProblem)
12+
}
13+
1014
export async function update(assignmentProblem: AssignmentProblem) {
1115
const { id, assignmentId, problemName, maxScore } = assignmentProblem
1216
if (!id) throw new Error('Missing Id')
@@ -26,26 +30,10 @@ export async function list(assignmentId: number) {
2630
return await connect().findBy({ assignmentId: assignmentId, deletedAt: IsNull() })
2731
}
2832

29-
export async function create(
30-
assignmentId: number,
31-
problemName: string,
32-
maxScore: number,
33-
metadata?: any,
34-
) {
35-
const assignmentProblem = <AssignmentProblemModel>{
36-
assignmentId: assignmentId,
37-
problemName: problemName,
38-
maxScore: maxScore,
39-
metadata: metadata,
40-
}
41-
42-
return await connect().save(assignmentProblem)
43-
}
44-
4533
export default {
34+
create,
4635
retrieve,
4736
update,
4837
_delete,
4938
list,
50-
create,
5139
}

devU-api/src/entities/assignmentProblem/assignmentProblem.validator.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import validate from '../../middleware/validator/generic.validator'
55
const assignmentId = check('assignmentId').isNumeric()
66
const problemName = check('problemName').isString().trim().isLength({ max: 128 })
77
const maxScore = check('maxScore').isNumeric()
8-
const metadata = check('metadata')
9-
.optional({ nullable: true })
10-
.isObject()
11-
.default({})
128

13-
const validator = [assignmentId, problemName, maxScore, metadata, validate]
9+
const validator = [assignmentId, problemName, maxScore, validate]
1410

1511
export default validator

devU-api/src/entities/nonContainerAutoGrader/nonContainerAutoGrader.controller.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,7 @@ export async function detail(req: Request, res: Response, next: NextFunction) {
4242

4343
export async function post(req: Request, res: Response, next: NextFunction) {
4444
try {
45-
req.body.assignmentId = parseInt(req.params.assignmentId)
46-
const nonContainer = await NonContainerAutoGraderService.create(
47-
req.body.assignmentId,
48-
req.body.question,
49-
req.body.score,
50-
req.body.isRegex,
51-
req.body.correctString
52-
)
45+
const nonContainer = await NonContainerAutoGraderService.create(req.body)
5346
const response = serialize(nonContainer)
5447

5548
res.status(201).json(response)

devU-api/src/entities/nonContainerAutoGrader/nonContainerAutoGrader.model.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export default class NonContainerAutoGraderModel {
2727
* type: integer
2828
* question:
2929
* type: string
30+
* metadata:
31+
* type: any
32+
* description: this contains a valid json string tha contains info about any arbitrary question type (MCQ, Fill in the blanks etc.)
3033
* score:
3134
* type: number
3235
* correctString:
@@ -53,6 +56,9 @@ export default class NonContainerAutoGraderModel {
5356
@Column({ name: 'question', length: 128 })
5457
question: string
5558

59+
@Column({ name: 'metadata', type: 'jsonb', nullable: true, default: {} })
60+
metadata: any // use any since this can be any arbitrary structure
61+
5662
@Column({ name: 'score' })
5763
score: number
5864

devU-api/src/entities/nonContainerAutoGrader/nonContainerAutoGrader.serializer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ export function serialize(nonContainerAutoGrader: NonContainerAutoGraderModel):
88
assignmentId: nonContainerAutoGrader.assignmentId,
99
question: nonContainerAutoGrader.question,
1010
score: nonContainerAutoGrader.score,
11-
isRegex: nonContainerAutoGrader.isRegex,
11+
metadata: JSON.stringify(nonContainerAutoGrader.metadata ?? ''),
1212
correctString: nonContainerAutoGrader.correctString,
13+
isRegex: nonContainerAutoGrader.isRegex,
1314
createdAt: nonContainerAutoGrader.createdAt.toISOString(),
1415
updatedAt: nonContainerAutoGrader.updatedAt.toISOString(),
1516
}

0 commit comments

Comments
 (0)