mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
chore: changes
This commit is contained in:
@ -1,41 +0,0 @@
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
export const deleteUserAndItsData = async (name: string) => {
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
name: {
|
||||
contains: name,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new Error(`User with name ${name} not found`);
|
||||
}
|
||||
|
||||
const document = await prisma.document.findMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
},
|
||||
select: {
|
||||
documentData: {
|
||||
select: {
|
||||
data: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return prisma.$transaction([
|
||||
prisma.user.delete({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
}),
|
||||
prisma.documentData.deleteMany({
|
||||
where: {
|
||||
data: document[0]?.documentData.data,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
};
|
||||
21
packages/lib/server-only/user/delete-user.ts
Normal file
21
packages/lib/server-only/user/delete-user.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
export const deleteUser = async (name: string) => {
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
name: {
|
||||
contains: name,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new Error(`User with name ${name} not found`);
|
||||
}
|
||||
|
||||
return await prisma.user.delete({
|
||||
where: {
|
||||
id: user.id,
|
||||
},
|
||||
});
|
||||
};
|
||||
@ -1,5 +1,6 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
output = "../../node_modules/.prisma/client"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
@ -110,10 +111,10 @@ model Document {
|
||||
Field Field[]
|
||||
ShareLink DocumentShareLink[]
|
||||
documentDataId String
|
||||
documentData DocumentData @relation(fields: [documentDataId], references: [id], onDelete: Cascade)
|
||||
documentData DocumentData @relation(fields: [documentDataId], references: [id], onDelete: Cascade)
|
||||
documentMeta DocumentMeta?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @default(now()) @updatedAt
|
||||
|
||||
@@unique([documentDataId])
|
||||
}
|
||||
@ -133,11 +134,11 @@ model DocumentData {
|
||||
}
|
||||
|
||||
model DocumentMeta {
|
||||
id String @id @default(cuid())
|
||||
subject String?
|
||||
message String?
|
||||
documentId Int @unique
|
||||
document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
id String @id @default(cuid())
|
||||
subject String?
|
||||
message String?
|
||||
documentId Int @unique
|
||||
document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
enum ReadStatus {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { type Page, expect, test } from '@playwright/test';
|
||||
|
||||
import { deleteUserAndItsData } from '@documenso/lib/server-only/user/delete-user-and-data';
|
||||
import { deleteUser } from '@documenso/lib/server-only/user/delete-user';
|
||||
|
||||
test.use({ storageState: { cookies: [], origins: [] } });
|
||||
|
||||
@ -10,9 +10,9 @@ test.use({ storageState: { cookies: [], origins: [] } });
|
||||
*/
|
||||
test.describe.configure({ mode: 'serial' });
|
||||
|
||||
const username = E2E_TEST_AUTHENTICATE_USERNAME;
|
||||
const email = E2E_TEST_AUTHENTICATE_USER_EMAIL;
|
||||
const password = E2E_TEST_AUTHENTICATE_USER_PASSWORD;
|
||||
const username = 'testuser';
|
||||
const email = 'test-user@documenso.com';
|
||||
const password = 'password';
|
||||
|
||||
test('user can sign up with email and password', async ({ page }: { page: Page }) => {
|
||||
await page.goto('/signup');
|
||||
@ -48,7 +48,7 @@ test('user can login with user and password', async ({ page }: { page: Page }) =
|
||||
|
||||
test.afterAll('Teardown', async () => {
|
||||
try {
|
||||
await deleteUserAndItsData(username);
|
||||
await deleteUser(username);
|
||||
} catch (e) {
|
||||
throw new Error(`Error deleting user: ${e}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user