MCPcopy Create free account
hub / github.com/monkeytypegame/monkeytype / createConnection

Function createConnection

backend/src/api/controllers/connections.ts:38–62  ·  view source on GitHub ↗
(
  req: MonkeyRequest<undefined, CreateConnectionRequest>,
)

Source from the content-addressed store, hash-verified

36}
37
38export async function createConnection(
39 req: MonkeyRequest<undefined, CreateConnectionRequest>,
40): Promise<CreateConnectionResponse> {
41 const { uid } = req.ctx.decodedToken;
42 const { receiverName } = req.body;
43 const { maxPerUser } = req.ctx.configuration.connections;
44
45 const receiver = await UserDal.getUserByName(
46 receiverName,
47 "create connection",
48 );
49
50 if (uid === receiver.uid) {
51 throw new MonkeyError(400, "You cannot be your own friend, sorry.");
52 }
53
54 const initiator = await UserDal.getPartialUser(uid, "create connection", [
55 "uid",
56 "name",
57 ]);
58
59 const result = await ConnectionsDal.create(initiator, receiver, maxPerUser);
60
61 return new MonkeyResponse("Connection created", convert(result));
62}
63
64export async function deleteConnection(
65 req: MonkeyRequest<undefined, undefined, IdPathParams>,

Callers

nothing calls this directly

Calls 1

convertFunction · 0.70

Tested by

no test coverage detected