mirror of
https://github.com/documenso/documenso.git
synced 2025-11-15 09:12:02 +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 });
|
const result = await validateApiToken({ authorization });
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
name: result.userId ? result.user.name : result.team?.name,
|
name: result.team?.name ?? result.user.name,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res.status(500).json({
|
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 { findDocuments } from '@documenso/lib/server-only/document/find-documents';
|
||||||
import { getRecipientsForDocument } from '@documenso/lib/server-only/recipient/get-recipients-for-document';
|
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 { getWebhooksByTeamId } from '../get-webhooks-by-team-id';
|
||||||
import { getWebhooksByUserId } from '../get-webhooks-by-user-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 });
|
const { user, userId, teamId } = await validateApiToken({ authorization });
|
||||||
|
|
||||||
let allWebhooks: Webhook[] = [];
|
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) {
|
if (userId) {
|
||||||
documents = await findDocuments({ userId });
|
|
||||||
allWebhooks = await getWebhooksByUserId(userId);
|
allWebhooks = await getWebhooksByUserId(userId);
|
||||||
recipients = await getRecipientsForDocument({ documentId: documents.data[0].id, userId });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (teamId) {
|
if (teamId) {
|
||||||
documents = await findDocuments({ userId: user.id, teamId });
|
|
||||||
allWebhooks = await getWebhooksByTeamId(teamId, user.id);
|
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) {
|
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],
|
eventTriggers: [eventTrigger],
|
||||||
secret: null,
|
secret: null,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
userId: result.userId ? result.userId : result.user.id,
|
userId: result.userId ?? result.user.id,
|
||||||
teamId: result.userId ? undefined : result.teamId,
|
teamId: result.teamId ?? undefined,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -15,8 +15,8 @@ export const unsubscribeHandler = async (req: NextApiRequest, res: NextApiRespon
|
|||||||
const deletedWebhook = await prisma.webhook.delete({
|
const deletedWebhook = await prisma.webhook.delete({
|
||||||
where: {
|
where: {
|
||||||
id: webhookId,
|
id: webhookId,
|
||||||
userId: result.userId ? result.userId : result.user.id,
|
userId: result.userId ?? result.user.id,
|
||||||
teamId: result.userId ? undefined : result.teamId,
|
teamId: result.teamId ?? undefined,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user