-
-
Notifications
You must be signed in to change notification settings - Fork 888
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for Action Items (#1648)
* feat: Add support for Categories * feat: Add support for Action Items * minor corrections * Add Organization-Category two way relationship * Add Event-ActionItem two way relationship * Add cascade delete functionality on Organization deletion * Add tests for Categories * Add tests for Action Items * fix typos in comments * Add check for action item assignee being an organization member * update to more meaningful field names in mongoose schema * remove the updatedBy field * remove schema.graphql * restore schema.graphql to upstream/develop * update field name and make resolvers nullable * merge upstream/develop into develop * update generatedGraphqlTypes * change Category name to ActionItemCategory * update field names * remove redundant relationships from Organization and Event * making actionItemCategory name unique for a given Organization * minor correction * update Action Item inputs * add actionItemsByOrganization query * add constant for milliseconds in a week * restore unwanted changes * Revert "add constant for milliseconds in a week" This reverts commit 0476a35. * add constant for milliseconds in a week
- Loading branch information
Showing
68 changed files
with
3,420 additions
and
4 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
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,107 @@ | ||
import type { PopulatedDoc, Types, Document, Model } from "mongoose"; | ||
import { Schema, model, models } from "mongoose"; | ||
import type { InterfaceUser } from "./User"; | ||
import type { InterfaceEvent } from "./Event"; | ||
import type { InterfaceActionItemCategory } from "./ActionItemCategory"; | ||
import { MILLISECONDS_IN_A_WEEK } from "../constants"; | ||
|
||
/** | ||
* This is an interface that represents a database(MongoDB) document for ActionItem. | ||
*/ | ||
|
||
export interface InterfaceActionItem { | ||
_id: Types.ObjectId; | ||
assigneeId: PopulatedDoc<InterfaceUser & Document>; | ||
assignerId: PopulatedDoc<InterfaceUser & Document>; | ||
actionItemCategoryId: PopulatedDoc<InterfaceActionItemCategory & Document>; | ||
preCompletionNotes: string; | ||
postCompletionNotes: string; | ||
assignmentDate: Date; | ||
dueDate: Date; | ||
completionDate: Date; | ||
isCompleted: boolean; | ||
eventId: PopulatedDoc<InterfaceEvent & Document>; | ||
creatorId: PopulatedDoc<InterfaceUser & Document>; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
} | ||
|
||
/** | ||
* This describes the schema for a `ActionItem` that corresponds to `InterfaceActionItem` document. | ||
* @param assigneeId - User to whom the ActionItem is assigned, refer to `User` model. | ||
* @param assignerId - User who assigned the ActionItem, refer to the `User` model. | ||
* @param actionItemCategoryId - ActionItemCategory to which the ActionItem is related, refer to the `ActionItemCategory` model. | ||
* @param preCompletionNotes - Notes prior to completion. | ||
* @param postCompletionNotes - Notes on completion. | ||
* @param assignmentDate - Date of assignment. | ||
* @param dueDate - Due date. | ||
* @param completionDate - Completion date. | ||
* @param isCompleted - Whether the ActionItem has been completed. | ||
* @param eventId - Event to which the ActionItem is related, refer to the `Event` model. | ||
* @param creatorId - User who created the ActionItem, refer to the `User` model. | ||
* @param createdAt - Timestamp when the ActionItem was created. | ||
* @param updatedAt - Timestamp when the ActionItem was last updated. | ||
*/ | ||
|
||
const actionItemSchema = new Schema( | ||
{ | ||
assigneeId: { | ||
type: Schema.Types.ObjectId, | ||
ref: "User", | ||
required: true, | ||
}, | ||
assignerId: { | ||
type: Schema.Types.ObjectId, | ||
ref: "User", | ||
required: true, | ||
}, | ||
actionItemCategoryId: { | ||
type: Schema.Types.ObjectId, | ||
ref: "ActionItemCategory", | ||
required: true, | ||
}, | ||
preCompletionNotes: { | ||
type: String, | ||
}, | ||
postCompletionNotes: { | ||
type: String, | ||
}, | ||
assignmentDate: { | ||
type: Date, | ||
required: true, | ||
default: Date.now(), | ||
}, | ||
dueDate: { | ||
type: Date, | ||
required: true, | ||
default: Date.now() + MILLISECONDS_IN_A_WEEK, | ||
}, | ||
completionDate: { | ||
type: Date, | ||
required: true, | ||
default: Date.now() + MILLISECONDS_IN_A_WEEK, | ||
}, | ||
isCompleted: { | ||
type: Boolean, | ||
required: true, | ||
default: false, | ||
}, | ||
eventId: { | ||
type: Schema.Types.ObjectId, | ||
ref: "Event", | ||
}, | ||
creatorId: { | ||
type: Schema.Types.ObjectId, | ||
ref: "User", | ||
required: true, | ||
}, | ||
}, | ||
{ timestamps: true } | ||
); | ||
|
||
const actionItemModel = (): Model<InterfaceActionItem> => | ||
model<InterfaceActionItem>("ActionItem", actionItemSchema); | ||
|
||
// This syntax is needed to prevent Mongoose OverwriteModelError while running tests. | ||
export const ActionItem = (models.ActionItem || | ||
actionItemModel()) as ReturnType<typeof actionItemModel>; |
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,68 @@ | ||
import type { PopulatedDoc, Types, Document, Model } from "mongoose"; | ||
import { Schema, model, models } from "mongoose"; | ||
import type { InterfaceUser } from "./User"; | ||
import type { InterfaceOrganization } from "./Organization"; | ||
|
||
/** | ||
* This is an interface that represents a database(MongoDB) document for ActionItemCategory. | ||
*/ | ||
|
||
export interface InterfaceActionItemCategory { | ||
_id: Types.ObjectId; | ||
name: string; | ||
organizationId: PopulatedDoc<InterfaceOrganization & Document>; | ||
isDisabled: boolean; | ||
creatorId: PopulatedDoc<InterfaceUser & Document>; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
} | ||
|
||
/** | ||
* This describes the schema for a `actionItemCategory` that corresponds to `InterfaceCategory` document. | ||
* @param name - An actionItemCategory to be selected for ActionItems. | ||
* @param organizationId - Organization the actionItemCategory belongs to, refer to the `Organization` model. | ||
* @param isDisabled - Whether actionItemCategory is disabled or not. | ||
* @param creatorId - Task creator, refer to `User` model. | ||
* @param createdAt - Time stamp of data creation. | ||
* @param updatedAt - Time stamp of data updation. | ||
*/ | ||
|
||
const actionItemCategorySchema = new Schema( | ||
{ | ||
name: { | ||
type: String, | ||
required: true, | ||
}, | ||
organizationId: { | ||
type: Schema.Types.ObjectId, | ||
ref: "Organization", | ||
required: true, | ||
}, | ||
isDisabled: { | ||
type: Boolean, | ||
required: true, | ||
default: false, | ||
}, | ||
creatorId: { | ||
type: Schema.Types.ObjectId, | ||
ref: "User", | ||
required: true, | ||
}, | ||
}, | ||
{ timestamps: true } | ||
); | ||
|
||
actionItemCategorySchema.index( | ||
{ organizationId: 1, name: 1 }, | ||
{ unique: true } | ||
); | ||
|
||
const actionItemCategoryModel = (): Model<InterfaceActionItemCategory> => | ||
model<InterfaceActionItemCategory>( | ||
"ActionItemCategory", | ||
actionItemCategorySchema | ||
); | ||
|
||
// This syntax is needed to prevent Mongoose OverwriteModelError while running tests. | ||
export const ActionItemCategory = (models.ActionItemCategory || | ||
actionItemCategoryModel()) as ReturnType<typeof actionItemCategoryModel>; |
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,9 @@ | ||
import type { ActionItemResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { ActionItemCategory } from "../../models"; | ||
|
||
export const actionItemCategory: ActionItemResolvers["actionItemCategory"] = | ||
async (parent) => { | ||
return ActionItemCategory.findOne({ | ||
_id: parent.actionItemCategoryId, | ||
}).lean(); | ||
}; |
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,8 @@ | ||
import type { ActionItemResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { User } from "../../models"; | ||
|
||
export const assignee: ActionItemResolvers["assignee"] = async (parent) => { | ||
return User.findOne({ | ||
_id: parent.assigneeId, | ||
}).lean(); | ||
}; |
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,8 @@ | ||
import type { ActionItemResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { User } from "../../models"; | ||
|
||
export const assigner: ActionItemResolvers["assigner"] = async (parent) => { | ||
return User.findOne({ | ||
_id: parent.assignerId, | ||
}).lean(); | ||
}; |
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,8 @@ | ||
import type { ActionItemResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { User } from "../../models"; | ||
|
||
export const creator: ActionItemResolvers["creator"] = async (parent) => { | ||
return User.findOne({ | ||
_id: parent.creatorId, | ||
}).lean(); | ||
}; |
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,8 @@ | ||
import type { ActionItemResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { Event } from "../../models"; | ||
|
||
export const event: ActionItemResolvers["event"] = async (parent) => { | ||
return Event.findOne({ | ||
_id: parent.eventId, | ||
}).lean(); | ||
}; |
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,14 @@ | ||
import type { ActionItemResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { assignee } from "./assignee"; | ||
import { assigner } from "./assigner"; | ||
import { actionItemCategory } from "./actionItemCategory"; | ||
import { event } from "./event"; | ||
import { creator } from "./creator"; | ||
|
||
export const ActionItem: ActionItemResolvers = { | ||
assignee, | ||
assigner, | ||
actionItemCategory, | ||
event, | ||
creator, | ||
}; |
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,10 @@ | ||
import type { ActionItemCategoryResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { User } from "../../models"; | ||
|
||
export const creator: ActionItemCategoryResolvers["creator"] = async ( | ||
parent | ||
) => { | ||
return User.findOne({ | ||
_id: parent.creatorId, | ||
}).lean(); | ||
}; |
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,8 @@ | ||
import type { ActionItemCategoryResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { organization } from "./organization"; | ||
import { creator } from "./creator"; | ||
|
||
export const ActionItemCategory: ActionItemCategoryResolvers = { | ||
organization, | ||
creator, | ||
}; |
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,10 @@ | ||
import type { ActionItemCategoryResolvers } from "../../types/generatedGraphQLTypes"; | ||
import { Organization } from "../../models"; | ||
|
||
export const organization: ActionItemCategoryResolvers["organization"] = async ( | ||
parent | ||
) => { | ||
return Organization.findOne({ | ||
_id: parent.organizationId, | ||
}).lean(); | ||
}; |
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,12 @@ | ||
import { ActionItem } from "../../models"; | ||
import type { EventResolvers } from "../../types/generatedGraphQLTypes"; | ||
/** | ||
* This resolver function will fetch and return the action items related to the event from database. | ||
* @param parent - An object that is the return value of the resolver for this field's parent. | ||
* @returns An object that contains the list of all action items related to the event. | ||
*/ | ||
export const actionItems: EventResolvers["actionItems"] = async (parent) => { | ||
return await ActionItem.find({ | ||
eventId: parent._id, | ||
}).lean(); | ||
}; |
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.