Skip to content

Commit

Permalink
delete user relevant info from projects
Browse files Browse the repository at this point in the history
  • Loading branch information
vincanger committed Nov 21, 2023
1 parent 23640bd commit bd607e0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
2 changes: 1 addition & 1 deletion wasp-ai/main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ action createFeedback {

action deleteMyself {
fn: import { deleteMyself } from "@server/operations.js",
entities: [User]
entities: [User, Project, File, Log]
}

query getFeedback {
Expand Down
61 changes: 53 additions & 8 deletions wasp-ai/src/server/operations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { RegisterZipDownload, StartGeneratingNewApp, CreateFeedback, DeleteMyself } from "@wasp/actions/types";
import { GetAppGenerationResult, GetStats, GetFeedback, GetNumProjects, GetProjectsByUser } from "@wasp/queries/types";
import {
RegisterZipDownload,
StartGeneratingNewApp,
CreateFeedback,
DeleteMyself,
} from "@wasp/actions/types";
import {
GetAppGenerationResult,
GetStats,
GetFeedback,
GetNumProjects,
GetProjectsByUser,
} from "@wasp/queries/types";
import HttpError from "@wasp/core/HttpError.js";
import { checkPendingAppsJob } from "@wasp/jobs/checkPendingAppsJob.js";
import { getNowInUTC } from "./utils.js";
Expand Down Expand Up @@ -242,10 +253,44 @@ export const deleteMyself: DeleteMyself<void, User> = async (args, context) => {
if (!context.user) {
throw new HttpError(401, "Not authorized");
}

return await context.entities.User.delete({
where: {
id: context.user.id,
},
});
try {
await context.entities.Log.deleteMany({
where: {
project: {
user: {
id: context.user.id,
},
},
},
});
await context.entities.File.deleteMany({
where: {
project: {
user: {
id: context.user.id,
},
},
},
});
await context.entities.Project.updateMany({
where: {
user: {
id: context.user.id,
},
},
data: {
zipDownloadedAt: undefined,
name: "Deleted project",
description: "Deleted project",
},
});
return await context.entities.User.delete({
where: {
id: context.user.id,
},
});
} catch (error) {
console.error(error);
throw new HttpError(500, "Error deleting user");
}
};

0 comments on commit bd607e0

Please sign in to comment.