11import { Audit } from "@/server/audit" ;
22import { db } from "@/server/db" ;
3+ import type { TUpdateOption } from "./update-option" ;
34
4- interface TDeleteOption {
5- optionId : string ;
6- companyId : string ;
7- userAgent : string ;
8- requestIp : string ;
9- user : {
10- id : string ;
11- name : string ;
12- } ;
13- }
5+ type TDeleteOption = Omit < TUpdateOption , "data" > ;
146
157export const deleteOption = async ( {
168 optionId,
@@ -35,13 +27,13 @@ export const deleteOption = async ({
3527 }
3628
3729 const option = await db . $transaction ( async ( tx ) => {
38- const deletedOption = await tx . option . delete ( {
30+ const deleted = await tx . option . delete ( {
3931 where : {
4032 id : optionId ,
4133 } ,
4234 } ) ;
4335
44- const { stakeholderId } = deletedOption ;
36+ const { stakeholderId } = deleted ;
4537
4638 await Audit . create (
4739 {
@@ -52,13 +44,13 @@ export const deleteOption = async ({
5244 userAgent,
5345 requestIp,
5446 } ,
55- target : [ { type : "option" , id : deletedOption . id } ] ,
47+ target : [ { type : "option" , id : deleted . id } ] ,
5648 summary : `${ user . name } deleted the option for stakeholder ${ stakeholderId } ` ,
5749 } ,
5850 tx ,
5951 ) ;
6052
61- return deletedOption ;
53+ return deleted ;
6254 } ) ;
6355 return {
6456 success : true ,
@@ -71,7 +63,9 @@ export const deleteOption = async ({
7163 success : false ,
7264 code : "INTERNAL_SERVER_ERROR" ,
7365 message :
74- "Error deleting the option, please try again or contact support." ,
66+ error instanceof Error
67+ ? error . message
68+ : "Error deleting the option, please try again or contact support." ,
7569 } ;
7670 }
7771} ;
0 commit comments