({ old, updated }: { old: F; updated: T })
| 20 | } from './zod'; |
| 21 | |
| 22 | export async function applyServerSettingsSideEffects< |
| 23 | F extends { bitfield: number }, |
| 24 | T extends z.infer<typeof zServerMutable>, |
| 25 | >({ old, updated }: { old: F; updated: T }) { |
| 26 | const { flags, ...updateDataWithoutFlags } = updated; |
| 27 | if (updateDataWithoutFlags.vanityUrl) { |
| 28 | const doesAliasExistAlready = await findServerByAliasOrId( |
| 29 | updateDataWithoutFlags.vanityUrl, |
| 30 | ); |
| 31 | if (doesAliasExistAlready) { |
| 32 | throw new Error( |
| 33 | `Server with alias ${updateDataWithoutFlags.vanityUrl} already exists`, |
| 34 | ); |
| 35 | } |
| 36 | } |
| 37 | return { |
| 38 | ...updateDataWithoutFlags, |
| 39 | bitfield: flags ? mergeServerFlags(old.bitfield, flags) : undefined, |
| 40 | }; |
| 41 | } |
| 42 | |
| 43 | export async function findServerByCustomDomain(domain: string) { |
| 44 | const found = await db.query.dbServers.findFirst({ |
no test coverage detected