Skip to content

Commit 8e74cfe

Browse files
Test: src/graphql/types/Community/updater.ts (#3110)
* added test for updater.ts Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * added test for updater.ts Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * added test for updater.ts Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * Added changes Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * removed repeated test Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * removed repeated test Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * Added more tests Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * Added more tests Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * Added more tests Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * Added new tests Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * Added new tests Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * rabbits changes Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * Added tests Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * Linting done Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> * Linting done Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in> --------- Signed-off-by: NishantSinghhhhh <nishantsingh_230137@aitpune.edu.in>
1 parent 19b4d1e commit 8e74cfe

File tree

5 files changed

+414
-0
lines changed

5 files changed

+414
-0
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"minio": "^8.0.4",
2929
"postgres": "^3.4.5",
3030
"ulidx": "^2.4.1",
31+
"uuid": "^11.0.5",
3132
"uuidv7": "^1.0.2",
3233
"zod": "^3.24.1"
3334
},
@@ -38,6 +39,7 @@
3839
"@swc/cli": "0.6.0",
3940
"@swc/core": "^1.10.9",
4041
"@types/node": "^22.10.7",
42+
"@types/uuid": "^10.0.0",
4143
"@vitest/coverage-v8": "^3.0.3",
4244
"drizzle-kit": "^0.30.4",
4345
"drizzle-seed": "^0.3.1",

pnpm-lock.yaml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/graphql/types/Community/Community.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,76 @@
11
import type { communitiesTable } from "~/src/drizzle/tables/communities";
22
import { builder } from "~/src/graphql/builder";
3+
import { TalawaGraphQLError } from "~/src/utilities/TalawaGraphQLError";
4+
import type { GraphQLContext } from "../../context";
5+
import type { User } from "../User/User";
36

47
export type Community = typeof communitiesTable.$inferSelect;
58

69
export const Community = builder.objectRef<Community>("Community");
710

11+
export type CommunityResolvers = {
12+
updater: (
13+
parent: Community,
14+
_args: unknown,
15+
context: GraphQLContext,
16+
) => Promise<User | null>;
17+
};
18+
19+
export const CommunityResolver: CommunityResolvers = {
20+
updater: async (parent, _args, context) => {
21+
try {
22+
if (!context.currentClient.isAuthenticated) {
23+
throw new TalawaGraphQLError({
24+
message: "User is not authenticated",
25+
extensions: { code: "unauthenticated" },
26+
});
27+
}
28+
if (!parent.updaterId) {
29+
return null;
30+
}
31+
const updaterId = parent.updaterId;
32+
33+
const existingUser =
34+
await context.drizzleClient.query.usersTable.findFirst({
35+
where: (users, { eq }) => eq(users.id, updaterId), // Must use updaterId here
36+
});
37+
38+
if (existingUser === undefined) {
39+
context.log.warn(`No user found for updaterId: ${updaterId}`);
40+
throw new TalawaGraphQLError({
41+
message: "Updater user not found",
42+
extensions: {
43+
code: "arguments_associated_resources_not_found",
44+
issues: [{ argumentPath: ["updaterId"] }],
45+
},
46+
});
47+
}
48+
49+
const updater = await context.drizzleClient.query.usersTable.findFirst({
50+
where: (users, { eq, and, isNull }) =>
51+
parent.updaterId ? eq(users.id, parent.updaterId) : isNull(users.id),
52+
});
53+
54+
if (!updater) {
55+
context.log.warn(`No user found for updaterId: ${parent.updaterId}`);
56+
throw new TalawaGraphQLError({
57+
message: "Updater user not found",
58+
extensions: {
59+
code: "arguments_associated_resources_not_found",
60+
issues: [{ argumentPath: ["updaterId"] }],
61+
},
62+
});
63+
}
64+
return updater;
65+
} catch (error) {
66+
context.log.error("Database error in community updater resolver", {
67+
error,
68+
});
69+
throw error;
70+
}
71+
},
72+
};
73+
874
Community.implement({
975
description:
1076
"Communitys are controlled spaces of collections of users who associate with the purpose those communities exist for.",

0 commit comments

Comments
 (0)