({
update,
existing,
}: {
update: z.infer<typeof zServerUpdate>;
existing: Server | null;
})
| 82 | } |
| 83 | |
| 84 | export async function updateServer({ |
| 85 | update, |
| 86 | existing, |
| 87 | }: { |
| 88 | update: z.infer<typeof zServerUpdate>; |
| 89 | existing: Server | null; |
| 90 | }) { |
| 91 | if (!existing) { |
| 92 | existing = await findServerById(update.id); |
| 93 | if (!existing) throw new Error(`Server with id ${update.id} not found`); |
| 94 | } |
| 95 | // Explicitly type this to avoid passing into .parse missing information |
| 96 | const combinedUpdateData = await applyServerSettingsSideEffects({ |
| 97 | old: existing, |
| 98 | updated: update, |
| 99 | }); |
| 100 | |
| 101 | await db |
| 102 | .update(dbServers) |
| 103 | .set(zServerUpdate.parse(combinedUpdateData)) |
| 104 | .where(eq(dbServers.id, update.id)); |
| 105 | |
| 106 | const updated = await db.query.dbServers.findFirst({ |
| 107 | where: eq(dbServers.id, update.id), |
| 108 | }); |
| 109 | |
| 110 | if (!updated) throw new Error(`Error updating server with id ${update.id}`); |
| 111 | return addFlagsToServer(updated); |
| 112 | } |
| 113 | |
| 114 | export async function findServerById(id: string) { |
| 115 | const found = await db.query.dbServers.findFirst({ |
no test coverage detected