forked from PalisadoesFoundation/talawa-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the functionality to create tags for user (PalisadoesFounda…
…tion#1158) * Add userOrgTag schema * Update tag validation * Introduce tags and tagFolders in models * Export the newly added models * Add createTagFolder * Add removeTagFolder * Add updateTagFolder mutation * Add all tag created CRUD operations * Add assignTag and unassignTag mutations * Add usersByTag Query * Change models and move all migrations * Add users field on Tag Interface * Add field resolver to get all tags for a user * Add resolvers for tag folder structure * Improve validation and indexing in models * Update schema and models to remove tagFolder model * Update Tag field resolvers * Update field resolvers in User and Org models * Remove deprecated tagFolder mutation files * Update assign and unassign mutations, constants * Rename fields * Update createTag mutation * Migrate all error objects to the new style * Add tests for Tag field resolvers * Make changes to typedefs and model implementations as per the review * Change typedefs * Updated typedefs * Migrate models to allow assigning to multiple object types * Update tests for tag/userAssignedTo * Update pagination * Update typedefs * Remove OrganizationTags connection * Add pagination to usersAssignedTo.ts * Fix typos * Update typedefs * Add Error Type * Remove resolvers * Update generated types * Update comments * Update typedefs * Improve comments * Rename type * Bugfix
- Loading branch information
Showing
11 changed files
with
408 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Schema, model, PopulatedDoc, Types, Document, models } from "mongoose"; | ||
import { Interface_Organization } from "./Organization"; | ||
|
||
export interface Interface_OrganizationTagUser { | ||
_id: Types.ObjectId; | ||
organizationId: PopulatedDoc<Interface_Organization & Document>; | ||
parentTagId: PopulatedDoc<Interface_OrganizationTagUser & Document>; | ||
name: string; | ||
} | ||
|
||
// A User Tag is used for the categorization and the grouping of related users | ||
// Each tag belongs to a particular organization, and is private to the same. | ||
// Each tag can be nested to hold other sub-tags so as to create a heriecheal structure. | ||
const OrganizationTagUserSchema = new Schema({ | ||
name: { | ||
type: String, | ||
required: true, | ||
}, | ||
organizationId: { | ||
type: Schema.Types.ObjectId, | ||
ref: "Organization", | ||
required: true, | ||
}, | ||
parentTagId: { | ||
type: Schema.Types.ObjectId, | ||
ref: "OrganizationTagUser", | ||
required: false, | ||
default: null, // A null parent corresponds to a root tag in the organization | ||
}, | ||
}); | ||
|
||
OrganizationTagUserSchema.index( | ||
{ organizationId: 1, parentOrganizationTagUserId: 1, name: 1 }, | ||
{ unique: true } | ||
); | ||
|
||
const OrganizationTagUserModel = () => | ||
model<Interface_OrganizationTagUser>( | ||
"OrganizationTagUser", | ||
OrganizationTagUserSchema | ||
); | ||
|
||
// This syntax is needed to prevent Mongoose OverwriteModelError while running tests. | ||
export const OrganizationTagUser = (models.OrganizationTagUser || | ||
OrganizationTagUserModel()) as ReturnType<typeof OrganizationTagUserModel>; |
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 { Schema, model, PopulatedDoc, Types, Document, models } from "mongoose"; | ||
import { Interface_OrganizationTagUser } from "./OrganizationTagUser"; | ||
import { Interface_User } from "./User"; | ||
|
||
export interface Interface_TagUser { | ||
_id: Types.ObjectId; | ||
userId: PopulatedDoc<Interface_User & Document>; | ||
tagId: PopulatedDoc<Interface_OrganizationTagUser & Document>; | ||
} | ||
|
||
// Relational schema used to keep track of assigned tags to users | ||
const TagUserSchema = new Schema({ | ||
userId: { | ||
type: Schema.Types.ObjectId, | ||
required: true, | ||
ref: "User", | ||
}, | ||
tagId: { | ||
type: Schema.Types.ObjectId, | ||
ref: "OrganizationTagUser", | ||
required: true, | ||
}, | ||
}); | ||
|
||
TagUserSchema.index({ userId: 1, tagId: 1 }, { unique: true }); | ||
|
||
const TagUserModel = () => model<Interface_TagUser>("TagUser", TagUserSchema); | ||
|
||
// This syntax is needed to prevent Mongoose OverwriteModelError while running tests. | ||
export const TagUser = (models.TagUser || TagUserModel()) as ReturnType< | ||
typeof TagUserModel | ||
>; |
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
Oops, something went wrong.