| 13 | export type Server = typeof server.$inferSelect; |
| 14 | |
| 15 | export const createServer = async ( |
| 16 | input: z.infer<typeof apiCreateServer>, |
| 17 | organizationId: string, |
| 18 | ) => { |
| 19 | const newServer = await db |
| 20 | .insert(server) |
| 21 | .values({ |
| 22 | ...input, |
| 23 | organizationId: organizationId, |
| 24 | createdAt: new Date().toISOString(), |
| 25 | } as typeof server.$inferInsert) |
| 26 | .returning() |
| 27 | .then((value) => value[0]); |
| 28 | |
| 29 | if (!newServer) { |
| 30 | throw new TRPCError({ |
| 31 | code: "BAD_REQUEST", |
| 32 | message: "Error creating the server", |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | return newServer; |
| 37 | }; |
| 38 | |
| 39 | export const findServerById = async (serverId: string) => { |
| 40 | const currentServer = await db.query.server.findFirst({ |