Skip to content

Commit

Permalink
refactor to deleteMyself
Browse files Browse the repository at this point in the history
  • Loading branch information
vincanger committed Nov 17, 2023
1 parent ef3be90 commit 23640bd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion wasp-ai/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"semi": true,
"singleQuote": false,
"trailingComma": "es5",
"printWidth": 120
"printWidth": 100
}
4 changes: 2 additions & 2 deletions wasp-ai/main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ action createFeedback {
entities: [Feedback]
}

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

Expand Down
2 changes: 1 addition & 1 deletion wasp-ai/src/client/pages/ResultPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export function OnSuccessModal({ isOpen, setIsOpen, appGenerationResult }) {
const num = parseFloat(match[1]);
setNumTokensSpent(num * 1000);
} else {
console.log('No match found');
console.log("Failed to parse total number of tokens used: no regex match.");
}
}

Expand Down
9 changes: 4 additions & 5 deletions wasp-ai/src/client/pages/UserPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
projectStatusToDisplayableText,
} from "../project/utils";
import { HomeButton } from "../components/Header";
import deleteUser from "@wasp/actions/deleteUser";
import deleteMyself from "@wasp/actions/deleteMyself";
import { MyDialog } from "../components/Dialog";

export function UserPage({ user }) {
Expand All @@ -33,8 +33,7 @@ export function UserPage({ user }) {
<DeleteUserModal
isOpen={isDeleteUserModalOpen}
setIsOpen={setIsDeleteUserModalOpen}
deleteUser={deleteUser}
user={user}
deleteUser={deleteMyself}
/>

<div className="big-box">
Expand Down Expand Up @@ -137,9 +136,9 @@ function UserProjectsTable({ projects }) {
);
}

function DeleteUserModal({ isOpen, setIsOpen, deleteUser, user }) {
function DeleteUserModal({ isOpen, setIsOpen, deleteUser }) {
async function deleteUserHandler() {
await deleteUser({ userId: user.id });
await deleteUser();
logout();
}

Expand Down
8 changes: 4 additions & 4 deletions wasp-ai/src/server/operations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RegisterZipDownload, StartGeneratingNewApp, CreateFeedback, DeleteUser } from "@wasp/actions/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";
Expand Down Expand Up @@ -238,14 +238,14 @@ export const getProjectsByUser: GetProjectsByUser<void, Project[]> = async (_arg
});
};

export const deleteUser: DeleteUser<{ userId: number }, User> = async (args, context) => {
if (!context.user || context.user.id !== args.userId) {
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: args.userId,
id: context.user.id,
},
});
};

0 comments on commit 23640bd

Please sign in to comment.