-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: return fields in GET /documents/:id endpoint #1317
base: main
Are you sure you want to change the base?
Conversation
@Etrenak is attempting to deploy a commit to the Documenso Team Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe changes introduce a new asynchronous function, Changes
Possibly related PRs
Suggested labels
Poem
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/api/v1/implementation.ts (3 hunks)
- packages/api/v1/schema.ts (3 hunks)
Additional comments not posted (4)
packages/api/v1/schema.ts (2)
37-51
: LGTM!The new
ZFieldSchema
declaration looks good. It correctly defines the structure of a field object using thez.object()
method from the Zod validation library. The usage ofz.nativeEnum(FieldType)
for thetype
property is a good practice to restrict the allowed values to a predefined set.
64-73
: LGTM!The changes to the
ZSuccessfulDocumentResponseSchema
look good. The inclusion of thefields
property as an array of objects conforming to theZFieldSchema
enhances the response schema by allowing it to encapsulate a collection of field objects. The usage of thepick
method to select specific fields fromZFieldSchema
is a good practice to keep the response schema concise and focused.packages/api/v1/implementation.ts (2)
21-21
: LGTM!The import statement is syntactically correct and necessary for using the
getFieldsForDocument
function.
94-97
: LGTM!The code changes in the
getDocument
function are syntactically correct and enhance the API functionality by returning the fields associated with the document.Also applies to: 107-107
Hey there, it looks like you haven't accepted our contributor license agreement yet. In order for us to accept your pull request we ask that you please fill out the CLA: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/api/v1/schema.ts (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/api/v1/schema.ts
This one looks good, I'll just need to grab a moment to run through the testing on this one manually! |
For my use case, I would like to be able to also get fieldMeta returned by this endpoint. However, when I tried to also return the fieldMeta, I encountered some typing issues. That is, I simply added fieldMeta in the schema like this : export const ZSuccessfulGetDocumentResponseSchema = ZSuccessfulDocumentResponseSchema.extend({
recipients: z.lazy(() => z.array(ZSuccessfulRecipientResponseSchema)),
fields: ZFieldSchema.pick({
id: true,
recipientId: true,
type: true,
page: true,
positionX: true,
positionY: true,
width: true,
height: true,
}).extend({
fieldMeta: ZFieldMetaSchema,
}).array(),
}); But since fieldMeta in only known as a JsonValue in the prisma schema, we cannot simply return the result of the query to the database. Please tell me if this is OK to simply do the parsing of the database result in Do you know why it was chosen to store the field meta as a JsonValue in the database, and which of the two solutions I should prefer ? EDIT : This can definitely be addressed in another PR |
Thank you for following the naming conventions for pull request titles! 💚🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/api/v1/implementation.ts (3 hunks)
- packages/api/v1/schema.ts (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- packages/api/v1/implementation.ts
- packages/api/v1/schema.ts
So I ended up adding fieldMeta anyway. I hope I did not waste your time on previously testing the PR without it. I also put back the definition of Feel free to tell me if you would like another implementation, my precedent comment still stands. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range and nitpick comments (1)
packages/api/v1/implementation.ts (1)
100-117
: Handle parsing errors and update API documentation.The parsing of
fieldMeta
usingZFieldMetaSchema
is a good way to ensure the response contains valid and typed metadata. However, consider the following suggestions:
Add proper error handling for the parsing error. Instead of throwing a generic error, catch the parsing error and throw a more specific error indicating the issue with the field metadata.
Log the parsing error for debugging purposes. This will help identify and fix issues with invalid field metadata stored in the database.
Update the API documentation to reflect the new
fields
key in the response. Clients need to be aware of this change to handle the response correctly.Here's an example of how you can handle the parsing error and log it:
if (field.fieldMeta) { const result = ZFieldMetaSchema.safeParse(field.fieldMeta); if (!result.success) { const error = new Error(`Field meta parsing failed for field ${field.id}: ${result.error.message}`); console.error(error); - throw new Error('Field meta parsing failed for field ' field.id); throw error; } parsedMetaOrNull = result.data; }
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/api/v1/implementation.ts (3 hunks)
- packages/api/v1/schema.ts (2 hunks)
Additional comments not posted (3)
packages/api/v1/schema.ts (2)
58-73
: LGTM!The extension of the
ZSuccessfulGetDocumentResponseSchema
to include thefields
property aligns with the PR objective and maintains consistency with the existing field schema. The selection of specific properties fromZFieldSchema
ensures a focused representation of the fields, while the optionalfieldMeta
property allows for flexibility in including additional metadata.
426-426
: Looks good!Omitting the
fields
property from theZSuccessfulSigningResponseSchema
helps to maintain a focused and streamlined response structure for signing operations. This change aligns with the separation of concerns between document retrieval and signing functionalities.packages/api/v1/implementation.ts (1)
95-98
: Fetching fields usinggetFieldsForDocument
looks good.The fields are correctly fetched using the
getFieldsForDocument
function with thedocumentId
anduserId
.
Hey, I see this has been approved. Any idea when it might get merged ? Thanks! |
Description
To be able to use the PATCH
/api/v1/documents/{id}/fields/{fieldId}
endpoint, we need to know the fields ID of a particular document. The issue #1178 suggested to create a new endpoint for this. To be consistent with the/templates
endpoint, I propose in this PR to directly add thefields
field to the/documents/:id
endpoint.Related Issue
This is related to #1178 but it might still be interesting to create a new endpoint which could also return the
fieldMeta
.Changes Made
Added
fields
toZSuccessfulGetDocumentResponseSchema
in the API contract, and changed the implementation accordingly.Testing Performed
npm run build
)Checklist
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Chores