( input: z.infer<typeof apiCreatePostgres>, )
| 30 | export type Postgres = typeof postgres.$inferSelect; |
| 31 | |
| 32 | export const createPostgres = async ( |
| 33 | input: z.infer<typeof apiCreatePostgres>, |
| 34 | ) => { |
| 35 | const appName = buildAppName("postgres", input.appName); |
| 36 | |
| 37 | const valid = await validUniqueServerAppName(appName); |
| 38 | if (!valid) { |
| 39 | throw new TRPCError({ |
| 40 | code: "CONFLICT", |
| 41 | message: "Service with this 'AppName' already exists", |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | const newPostgres = await db |
| 46 | .insert(postgres) |
| 47 | .values({ |
| 48 | ...input, |
| 49 | databasePassword: input.databasePassword |
| 50 | ? input.databasePassword |
| 51 | : generatePassword(), |
| 52 | appName, |
| 53 | }) |
| 54 | .returning() |
| 55 | .then((value) => value[0]); |
| 56 | |
| 57 | if (!newPostgres) { |
| 58 | throw new TRPCError({ |
| 59 | code: "BAD_REQUEST", |
| 60 | message: "Error input: Inserting postgresql database", |
| 61 | }); |
| 62 | } |
| 63 | |
| 64 | return newPostgres; |
| 65 | }; |
| 66 | export const findPostgresById = async (postgresId: string) => { |
| 67 | const result = await db.query.postgres.findFirst({ |
| 68 | where: eq(postgres.postgresId, postgresId), |
no test coverage detected