mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
chore: implemented feedback
This commit is contained in:
@ -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({
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -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,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user