(input: z.infer<typeof apiCreateMount>)
| 23 | export type Mount = typeof mounts.$inferSelect; |
| 24 | |
| 25 | export const createMount = async (input: z.infer<typeof apiCreateMount>) => { |
| 26 | try { |
| 27 | const { serviceId, ...rest } = input; |
| 28 | const value = await db |
| 29 | .insert(mounts) |
| 30 | .values({ |
| 31 | ...rest, |
| 32 | ...(input.serviceType === "application" && { |
| 33 | applicationId: serviceId, |
| 34 | }), |
| 35 | ...(input.serviceType === "compose" && { |
| 36 | composeId: serviceId, |
| 37 | }), |
| 38 | ...(input.serviceType === "libsql" && { |
| 39 | libsqlId: serviceId, |
| 40 | }), |
| 41 | ...(input.serviceType === "mariadb" && { |
| 42 | mariadbId: serviceId, |
| 43 | }), |
| 44 | ...(input.serviceType === "mongo" && { |
| 45 | mongoId: serviceId, |
| 46 | }), |
| 47 | ...(input.serviceType === "mysql" && { |
| 48 | mysqlId: serviceId, |
| 49 | }), |
| 50 | ...(input.serviceType === "postgres" && { |
| 51 | postgresId: serviceId, |
| 52 | }), |
| 53 | ...(input.serviceType === "redis" && { |
| 54 | redisId: serviceId, |
| 55 | }), |
| 56 | }) |
| 57 | .returning() |
| 58 | .then((value) => value[0]); |
| 59 | |
| 60 | if (!value) { |
| 61 | throw new TRPCError({ |
| 62 | code: "BAD_REQUEST", |
| 63 | message: "Error inserting mount", |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | if (value.type === "file") { |
| 68 | await createFileMount(value.mountId); |
| 69 | } |
| 70 | return value; |
| 71 | } catch (error) { |
| 72 | console.log(error); |
| 73 | throw new TRPCError({ |
| 74 | code: "BAD_REQUEST", |
| 75 | message: `Error ${error instanceof Error ? error.message : error}`, |
| 76 | cause: error, |
| 77 | }); |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | export const createFileMount = async (mountId: string) => { |
| 82 | try { |
no test coverage detected