( securityId: string, data: Partial<Security>, )
| 87 | }; |
| 88 | |
| 89 | export const updateSecurityById = async ( |
| 90 | securityId: string, |
| 91 | data: Partial<Security>, |
| 92 | ) => { |
| 93 | try { |
| 94 | await db.transaction(async (tx) => { |
| 95 | const securityResponse = await findSecurityById(securityId); |
| 96 | |
| 97 | const application = await findApplicationById( |
| 98 | securityResponse.applicationId, |
| 99 | ); |
| 100 | |
| 101 | await removeSecurityMiddleware(application, securityResponse); |
| 102 | |
| 103 | const response = await tx |
| 104 | .update(security) |
| 105 | .set({ |
| 106 | ...data, |
| 107 | }) |
| 108 | .where(eq(security.securityId, securityId)) |
| 109 | .returning() |
| 110 | .then((res) => res[0]); |
| 111 | |
| 112 | if (!response) { |
| 113 | throw new TRPCError({ |
| 114 | code: "NOT_FOUND", |
| 115 | message: "Security not found", |
| 116 | }); |
| 117 | } |
| 118 | |
| 119 | await createSecurityMiddleware(application, response); |
| 120 | |
| 121 | return response; |
| 122 | }); |
| 123 | } catch (error) { |
| 124 | const message = |
| 125 | error instanceof Error ? error.message : "Error updating this security"; |
| 126 | throw new TRPCError({ |
| 127 | code: "BAD_REQUEST", |
| 128 | message, |
| 129 | }); |
| 130 | } |
| 131 | }; |
no test coverage detected