forked from PalisadoesFoundation/talawa-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: User tags backend adjustments (GSoC) (PalisadoesFoundation#2460)
* add organization userTags connection * add tests * fix formatting issue * adjustments and queries for tag screens * fix linting
- Loading branch information
Showing
17 changed files
with
372 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { OrganizationTagUser } from "../../models"; | ||
import { errors, requestContext } from "../../libraries"; | ||
import type { QueryResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { TAG_NOT_FOUND } from "../../constants"; | ||
|
||
export const getUserTag: QueryResolvers["getUserTag"] = async ( | ||
_parent, | ||
args, | ||
) => { | ||
const userTag = await OrganizationTagUser.findById(args.id).lean(); | ||
|
||
if (!userTag) { | ||
throw new errors.NotFoundError( | ||
requestContext.translate(TAG_NOT_FOUND.MESSAGE), | ||
TAG_NOT_FOUND.CODE, | ||
TAG_NOT_FOUND.PARAM, | ||
); | ||
} | ||
|
||
return userTag; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { OrganizationTagUser } from "../../models"; | ||
import { errors, requestContext } from "../../libraries"; | ||
import type { QueryResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { TAG_NOT_FOUND } from "../../constants"; | ||
|
||
export const getUserTagAncestors: QueryResolvers["getUserTagAncestors"] = | ||
async (_parent, args) => { | ||
let currentTag = await OrganizationTagUser.findById(args.id).lean(); | ||
|
||
const tagAncestors = [currentTag]; | ||
|
||
while (currentTag?.parentTagId) { | ||
const currentParent = await OrganizationTagUser.findById( | ||
currentTag.parentTagId, | ||
).lean(); | ||
|
||
if (currentParent) { | ||
tagAncestors.push(currentParent); | ||
currentTag = currentParent; | ||
} | ||
} | ||
|
||
if (!currentTag) { | ||
throw new errors.NotFoundError( | ||
requestContext.translate(TAG_NOT_FOUND.MESSAGE), | ||
TAG_NOT_FOUND.CODE, | ||
TAG_NOT_FOUND.PARAM, | ||
); | ||
} | ||
|
||
return tagAncestors.reverse(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.