168 lines
4.5 KiB
TypeScript
168 lines
4.5 KiB
TypeScript
import client from "@/honoClient";
|
|
import fetchRPC from "@/utils/fetchRPC";
|
|
import { queryOptions, useMutation } from "@tanstack/react-query";
|
|
|
|
export const assessmentResultsQueryOptions = (page: number, limit: number, q?: string) =>
|
|
queryOptions({
|
|
queryKey: ["assessmentResults", { page, limit, q }],
|
|
queryFn: () =>
|
|
fetchRPC(
|
|
client.assessmentResult.$get({
|
|
query: {
|
|
limit: String(limit),
|
|
page: String(page),
|
|
q: q || "",
|
|
},
|
|
})
|
|
),
|
|
});
|
|
|
|
export const getAssessmentResultByIdQueryOptions = (assessmentResultId: string | undefined) =>
|
|
queryOptions({
|
|
queryKey: ["assessmentResults", assessmentResultId],
|
|
queryFn: () =>
|
|
fetchRPC(
|
|
client.assessmentResult[":id"].$get({
|
|
param: {
|
|
id: assessmentResultId!,
|
|
},
|
|
})
|
|
),
|
|
enabled: Boolean(assessmentResultId),
|
|
});
|
|
|
|
export const getVerifiedAssessmentResultByIdQueryOptions = (assessmentResultId: string | undefined) =>
|
|
queryOptions({
|
|
queryKey: ["verifiedAssessmentResult", assessmentResultId],
|
|
queryFn: () =>
|
|
fetchRPC(
|
|
client.assessmentResult.verified[":id"].$get({
|
|
param: {
|
|
id: assessmentResultId!,
|
|
},
|
|
})
|
|
),
|
|
enabled: Boolean(assessmentResultId),
|
|
});
|
|
|
|
export const postAnswerRevisionQueryOptions = (
|
|
assessmentId: string,
|
|
revisedBy: string,
|
|
) =>
|
|
queryOptions({
|
|
queryKey: ["answerRevisions", assessmentId],
|
|
queryFn: () =>
|
|
fetchRPC(
|
|
client.assessmentResult["answer-revisions"].$post({
|
|
json: {
|
|
assessmentId,
|
|
revisedBy,
|
|
},
|
|
})
|
|
),
|
|
enabled: Boolean(assessmentId && revisedBy),
|
|
});
|
|
|
|
export const postAnswerRevisionMutation = () => {
|
|
return useMutation({
|
|
mutationFn: ({ assessmentId, revisedBy }: { assessmentId: string; revisedBy: string }) => {
|
|
return fetchRPC(
|
|
client.assessmentResult["answer-revisions"].$post({
|
|
json: {
|
|
assessmentId,
|
|
revisedBy,
|
|
},
|
|
})
|
|
);
|
|
},
|
|
onSuccess: () => {
|
|
console.log("Revision posted successfully.");
|
|
// Optionally, you could trigger a refetch of relevant data here
|
|
},
|
|
onError: (error: any) => {
|
|
console.error("Error posting revision:", error);
|
|
},
|
|
});
|
|
};
|
|
|
|
// Query untuk mendapatkan jawaban berdasarkan assessment ID
|
|
export const getAnswersRevisionQueryOptions = (
|
|
assessmentId: string,
|
|
) => {
|
|
return queryOptions({
|
|
queryKey: ["answerRevision", { assessmentId }],
|
|
queryFn: () =>
|
|
fetchRPC(
|
|
client.assessmentResult.getAnswers[":id"].$get({
|
|
param: { id: assessmentId },
|
|
})
|
|
),
|
|
});
|
|
};
|
|
|
|
export const updateValidationQueryOptions = (assessmentId: string, questionId: string, newValidationInformation: string) => {
|
|
return queryOptions({
|
|
queryKey: ["updateValidation", { assessmentId, questionId }],
|
|
queryFn: () =>
|
|
fetchRPC(
|
|
client.assessmentResult.updateValidation.$post({
|
|
json: {
|
|
assessmentId,
|
|
questionId,
|
|
newValidationInformation,
|
|
},
|
|
})
|
|
),
|
|
enabled: Boolean(assessmentId && questionId && newValidationInformation),
|
|
});
|
|
};
|
|
|
|
export const updateValidationQuery = async (
|
|
form: {
|
|
assessmentId: string;
|
|
questionId: string;
|
|
newValidationInformation: string;
|
|
}
|
|
) => {
|
|
return await fetchRPC(
|
|
client.assessmentResult.updateValidation.$post({
|
|
json: {
|
|
...form,
|
|
assessmentId: String(form.assessmentId),
|
|
questionId: String(form.questionId),
|
|
newValidationInformation: form.newValidationInformation,
|
|
},
|
|
})
|
|
);
|
|
};
|
|
|
|
export const updateOptionQuery = async (
|
|
form: {
|
|
assessmentId: string;
|
|
questionId: string;
|
|
optionId: string;
|
|
}
|
|
) => {
|
|
return await fetchRPC(
|
|
client.assessments.updateOption.$patch({
|
|
json: {
|
|
...form,
|
|
assessmentId: String(form.assessmentId),
|
|
questionId: String(form.questionId),
|
|
newOptionId: form.optionId,
|
|
},
|
|
})
|
|
);
|
|
};
|
|
|
|
export const submitAssessmentRevision = async (assessmentId: string): Promise<{ message: string }> => {
|
|
return await fetchRPC(
|
|
client.assessmentResult.submitAssessmentRevision[":id"].$patch({
|
|
param: { id: assessmentId },
|
|
})
|
|
);
|
|
};
|
|
|
|
export const submitAssessmentRevisionMutationOptions = (assessmentId: string) => ({
|
|
mutationFn: () => submitAssessmentRevision(assessmentId),
|
|
}); |