( data: z.infer<typeof apiCreateSecurity>, )
| 24 | }; |
| 25 | |
| 26 | export const createSecurity = async ( |
| 27 | data: z.infer<typeof apiCreateSecurity>, |
| 28 | ) => { |
| 29 | try { |
| 30 | await db.transaction(async (tx) => { |
| 31 | const application = await findApplicationById(data.applicationId); |
| 32 | |
| 33 | const securityResponse = await tx |
| 34 | .insert(security) |
| 35 | .values({ |
| 36 | ...data, |
| 37 | }) |
| 38 | .returning() |
| 39 | .then((res) => res[0]); |
| 40 | |
| 41 | if (!securityResponse) { |
| 42 | throw new TRPCError({ |
| 43 | code: "BAD_REQUEST", |
| 44 | message: "Error creating the security", |
| 45 | }); |
| 46 | } |
| 47 | await createSecurityMiddleware(application, securityResponse); |
| 48 | return true; |
| 49 | }); |
| 50 | } catch (error) { |
| 51 | throw new TRPCError({ |
| 52 | code: "BAD_REQUEST", |
| 53 | message: |
| 54 | error instanceof Error ? error.message : "Error creating this security", |
| 55 | cause: error, |
| 56 | }); |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | export const deleteSecurityById = async (securityId: string) => { |
| 61 | try { |
no test coverage detected