add mutations to SG2; remove over-fetching fragment

Change-Id: I9af6c8accefa8805bd592896f9c81c1b3c021709
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/358355
Reviewed-by: Spencer Olson <solson@instructure.com>
QA-Review: Aaron Shafovaloff <ashafovaloff@instructure.com>
Product-Review: Aaron Shafovaloff <ashafovaloff@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
This commit is contained in:
Aaron Shafovaloff 2024-09-24 14:27:06 -06:00
parent 388d995568
commit 88c71e735d
4 changed files with 133 additions and 7 deletions

View File

@ -0,0 +1,33 @@
/*
* Copyright (C) 2024 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {z} from 'zod'
import doFetchApi from '@canvas/do-fetch-api-effect'
export const ZParams = z.object({
attachmentId: z.string(),
})
type Params = z.infer<typeof ZParams>
export function deleteAttachment(params: Params): Promise<unknown> {
ZParams.parse(params)
return doFetchApi({
path: `/api/v1/files/${params.attachmentId}?replace=1`,
method: 'DELETE',
})
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (C) 2024 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {z} from 'zod'
import doFetchApi from '@canvas/do-fetch-api-effect'
export const ZParams = z.object({
courseId: z.string(),
assignmentId: z.string(),
userId: z.string(),
})
type Params = z.infer<typeof ZParams>
export function reassignAssignmentMutation(params: Params): Promise<unknown> {
ZParams.parse(params)
return doFetchApi({
path: `/courses/${params.courseId}/assignments/${params.assignmentId}/submissions/${params.userId}/reassign`,
method: 'PUT',
})
}

View File

@ -0,0 +1,64 @@
/*
* Copyright (C) 2024 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import doFetchApi from '@canvas/do-fetch-api-effect'
import {RubricAssessmentData} from '@canvas/rubrics/react/types/rubric'
export default function saveRubricAssessementMutation(
assessments: RubricAssessmentData[],
userId: string
) {
// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {assessment_user_id, anonymous_id, assessment_type} = ENV.RUBRIC_ASSESSMENT ?? {}
// TODO: anonymous grading stuff here, see convertSubmittedAssessmentin RubricAssessmentContainerWrapper
// if (assessment_user_id) {
// data['rubric_assessment[user_id]'] = assessment_user_id
// } else {
// data['rubric_assessment[anonymous_id]'] = anonymous_id
// }
const rubric_assessment: Record<string, any> = {}
rubric_assessment.user_id = userId
rubric_assessment.assessment_type = assessment_type
assessments.forEach(assessment => {
const pre = `criterion_${assessment.criterionId}`
rubric_assessment[pre] = {}
rubric_assessment[pre].points = assessment.points
rubric_assessment[pre].comments = assessment.comments
rubric_assessment[pre].save_comment = assessment.saveCommentsForLater ? '1' : '0'
rubric_assessment[pre].description = assessment.description
if (assessment.id) {
rubric_assessment[pre].rating_id = assessment.id
}
})
const data: any = {rubric_assessment}
// TODO: moderated grading support here, see saveRubricAssessment in speed_grader.tsx
// TODO: anonymous grading support, see saveRubricAssessment in speed_grader.tsx
data.graded_anonymously = false
// @ts-expect-error
const url = window.ENV.update_rubric_assessment_url!
const method = 'POST'
return doFetchApi({
path: url,
method,
body: data,
})
}

View File

@ -19,7 +19,6 @@
import {z} from 'zod'
import {executeQuery} from '@canvas/query/graphql'
import gql from 'graphql-tag'
import {SUBMISSION_FRAGMENT} from '../queries/submissionQuery'
export const UPDATE_SUBMISSION_GRADE_STATUS = gql`
mutation updateSubmissionGradeStatus(
@ -35,13 +34,8 @@ export const UPDATE_SUBMISSION_GRADE_STATUS = gql`
latePolicyStatus: $latePolicyStatus
customGradeStatusId: $customGradeStatusId
}
) {
submission {
...SubmissionInterfaceFragment
}
}
)
}
${SUBMISSION_FRAGMENT}
`
export const ZUpdateSubmissionGradeStatusParams = z.object({