mirror of
https://github.com/documenso/documenso.git
synced 2025-11-26 14:34:05 +10:00
refactor: improve find envelopes endpoint implementation
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { expect, test } from '@playwright/test';
|
import { type APIRequestContext, expect, test } from '@playwright/test';
|
||||||
import type { Team, User } from '@prisma/client';
|
import type { Team, User } from '@prisma/client';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
@@ -165,6 +165,9 @@ test.describe('API V2 Envelopes', () => {
|
|||||||
positionY: 0,
|
positionY: 0,
|
||||||
width: 0,
|
width: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'signature',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: FieldType.SIGNATURE,
|
type: FieldType.SIGNATURE,
|
||||||
@@ -174,6 +177,9 @@ test.describe('API V2 Envelopes', () => {
|
|||||||
positionY: 0,
|
positionY: 0,
|
||||||
width: 0,
|
width: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
|
fieldMeta: {
|
||||||
|
type: 'signature',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -561,7 +567,7 @@ test.describe('API V2 Envelopes', () => {
|
|||||||
|
|
||||||
test.describe('Envelope find endpoint', () => {
|
test.describe('Envelope find endpoint', () => {
|
||||||
const createEnvelope = async (
|
const createEnvelope = async (
|
||||||
request: ReturnType<typeof test.extend>['request'] extends Promise<infer R> ? R : never,
|
request: APIRequestContext,
|
||||||
token: string,
|
token: string,
|
||||||
payload: TCreateEnvelopePayload,
|
payload: TCreateEnvelopePayload,
|
||||||
) => {
|
) => {
|
||||||
@@ -747,10 +753,7 @@ test.describe('API V2 Envelopes', () => {
|
|||||||
expect(envelope?.id).toBeDefined();
|
expect(envelope?.id).toBeDefined();
|
||||||
expect(envelope?.type).toBe(EnvelopeType.DOCUMENT);
|
expect(envelope?.type).toBe(EnvelopeType.DOCUMENT);
|
||||||
expect(envelope?.status).toBe(DocumentStatus.DRAFT);
|
expect(envelope?.status).toBe(DocumentStatus.DRAFT);
|
||||||
expect(envelope?.documentMeta).toBeDefined();
|
|
||||||
expect(envelope?.recipients).toBeDefined();
|
expect(envelope?.recipients).toBeDefined();
|
||||||
expect(envelope?.fields).toBeDefined();
|
|
||||||
expect(envelope?.envelopeItems).toBeDefined();
|
|
||||||
expect(envelope?.user).toBeDefined();
|
expect(envelope?.user).toBeDefined();
|
||||||
expect(envelope?.team).toBeDefined();
|
expect(envelope?.team).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -150,18 +150,6 @@ export const findEnvelopes = async ({
|
|||||||
[orderByColumn]: orderByDirection,
|
[orderByColumn]: orderByDirection,
|
||||||
},
|
},
|
||||||
include: {
|
include: {
|
||||||
envelopeItems: {
|
|
||||||
select: {
|
|
||||||
envelopeId: true,
|
|
||||||
id: true,
|
|
||||||
title: true,
|
|
||||||
order: true,
|
|
||||||
},
|
|
||||||
orderBy: {
|
|
||||||
order: 'asc',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
documentMeta: true,
|
|
||||||
user: {
|
user: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -174,21 +162,12 @@ export const findEnvelopes = async ({
|
|||||||
id: 'asc',
|
id: 'asc',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fields: true,
|
|
||||||
team: {
|
team: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
url: true,
|
url: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
directLink: {
|
|
||||||
select: {
|
|
||||||
directTemplateRecipientId: true,
|
|
||||||
enabled: true,
|
|
||||||
id: true,
|
|
||||||
token: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
prisma.envelope.count({
|
prisma.envelope.count({
|
||||||
|
|||||||
@@ -115,5 +115,40 @@ export type TEnvelopeLite = z.infer<typeof ZEnvelopeLiteSchema>;
|
|||||||
/**
|
/**
|
||||||
* A version of the envelope response schema when returning multiple envelopes at once from a single API endpoint.
|
* A version of the envelope response schema when returning multiple envelopes at once from a single API endpoint.
|
||||||
*/
|
*/
|
||||||
// export const ZEnvelopeManySchema = X
|
export const ZEnvelopeManySchema = EnvelopeSchema.pick({
|
||||||
// export type TEnvelopeMany = z.infer<typeof ZEnvelopeManySchema>;
|
internalVersion: true,
|
||||||
|
type: true,
|
||||||
|
status: true,
|
||||||
|
source: true,
|
||||||
|
visibility: true,
|
||||||
|
templateType: true,
|
||||||
|
id: true,
|
||||||
|
secondaryId: true,
|
||||||
|
externalId: true,
|
||||||
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
completedAt: true,
|
||||||
|
deletedAt: true,
|
||||||
|
title: true,
|
||||||
|
authOptions: true,
|
||||||
|
formValues: true,
|
||||||
|
publicTitle: true,
|
||||||
|
publicDescription: true,
|
||||||
|
userId: true,
|
||||||
|
teamId: true,
|
||||||
|
folderId: true,
|
||||||
|
templateId: true,
|
||||||
|
}).extend({
|
||||||
|
user: z.object({
|
||||||
|
id: z.number(),
|
||||||
|
name: z.string(),
|
||||||
|
email: z.string(),
|
||||||
|
}),
|
||||||
|
recipients: ZEnvelopeRecipientLiteSchema.array(),
|
||||||
|
team: TeamSchema.pick({
|
||||||
|
id: true,
|
||||||
|
url: true,
|
||||||
|
}).nullable(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export type TEnvelopeMany = z.infer<typeof ZEnvelopeManySchema>;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { DocumentSource, DocumentStatus, EnvelopeType } from '@prisma/client';
|
import { DocumentSource, DocumentStatus, EnvelopeType } from '@prisma/client';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { ZEnvelopeSchema } from '@documenso/lib/types/envelope';
|
import { ZEnvelopeManySchema } from '@documenso/lib/types/envelope';
|
||||||
import { ZFindResultResponse, ZFindSearchParamsSchema } from '@documenso/lib/types/search-params';
|
import { ZFindResultResponse, ZFindSearchParamsSchema } from '@documenso/lib/types/search-params';
|
||||||
|
|
||||||
import type { TrpcRouteMeta } from '../trpc';
|
import type { TrpcRouteMeta } from '../trpc';
|
||||||
@@ -39,7 +39,7 @@ export const ZFindEnvelopesRequestSchema = ZFindSearchParamsSchema.extend({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const ZFindEnvelopesResponseSchema = ZFindResultResponse.extend({
|
export const ZFindEnvelopesResponseSchema = ZFindResultResponse.extend({
|
||||||
data: ZEnvelopeSchema.array(),
|
data: ZEnvelopeManySchema.array(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TFindEnvelopesRequest = z.infer<typeof ZFindEnvelopesRequestSchema>;
|
export type TFindEnvelopesRequest = z.infer<typeof ZFindEnvelopesRequestSchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user