fix reviews query

This commit is contained in:
João Geonizeli
2022-08-10 18:26:17 +00:00
parent f9fc5fc3a7
commit 483234de31
4 changed files with 42 additions and 39 deletions

View File

@@ -8,8 +8,7 @@ module Resolvers
def resolve def resolve
UserPolicy::Scope.new(@context[:current_user], User) UserPolicy::Scope.new(@context[:current_user], User)
.resolve .resolve
.joins(:roles) .where(roles: %i[teacher nde])
.where(roles: { name: %i[teacher nde] })
.where.not(id: @context[:current_user].id) .where.not(id: @context[:current_user].id)
.distinct .distinct
end end

View File

@@ -59,8 +59,13 @@ export const Form: FC<Props> = ({question, onSubmit, onDraftSubmit, alert}) => {
const [leaveDialogIsOpen, setLeaveDialogIsOpen] = useState(false) const [leaveDialogIsOpen, setLeaveDialogIsOpen] = useState(false)
const formHooks = useForm<FieldValues>({ const formHooks = useForm<FieldValues>({
defaultValues: { defaultValues: {
authorship: 'UNIFESO', authorship: question?.authorship ?? 'UNIFESO',
authorshipType: question?.authorship === 'UNIFESO' ? 'UNIFESO' : 'OTHER',
authorshipYear: new Date().getFullYear().toString(), authorshipYear: new Date().getFullYear().toString(),
difficulty: question?.difficulty,
checkType: question?.checkType,
bloomTaxonomy: question?.bloomTaxonomy,
intention: question?.intention,
} }
}) })
const {register, control, setValue, getValues, reset, formState, resetField} = formHooks const {register, control, setValue, getValues, reset, formState, resetField} = formHooks

View File

@@ -1,20 +1,23 @@
import React, { FC, useState } from "react";
import { gql } from "@apollo/client"; import { gql } from "@apollo/client";
import React, { FC, useState } from "react";
import { Card } from "../../../../../components"; import { Card } from "../../../../../components";
import { SubjectSelect, SubjectFragment } from "./SubjectSelect"; import { useFormProvider } from "../../FormContext";
import { ReviewerSelect, ReviewerFragment } from "./ReviewSelect"; import { ReviewerFragment, ReviewerSelect } from "./ReviewSelect";
import { useFormProvider } from '../../FormContext' import { SubjectFragment, SubjectSelect } from "./SubjectSelect";
import { BLOOM_TAXONOMY, CHECK_TYPE, DIFFICULTY } from "../../../../../utils/types"; import {
import { Question } from "../../../../../__generated__/graphql-schema"; BLOOM_TAXONOMY,
CHECK_TYPE,
DIFFICULTY,
} from "../../../../../utils/types";
export const FeaturesFragment = gql` export const FeaturesFragment = gql`
${ReviewerFragment} ${ReviewerFragment}
${SubjectFragment} ${SubjectFragment}
fragment FeaturesFields on Question { fragment FeaturesFields on Question {
... ReviewerFields ...ReviewerFields
... SubjectFields ...SubjectFields
authorship authorship
authorshipYear authorshipYear
difficulty difficulty
@@ -22,31 +25,24 @@ export const FeaturesFragment = gql`
intention intention
bloomTaxonomy bloomTaxonomy
} }
` `;
export const FeaturesFormStep: FC = () => { export const FeaturesFormStep: FC = () => {
const { question, hooks: { setValue, register, formState, getValues } } = useFormProvider(); const {
hooks: { setValue, register, getValues },
} = useFormProvider();
const currentYear = new Date().getFullYear(); const currentYear = new Date().getFullYear();
if (!question) return null const authorship = getValues("authorship");
const [ownQuestion, setOwnQuestion] = useState(authorship === "UNIFESO");
const {
difficulty,
bloomTaxonomy,
checkType,
} = question
const authorship = getValues('authorship')
const [ownQuestion, setOwnQuestion] = useState(authorship === "UNIFESO")
const handleOwnCheck = (value: string) => { const handleOwnCheck = (value: string) => {
if (value === 'UNIFESO') { if (value === "UNIFESO") {
setOwnQuestion(true) setOwnQuestion(true);
setValue("authorship", "UNIFESO"); setValue("authorship", "UNIFESO");
setValue("authorshipYear", currentYear.toString()); setValue("authorshipYear", currentYear.toString());
} else { } else {
setOwnQuestion(false) setOwnQuestion(false);
setValue("authorship", ""); setValue("authorship", "");
setValue("authorshipYear", ""); setValue("authorshipYear", "");
} }
@@ -62,23 +58,29 @@ export const FeaturesFormStep: FC = () => {
</label> </label>
<div className="my-auto"> <div className="my-auto">
<input <input
{...register("authorshipType", { required: true })}
value="UNIFESO"
className="my-auto" className="my-auto"
type="radio" type="radio"
id="authorship-own" id="authorship-own"
checked={!!ownQuestion}
onChange={() => handleOwnCheck("UNIFESO")} onChange={() => handleOwnCheck("UNIFESO")}
/> />
<label htmlFor="authorship-own" className="ml-1">Própria</label> <label htmlFor="authorship-own" className="ml-1">
Própria
</label>
</div> </div>
<div className="my-auto ml-3"> <div className="my-auto ml-3">
<input <input
{...register("authorshipType", { required: true })}
value="OTHER"
className="my-auto" className="my-auto"
type="radio" type="radio"
id="authorship-third" id="authorship-third"
checked={!ownQuestion}
onChange={() => handleOwnCheck("")} onChange={() => handleOwnCheck("")}
/> />
<label htmlFor="authorship-third" className="ml-1">Outro</label> <label htmlFor="authorship-third" className="ml-1">
Outro
</label>
</div> </div>
</div> </div>
<div className="flex"> <div className="flex">
@@ -87,7 +89,7 @@ export const FeaturesFormStep: FC = () => {
<div className="w-full"> <div className="w-full">
<div style={{ maxWidth: "194px" }}> <div style={{ maxWidth: "194px" }}>
<input <input
{...register('authorship')} {...register("authorship")}
className="block rounded p-1 w-full border-gray-400 border shadow-sm" className="block rounded p-1 w-full border-gray-400 border shadow-sm"
readOnly={!!ownQuestion} readOnly={!!ownQuestion}
/> />
@@ -98,7 +100,7 @@ export const FeaturesFormStep: FC = () => {
<h2 className="pr-2 pl-3 my-auto">Ano</h2> <h2 className="pr-2 pl-3 my-auto">Ano</h2>
<div style={{ maxWidth: "62px" }}> <div style={{ maxWidth: "62px" }}>
<input <input
{...register('authorshipYear')} {...register("authorshipYear")}
className="w-full rounded p-1 border-gray-400 border shadow-sm" className="w-full rounded p-1 border-gray-400 border shadow-sm"
type="number" type="number"
min="1999" min="1999"
@@ -116,9 +118,8 @@ export const FeaturesFormStep: FC = () => {
<div className="flex flex-col"> <div className="flex flex-col">
<h2>Grau de Dificuldade</h2> <h2>Grau de Dificuldade</h2>
<select <select
{...register('difficulty')} {...register("difficulty")}
className="w-full rounded p-1 border-gray-400 border shadow-sm" className="w-full rounded p-1 border-gray-400 border shadow-sm"
defaultValue={difficulty ?? ""}
> >
<option /> <option />
{DIFFICULTY.map((item, index) => ( {DIFFICULTY.map((item, index) => (
@@ -133,7 +134,6 @@ export const FeaturesFormStep: FC = () => {
<select <select
{...register("checkType")} {...register("checkType")}
className="w-full rounded p-1 border-gray-400 border shadow-sm" className="w-full rounded p-1 border-gray-400 border shadow-sm"
defaultValue={checkType ?? ""}
> >
<option /> <option />
{CHECK_TYPE.map((item, index) => ( {CHECK_TYPE.map((item, index) => (
@@ -146,9 +146,8 @@ export const FeaturesFormStep: FC = () => {
<div className="w-full"> <div className="w-full">
<h2>Habilidade Cognitiva</h2> <h2>Habilidade Cognitiva</h2>
<select <select
{...register('bloomTaxonomy')} {...register("bloomTaxonomy")}
className="w-full rounded p-1 border-gray-400 border shadow-sm" className="w-full rounded p-1 border-gray-400 border shadow-sm"
defaultValue={bloomTaxonomy ?? ""}
> >
<option /> <option />
{BLOOM_TAXONOMY.map((item, index) => ( {BLOOM_TAXONOMY.map((item, index) => (
@@ -168,7 +167,6 @@ export const FeaturesFormStep: FC = () => {
<textarea <textarea
{...register("intention")} {...register("intention")}
className="block rounded p-1 w-full border-gray-400 border shadow-sm" className="block rounded p-1 w-full border-gray-400 border shadow-sm"
defaultValue={question?.intention ?? ""}
/> />
</div> </div>
<div className="flex flex-col mt-4"> <div className="flex flex-col mt-4">

View File

@@ -12,4 +12,5 @@ export const formatInput = (inputs: any) =>
inputs.reviewerUserId === "" ? undefined : inputs.reviewerUserId, inputs.reviewerUserId === "" ? undefined : inputs.reviewerUserId,
alternatives: inputs.alternatives, alternatives: inputs.alternatives,
__nonused: undefined, __nonused: undefined,
authorshipType: undefined,
} as Question); } as Question);