mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 00:32:43 +10:00
This PR is handles the changes required to support envelopes. The new envelope editor/signing page will be hidden during release. The core changes here is to migrate the documents and templates model to a centralized envelopes model. Even though Documents and Templates are removed, from the user perspective they will still exist as we remap envelopes to documents and templates.
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { DocumentStatus, EnvelopeType } from '@prisma/client';
|
|
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
|
import { deletedAccountServiceAccount } from './service-accounts/deleted-account';
|
|
|
|
export type DeleteUserOptions = {
|
|
id: number;
|
|
};
|
|
|
|
export const deleteUser = async ({ id }: DeleteUserOptions) => {
|
|
const user = await prisma.user.findFirst({
|
|
where: {
|
|
id,
|
|
},
|
|
});
|
|
|
|
if (!user) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
message: `User with ID ${id} not found`,
|
|
});
|
|
}
|
|
|
|
const serviceAccount = await deletedAccountServiceAccount();
|
|
|
|
// TODO: Send out cancellations for all pending docs
|
|
await prisma.envelope.updateMany({
|
|
where: {
|
|
userId: user.id,
|
|
type: EnvelopeType.DOCUMENT,
|
|
status: {
|
|
in: [DocumentStatus.PENDING, DocumentStatus.REJECTED, DocumentStatus.COMPLETED],
|
|
},
|
|
},
|
|
data: {
|
|
userId: serviceAccount.id,
|
|
deletedAt: new Date(),
|
|
},
|
|
});
|
|
|
|
return await prisma.user.delete({
|
|
where: {
|
|
id: user.id,
|
|
},
|
|
});
|
|
};
|