Skip to content

Commit

Permalink
add coderabbitai suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
meetulr committed Nov 2, 2024
1 parent affa497 commit 3220b37
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/resolvers/User/tagsAssignedWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type ParsedCursor = string;
* @param cursorValue - The cursor value to be parsed.
* @param cursorName - The name of the cursor argument.
* @param cursorPath - The path of the cursor argument in the GraphQL query.
* @param tagId - The ID of the user to which the tags are assigned.
* @param userId - The ID of the user for which assigned tags are being queried.
* @returns An object containing the parsed cursor value or an array of errors if the cursor value is invalid.
*
* @see TagUser - The TagUser model used to interact with the tag users collection in the database.
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/UserTag/usersToAssignTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const usersToAssignTo: UserTagResolvers["usersToAssignTo"] = async (
{
$match: {
...objectListFilter,
joinedOrganizations: parent.organizationId,
joinedOrganizations: { $in: [parent.organizationId] },
},
},
...commonPipeline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type {
} from "../userTagsPaginationUtils";

/**
* This is typescript type of the object returned from function `getGraphQLConnectionFilter`.
* This is typescript type of the object returned from function `getUserTagGraphQLConnectionFilter`.
*/
type GraphQLConnectionFilter =
type UserTagGraphQLConnectionFilter =
| {
_id: {
$lt: string;
Expand Down Expand Up @@ -37,11 +37,14 @@ export function getUserTagGraphQLConnectionFilter({
ParseUserTagWhereResult & {
cursor: string | null;
direction: GraphQLConnectionTraversalDirection;
}): GraphQLConnectionFilter {
const filter = {} as GraphQLConnectionFilter;
}): UserTagGraphQLConnectionFilter {
const filter = {} as UserTagGraphQLConnectionFilter;

filter.name = {
$regex: new RegExp(`^${nameStartsWith}`, "i"),
$regex: new RegExp(
`^${nameStartsWith.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`,
"i",
),
};

if (cursor !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { GraphQLConnectionTraversalDirection } from ".";
import type { ParseSortedByResult } from "../userTagsPaginationUtils";

/**
*This is typescript type of the object returned from `getGraphQLConnectionSort` function.
*This is typescript type of the object returned from `getUserTagGraphQLConnectionSort` function.
*/
type GraphQLConnectionSort =
type UserTagGraphQLConnectionSort =
| {
_id: 1;
}
Expand All @@ -20,7 +20,7 @@ export function getUserTagGraphQLConnectionSort({
sortById,
}: ParseSortedByResult & {
direction: GraphQLConnectionTraversalDirection;
}): GraphQLConnectionSort {
}): UserTagGraphQLConnectionSort {
if (sortById === "ASCENDING") {
if (direction === "BACKWARD") {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type {
} from "../userTagsPaginationUtils";

/**
* This is typescript type of the object returned from function `getGraphQLConnectionFilter`.
* This is typescript type of the object returned from function `getUserTagMemberGraphQLConnectionFilter`.
*/
type GraphQLConnectionFilter =
type UserTagMemberGraphQLConnectionFilter =
| {
_id: {
$lt: Types.ObjectId;
Expand Down Expand Up @@ -45,14 +45,20 @@ export function getUserTagMemberGraphQLConnectionFilter({
ParseUserTagMemberWhereResult & {
cursor: string | null;
direction: GraphQLConnectionTraversalDirection;
}): GraphQLConnectionFilter {
const filter = {} as GraphQLConnectionFilter;
}): UserTagMemberGraphQLConnectionFilter {
const filter = {} as UserTagMemberGraphQLConnectionFilter;

filter.firstName = {
$regex: new RegExp(`^${firstNameStartsWith}`, "i"),
$regex: new RegExp(
`^${firstNameStartsWith.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`,
"i",
),
};
filter.lastName = {
$regex: new RegExp(`^${lastNameStartsWith}`, "i"),
$regex: new RegExp(
`^${lastNameStartsWith.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`,
"i",
),
};

if (cursor !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function parseUserTagMemberWhere(
} else {
if (!where.firstName && !where.lastName) {
errors.push({
message: `Atleast one of firstName or lastName should be provided`,
message: `At least one of firstName or lastName should be provided`,
path: ["where"],
});

Expand All @@ -45,7 +45,7 @@ export function parseUserTagMemberWhere(
) {
errors.push({
message: "Invalid firstName provided. It must be a string.",
path: ["whereFirstName"],
path: ["where", "firstName", "starts_with"],
});

return {
Expand All @@ -58,7 +58,7 @@ export function parseUserTagMemberWhere(
) {
errors.push({
message: "Invalid lastName provided. It must be a string.",
path: ["whereLastName"],
path: ["where", "lastName", "starts_with"],
});

return {
Expand Down
33 changes: 16 additions & 17 deletions src/utilities/userTagsPaginationUtils/parseUserTagSortedBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,24 @@ export function parseUserTagSortedBy(
isSuccessful: true,
parsedSortedBy: { sortById: "DESCENDING" },
};
} else {
if (sortedBy.id !== "DESCENDING" && sortedBy.id !== "ASCENDING") {
errors.push({
message:
"Invalid sortedById provided. It must be a of type SortedByOrder.",
path: ["sortedById"],
});

return {
isSuccessful: false,
errors,
};
}
}

if (sortedBy.id !== "DESCENDING" && sortedBy.id !== "ASCENDING") {
errors.push({
message:
"Invalid sortedById provided. It must be a of type SortedByOrder.",
path: ["sortedBy", "id"],
});
return {
isSuccessful: true,
parsedSortedBy: {
sortById: sortedBy.id,
},
isSuccessful: false,
errors,
};
}

return {
isSuccessful: true,
parsedSortedBy: {
sortById: sortedBy.id,
},
};
}
2 changes: 1 addition & 1 deletion src/utilities/userTagsPaginationUtils/parseUserTagWhere.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function parseUserTagWhere(
if (typeof where.name.starts_with !== "string") {
errors.push({
message: "Invalid name provided. It must be a string.",
path: ["whereName"],
path: ["where", "name", "starts_with"],
});

return {
Expand Down
10 changes: 9 additions & 1 deletion tests/resolvers/UserTag/ancestorTags.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ afterAll(async () => {
});

describe("resolvers -> Tag -> ancestorTags", () => {
it(`returns the correct ancestorTags array`, async () => {
it(`returns an empty ancestorTags array for the root tag`, async () => {
const parent = testRootTag as InterfaceOrganizationTagUser;

const payload = await ancestorTagsResolver?.(parent, {}, {});

expect(payload).toEqual([]);
});

it(`returns the correct ancestorTags array for a nested tag`, async () => {
const parent = testSubTagLevel2 as InterfaceOrganizationTagUser;

const payload = await ancestorTagsResolver?.(parent, {}, {});
Expand Down

0 comments on commit 3220b37

Please sign in to comment.