-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move add round number logic to resolver chain
- Loading branch information
1 parent
af20cd4
commit fa5593d
Showing
4 changed files
with
84 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
services/app-api/src/resolvers/questionResponse/questionResolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import type { Resolvers } from '../../gen/gqlServer' | ||
|
||
import type { ContractQuestionType } from '../../domain-models' | ||
import type { Store } from '../../postgres' | ||
|
||
import { GraphQLError } from 'graphql' | ||
export function questionResolver(store: Store): Resolvers['QuestionResolver'] { | ||
return { | ||
round: async (parent: ContractQuestionType) => { | ||
const questions = await store.findAllQuestionsByContract( | ||
parent.contractID | ||
) | ||
if (questions instanceof Error) { | ||
const errMessage = `Issue finding contract message: ${questions.message}` | ||
|
||
throw new GraphQLError(errMessage, { | ||
extensions: { | ||
code: 'INTERNAL_SERVER_ERROR', | ||
cause: 'DB_ERROR', | ||
}, | ||
}) | ||
} | ||
|
||
const divisionQuestions = questions | ||
?.filter((q) => q.division === parent.division) | ||
.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime()) | ||
|
||
const matchingQuestion = divisionQuestions?.find( | ||
(question) => question.id == parent.id | ||
) | ||
|
||
if (!matchingQuestion) { | ||
return 0 | ||
} else { | ||
return divisionQuestions?.indexOf(matchingQuestion) !== | ||
undefined | ||
? divisionQuestions?.indexOf(matchingQuestion) + 1 | ||
: 0 | ||
} | ||
}, | ||
// responses: async (parent: any) => { | ||
// const questions = await store.findAllQuestionsByContract(parent.contractID) | ||
// if (questions instanceof Error) { | ||
// const errMessage = `Issue finding contract message: ${questions.message}` | ||
|
||
// throw new GraphQLError(errMessage, { | ||
// extensions: { | ||
// code: 'INTERNAL_SERVER_ERROR', | ||
// cause: 'DB_ERROR', | ||
// }, | ||
// }) | ||
// } | ||
|
||
// let round = 0 | ||
// const divisionQuestions = questions?. | ||
// filter((q) => q.division === parent.division). | ||
// sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime()) | ||
|
||
// const matchingQuestion = divisionQuestions?.find( | ||
// (question) => question.id == parent.id) | ||
|
||
// if (!matchingQuestion) { | ||
// round = 0 | ||
// } else { | ||
// divisionQuestions?.indexOf(matchingQuestion) !== undefined | ||
// ? round = divisionQuestions?.indexOf(matchingQuestion) + 1 | ||
// : round = 0 | ||
// } | ||
// const responses = parent.responses.map((res: any) => { | ||
// res.round = round | ||
// return round | ||
// }) | ||
// return responses | ||
// } | ||
} | ||
} |