fix: soft delete a document when the owner deletes it

This commit is contained in:
Ephraim Atta-Duncan
2024-06-17 22:20:42 +00:00
committed by Mythie
parent 26ccdc1b23
commit 2837b178fb
3 changed files with 74 additions and 20 deletions

View File

@ -138,6 +138,16 @@ const handleDocumentOwnerDelete = async ({
}),
});
// Soft delete for document recipients since the owner is deleting it
await tx.recipient.updateMany({
where: {
documentId: document.id,
},
data: {
documentDeletedAt: new Date().toISOString(),
},
});
return await tx.document.update({
where: {
id: document.id,

View File

@ -338,7 +338,7 @@ const findDocumentsFilter = (status: ExtendedDocumentStatus, user: User) => {
teamId: null,
status: ExtendedDocumentStatus.COMPLETED,
deletedAt: {
not: null,
gte: DateTime.now().minus({ days: 30 }).startOf('day').toJSDate(),
},
},
{
@ -347,7 +347,7 @@ const findDocumentsFilter = (status: ExtendedDocumentStatus, user: User) => {
some: {
email: user.email,
documentDeletedAt: {
not: null,
gte: DateTime.now().minus({ days: 30 }).startOf('day').toJSDate(),
},
},
},
@ -539,7 +539,7 @@ const findTeamDocumentsFilter = (
{
teamId: team.id,
deletedAt: {
not: null,
gte: DateTime.now().minus({ days: 30 }).startOf('day').toJSDate(),
},
},
],
@ -552,7 +552,7 @@ const findTeamDocumentsFilter = (
email: teamEmail,
},
deletedAt: {
not: null,
gte: DateTime.now().minus({ days: 30 }).startOf('day').toJSDate(),
},
},
{
@ -560,7 +560,7 @@ const findTeamDocumentsFilter = (
some: {
email: teamEmail,
documentDeletedAt: {
not: null,
gte: DateTime.now().minus({ days: 30 }).startOf('day').toJSDate(),
},
},
},

View File

@ -152,12 +152,39 @@ const getCounts = async ({ user, createdAt }: GetCountsOption) => {
_all: true,
},
where: {
OR: [
{
userId: user.id,
createdAt,
deletedAt: {
gte: DateTime.now().minus({ days: 30 }).startOf('day').toJSDate(),
},
},
{
status: ExtendedDocumentStatus.PENDING,
Recipient: {
some: {
email: user.email,
signingStatus: SigningStatus.SIGNED,
documentDeletedAt: {
gte: DateTime.now().minus({ days: 30 }).startOf('day').toJSDate(),
},
},
},
},
{
status: ExtendedDocumentStatus.COMPLETED,
Recipient: {
some: {
email: user.email,
signingStatus: SigningStatus.SIGNED,
documentDeletedAt: {
gte: DateTime.now().minus({ days: 30 }).startOf('day').toJSDate(),
},
},
},
},
],
},
}),
]);
};
@ -273,6 +300,21 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
where: {
userId: userIdWhereClause,
createdAt,
OR: [
{
status: ExtendedDocumentStatus.PENDING,
Recipient: {
some: {
email: teamEmail,
signingStatus: SigningStatus.SIGNED,
documentDeletedAt: null,
},
},
deletedAt: {
gte: DateTime.now().minus({ days: 30 }).startOf('day').toJSDate(),
},
},
{
status: ExtendedDocumentStatus.COMPLETED,
Recipient: {
some: {
@ -287,6 +329,8 @@ const getTeamCounts = async (options: GetTeamCountsOption) => {
gte: DateTime.now().minus({ days: 30 }).startOf('day').toJSDate(),
},
},
],
},
} satisfies Prisma.DocumentGroupByArgs;
}