MCPcopy Index your code
hub / github.com/AnswerOverflow/AnswerOverflow / mutateServer

Function mutateServer

packages/api/src/router/server.ts:49–79  ·  view source on GitHub ↗
({
	operation,
	server,
	ctx,
}: {
	operation: (input: {
		oldSettings: ServerWithFlags;
		doSettingsExistAlready: boolean;
	}) => Promise<ServerWithFlags>;
	server: z.infer<typeof zServerCreate>;
	ctx: Context;
})

Source from the content-addressed store, hash-verified

47);
48
49async function mutateServer({
50 operation,
51 server,
52 ctx,
53}: {
54 operation: (input: {
55 oldSettings: ServerWithFlags;
56 doSettingsExistAlready: boolean;
57 }) => Promise<ServerWithFlags>;
58 server: z.infer<typeof zServerCreate>;
59 ctx: Context;
60}) {
61 return protectedMutation({
62 permissions: () => assertCanEditServer(ctx, server.id),
63 operation: async () => {
64 let oldSettings = await findServerById(server.id);
65 let doSettingsExistAlready = true;
66 if (!oldSettings) {
67 oldSettings = getDefaultServerWithFlags({
68 id: server.id,
69 name: server.name,
70 icon: server.icon,
71 });
72 doSettingsExistAlready = false;
73 } else {
74 doSettingsExistAlready = true;
75 }
76 return operation({ oldSettings, doSettingsExistAlready });
77 },
78 });
79}
80
81export const serverRouter = router({
82 byId: withUserServersProcedure

Callers 1

server.tsFile · 0.85

Calls 5

protectedMutationFunction · 0.90
assertCanEditServerFunction · 0.90
findServerByIdFunction · 0.90
operationFunction · 0.70

Tested by

no test coverage detected