-
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.
MCR-4449: Rate create rate question response api (#2824)
* Add create rate response mutation and schema changes * More renaming question to contractQuestion * create rate question response postgres functions * create rate question response resolver and tests * A comment.
- Loading branch information
1 parent
037d7ff
commit ea1997e
Showing
20 changed files
with
398 additions
and
32 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
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
55 changes: 55 additions & 0 deletions
55
services/app-api/src/postgres/questionResponse/insertRateQuestionResponse.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,55 @@ | ||
import type { PrismaClient } from '@prisma/client' | ||
import type { | ||
InsertQuestionResponseArgs, | ||
RateQuestionType, | ||
StateUserType, | ||
} from '../../domain-models' | ||
import { | ||
questionInclude, | ||
rateQuestionPrismaToDomainType, | ||
} from './questionHelpers' | ||
import { NotFoundError } from '../postgresErrors' | ||
|
||
export async function insertRateQuestionResponse( | ||
client: PrismaClient, | ||
response: InsertQuestionResponseArgs, | ||
user: StateUserType | ||
): Promise<RateQuestionType | Error> { | ||
const documents = response.documents.map((document) => ({ | ||
name: document.name, | ||
s3URL: document.s3URL, | ||
})) | ||
|
||
try { | ||
const result = await client.rateQuestion.update({ | ||
where: { | ||
id: response.questionID, | ||
}, | ||
data: { | ||
responses: { | ||
create: { | ||
addedBy: { | ||
connect: { | ||
id: user.id, | ||
}, | ||
}, | ||
documents: { | ||
create: documents, | ||
}, | ||
}, | ||
}, | ||
}, | ||
include: questionInclude, | ||
}) | ||
|
||
return rateQuestionPrismaToDomainType(result) | ||
} catch (e) { | ||
// Return a NotFoundError if prisma fails on the primary key constraint | ||
// An operation failed because it depends on one or more records | ||
// that were required but not found. | ||
if (e.code === 'P2025') { | ||
return new NotFoundError('Question was not found to respond to') | ||
} | ||
return e | ||
} | ||
} |
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
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
Oops, something went wrong.