Skip to content
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

fix: complete document when all recipients are CC #1113

Merged
merged 8 commits into from
Apr 27, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ export const EditDocumentForm = ({

const onAddSubjectFormSubmit = async (data: TAddSubjectFormSchema) => {
const { subject, message } = data.meta;

try {
await sendDocument({
documentId: document.id,
Expand Down
6 changes: 5 additions & 1 deletion packages/lib/server-only/document/send-document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ export const sendDocument = async ({
}),
);

const allRecipientsAreCC = document.Recipient.every(
(recipient) => recipient.role === RecipientRole.CC,
);

const updatedDocument = await prisma.$transaction(async (tx) => {
if (document.status === DocumentStatus.DRAFT) {
await tx.documentAuditLog.create({
Expand All @@ -229,7 +233,7 @@ export const sendDocument = async ({
id: documentId,
},
data: {
status: DocumentStatus.PENDING,
status: allRecipientsAreCC ? DocumentStatus.COMPLETED : DocumentStatus.PENDING,
},
include: {
Recipient: true,
Expand Down
Loading