Skip to content

Commit

Permalink
fix: type in delete-option service
Browse files Browse the repository at this point in the history
  • Loading branch information
Raju-kadel-27 committed Jul 29, 2024
1 parent c6af832 commit c544f18
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/server/services/stock-option/delete-option.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { Audit } from "@/server/audit";
import { db } from "@/server/db";
import type { TUpdateOption } from "./update-option";

interface TDeleteOption {
optionId: string;
companyId: string;
userAgent: string;
requestIp: string;
user: {
id: string;
name: string;
};
}
type TDeleteOption = Omit<TUpdateOption, "data">;

export const deleteOption = async ({
optionId,
Expand All @@ -35,13 +27,13 @@ export const deleteOption = async ({
}

const option = await db.$transaction(async (tx) => {
const deletedOption = await tx.option.delete({
const deleted = await tx.option.delete({
where: {
id: optionId,
},
});

const { stakeholderId } = deletedOption;
const { stakeholderId } = deleted;

await Audit.create(
{
Expand All @@ -52,13 +44,13 @@ export const deleteOption = async ({
userAgent,
requestIp,
},
target: [{ type: "option", id: deletedOption.id }],
target: [{ type: "option", id: deleted.id }],
summary: `${user.name} deleted the option for stakeholder ${stakeholderId}`,
},
tx,
);

return deletedOption;
return deleted;
});
return {
success: true,
Expand All @@ -71,7 +63,9 @@ export const deleteOption = async ({
success: false,
code: "INTERNAL_SERVER_ERROR",
message:
"Error deleting the option, please try again or contact support.",
error instanceof Error
? error.message
: "Error deleting the option, please try again or contact support.",
};
}
};

0 comments on commit c544f18

Please sign in to comment.