chore: implemented feedback

This commit is contained in:
Catalin Pit
2024-02-28 08:10:38 +02:00
parent 93e34a5abd
commit 00a7389af3
4 changed files with 18 additions and 16 deletions

View File

@ -9,7 +9,7 @@ export const testCredentialsHandler = async (req: NextApiRequest, res: NextApiRe
const result = await validateApiToken({ authorization });
return res.status(200).json({
name: result.userId ? result.user.name : result.team?.name,
name: result.team?.name ?? result.user.name,
});
} catch (err) {
return res.status(500).json({

View File

@ -2,7 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import { findDocuments } from '@documenso/lib/server-only/document/find-documents';
import { getRecipientsForDocument } from '@documenso/lib/server-only/recipient/get-recipients-for-document';
import type { Recipient, Webhook } from '@documenso/prisma/client';
import type { Webhook } from '@documenso/prisma/client';
import { getWebhooksByTeamId } from '../get-webhooks-by-team-id';
import { getWebhooksByUserId } from '../get-webhooks-by-user-id';
@ -14,23 +14,25 @@ export const listDocumentsHandler = async (req: NextApiRequest, res: NextApiResp
const { user, userId, teamId } = await validateApiToken({ authorization });
let allWebhooks: Webhook[] = [];
let documents;
let recipients: Recipient[] = [];
const documents = await findDocuments({
userId: userId ?? user.id,
teamId: teamId ?? undefined,
perPage: 1,
});
const recipients = await getRecipientsForDocument({
documentId: documents.data[0].id,
userId: userId ?? user.id,
teamId: teamId ?? undefined,
});
if (userId) {
documents = await findDocuments({ userId });
allWebhooks = await getWebhooksByUserId(userId);
recipients = await getRecipientsForDocument({ documentId: documents.data[0].id, userId });
}
if (teamId) {
documents = await findDocuments({ userId: user.id, teamId });
allWebhooks = await getWebhooksByTeamId(teamId, user.id);
recipients = await getRecipientsForDocument({
documentId: documents.data[0].id,
userId: user.id,
teamId,
});
}
if (documents && documents.data.length > 0 && allWebhooks.length > 0 && recipients.length > 0) {

View File

@ -18,8 +18,8 @@ export const subscribeHandler = async (req: NextApiRequest, res: NextApiResponse
eventTriggers: [eventTrigger],
secret: null,
enabled: true,
userId: result.userId ? result.userId : result.user.id,
teamId: result.userId ? undefined : result.teamId,
userId: result.userId ?? result.user.id,
teamId: result.teamId ?? undefined,
},
});

View File

@ -15,8 +15,8 @@ export const unsubscribeHandler = async (req: NextApiRequest, res: NextApiRespon
const deletedWebhook = await prisma.webhook.delete({
where: {
id: webhookId,
userId: result.userId ? result.userId : result.user.id,
teamId: result.userId ? undefined : result.teamId,
userId: result.userId ?? result.user.id,
teamId: result.teamId ?? undefined,
},
});