diff --git a/codegen.ts b/codegen.ts index 9b193a3228..47f6985cad 100644 --- a/codegen.ts +++ b/codegen.ts @@ -27,7 +27,8 @@ const config: CodegenConfig = { mappers: { ActionItem: "../models/ActionItem#InterfaceActionItem", - ActionItemCategory: "../models/ActionItemCategory#InterfaceActionItemCategory", + ActionItemCategory: + "../models/ActionItemCategory#InterfaceActionItemCategory", CheckIn: "../models/CheckIn#InterfaceCheckIn", diff --git a/locales/en.json b/locales/en.json index d977539b13..69060fe459 100644 --- a/locales/en.json +++ b/locales/en.json @@ -4,7 +4,8 @@ "user.notFound": "User not found", "user.alreadyMember": "User is already a member", "user.profileImage.notFound": "User profile image not found", - "actionItemCategory.notFound": "ActionItemCategory not found", + "actionItemCategory.notFound": "Action Item Category not found", + "actionItemCategory.alreadyExists": "Action Item Category already exists", "actionItem.notFound": "Action Item not found", "advertisement.notFound": "Advertisement not found", "event.notFound": "Event not found", diff --git a/locales/fr.json b/locales/fr.json index 61e52816a1..d3fafdc5cb 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -4,7 +4,8 @@ "user.notFound": "Utilisateur introuvable", "user.alreadyMember": "L'utilisateur est déjà membre", "user.profileImage.notFound": "Image du profil utilisateur introuvable", - "actionItemCategory.notFound": "Catégorie non trouvée", + "actionItemCategory.notFound": "Catégorie d’élément d’action introuvable", + "actionItemCategory.alreadyExists": "La catégorie d’élément d’action existe déjà", "actionItem.notFound": "Élément d\\’action non trouvé", "event.notFound": "Événement non trouvé", "organization.notFound": "Organisation introuvable", diff --git a/locales/hi.json b/locales/hi.json index 79c9071e0b..959f97b093 100644 --- a/locales/hi.json +++ b/locales/hi.json @@ -5,6 +5,7 @@ "user.alreadyMember": "उपयोगकर्ता पहले से ही एक सदस्य है", "user.profileImage.notFound": "उपयोगकर्ता प्रोफ़ाइल छवि नहीं मिली", "actionItemCategory.notFound": "श्रेणी नहीं मिली", + "actionItemCategory.alreadyExists": "यह श्रेणी पहले से मौजूद है", "actionItem.notFound": "कार्रवाई का मद नहीं मिला", "advertisement.notFound": "विज्ञापन नहीं मिला", "event.notFound": "घटना नहीं मिली", diff --git a/locales/sp.json b/locales/sp.json index 4923eab91a..cfee07ce87 100644 --- a/locales/sp.json +++ b/locales/sp.json @@ -4,7 +4,8 @@ "user.notFound": "Usuario no encontrado", "user.alreadyMember": "El usuario ya es miembro", "user.profileImage.notFound": "No se encontró la imagen de perfil de usuario", - "actionItemCategory.notFound": "Categoría no encontrada", + "actionItemCategory.notFound": "No se encontró la categoría de elemento de acción", + "actionItemCategory.alreadyExists": "Ya existe una categoría de elemento de acción", "actionItem.notFound": "Elemento de acción no encontrado", "event.notFound": "Evento no encontrado", "organization.notFound": "Organización no encontrada", diff --git a/locales/zh.json b/locales/zh.json index cef354813a..5ef0656cb6 100644 --- a/locales/zh.json +++ b/locales/zh.json @@ -4,7 +4,8 @@ "user.notFound": "找不到用戶", "user.alreadyMember": "用戶已經是會員", "user.profileImage.notFound": "未找到用戶個人資料圖像", - "actionItemCategory.notFound": "找不到类别", + "actionItemCategory.notFound": "未找到措施项类别", + "actionItemCategory.alreadyExists": "措施项类别已存在", "actionItem.notFound": "找不到操作项", "event.notFound": "未找到事件", "organization.notFound": "未找到組織", diff --git a/src/constants.ts b/src/constants.ts index e026f25991..22ef758fb3 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -21,6 +21,13 @@ export const ACTION_ITEM_CATEGORY_NOT_FOUND_ERROR = { PARAM: "actionItemCategory", }; +export const ACTION_ITEM_CATEGORY_ALREADY_EXISTS = { + DESC: "Action Item Category already exists", + CODE: "actionItemCategory.alreadyExists", + MESSAGE: "actionItemCategory.alreadyExists", + PARAM: "actionItemCategory", +}; + export const CHAT_NOT_FOUND_ERROR = { DESC: "Chat not found", CODE: "chat.notFound", diff --git a/src/models/ActionItemCategory.ts b/src/models/ActionItemCategory.ts index 1d2e32c165..4110dfa88c 100644 --- a/src/models/ActionItemCategory.ts +++ b/src/models/ActionItemCategory.ts @@ -52,10 +52,17 @@ const actionItemCategorySchema = new Schema( { timestamps: true } ); +actionItemCategorySchema.index( + { organizationId: 1, name: 1 }, + { unique: true } +); + const actionItemCategoryModel = (): Model => - model("ActionItemCategory", actionItemCategorySchema); + model( + "ActionItemCategory", + actionItemCategorySchema + ); // This syntax is needed to prevent Mongoose OverwriteModelError while running tests. -export const ActionItemCategory = (models.ActionItemCategory || actionItemCategoryModel()) as ReturnType< - typeof actionItemCategoryModel ->; +export const ActionItemCategory = (models.ActionItemCategory || + actionItemCategoryModel()) as ReturnType; diff --git a/src/resolvers/ActionItem/actionItemCategory.ts b/src/resolvers/ActionItem/actionItemCategory.ts index e9e3c5e293..146d836017 100644 --- a/src/resolvers/ActionItem/actionItemCategory.ts +++ b/src/resolvers/ActionItem/actionItemCategory.ts @@ -1,8 +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(); -}; +export const actionItemCategory: ActionItemResolvers["actionItemCategory"] = + async (parent) => { + return ActionItemCategory.findOne({ + _id: parent.actionItemCategoryId, + }).lean(); + }; diff --git a/src/resolvers/ActionItemCategory/creator.ts b/src/resolvers/ActionItemCategory/creator.ts index 4e39055a8f..b9d355ed0a 100644 --- a/src/resolvers/ActionItemCategory/creator.ts +++ b/src/resolvers/ActionItemCategory/creator.ts @@ -1,7 +1,9 @@ import type { ActionItemCategoryResolvers } from "../../types/generatedGraphQLTypes"; import { User } from "../../models"; -export const creator: ActionItemCategoryResolvers["creator"] = async (parent) => { +export const creator: ActionItemCategoryResolvers["creator"] = async ( + parent +) => { return User.findOne({ _id: parent.creatorId, }).lean(); diff --git a/src/resolvers/ActionItemCategory/organization.ts b/src/resolvers/ActionItemCategory/organization.ts index 0ba8db4aeb..98fcb42897 100644 --- a/src/resolvers/ActionItemCategory/organization.ts +++ b/src/resolvers/ActionItemCategory/organization.ts @@ -1,7 +1,9 @@ import type { ActionItemCategoryResolvers } from "../../types/generatedGraphQLTypes"; import { Organization } from "../../models"; -export const organization: ActionItemCategoryResolvers["organization"] = async (parent) => { +export const organization: ActionItemCategoryResolvers["organization"] = async ( + parent +) => { return Organization.findOne({ _id: parent.organizationId, }).lean(); diff --git a/src/resolvers/Event/actionItems.ts b/src/resolvers/Event/actionItems.ts index f1c83a7d1d..0fcc7b29fb 100644 --- a/src/resolvers/Event/actionItems.ts +++ b/src/resolvers/Event/actionItems.ts @@ -7,6 +7,6 @@ import type { EventResolvers } from "../../types/generatedGraphQLTypes"; */ export const actionItems: EventResolvers["actionItems"] = async (parent) => { return await ActionItem.find({ - eventId: parent._id + eventId: parent._id, }).lean(); }; diff --git a/src/resolvers/Mutation/createActionItemCategory.ts b/src/resolvers/Mutation/createActionItemCategory.ts index 74b601fb5d..62182ff432 100644 --- a/src/resolvers/Mutation/createActionItemCategory.ts +++ b/src/resolvers/Mutation/createActionItemCategory.ts @@ -4,6 +4,7 @@ import { errors, requestContext } from "../../libraries"; import { USER_NOT_FOUND_ERROR, ORGANIZATION_NOT_FOUND_ERROR, + ACTION_ITEM_CATEGORY_ALREADY_EXISTS, } from "../../constants"; import { adminCheck } from "../../utilities"; @@ -22,57 +23,72 @@ import { cacheOrganizations } from "../../services/OrganizationCache/cacheOrgani * @returns Created ActionItemCategory */ -export const createActionItemCategory: MutationResolvers["createActionItemCategory"] = async ( - _parent, - args, - context -) => { - const currentUser = await User.findOne({ - _id: context.userId, - }); - - // Checks whether currentUser with _id == context.userId exists. - if (currentUser === null) { - throw new errors.NotFoundError( - requestContext.translate(USER_NOT_FOUND_ERROR.MESSAGE), - USER_NOT_FOUND_ERROR.CODE, - USER_NOT_FOUND_ERROR.PARAM - ); - } - - let organization; - - const organizationFoundInCache = await findOrganizationsInCache([args.organizationId]); - - organization = organizationFoundInCache[0]; - - if (organizationFoundInCache[0] == null) { - organization = await Organization.findOne({ - _id: args.organizationId, - }).lean(); - - await cacheOrganizations([organization!]); - } - - // Checks whether the organization with _id === args.organizationId exists. - if (!organization) { - throw new errors.NotFoundError( - requestContext.translate(ORGANIZATION_NOT_FOUND_ERROR.MESSAGE), - ORGANIZATION_NOT_FOUND_ERROR.CODE, - ORGANIZATION_NOT_FOUND_ERROR.PARAM - ); - } - - // Checks whether the user is authorized to perform the operation - await adminCheck(context.userId, organization); - - // Creates new actionItemCategory. - const createdActionItemCategory = await ActionItemCategory.create({ - name: args.name, - organizationId: args.organizationId, - creatorId: context.userId, - }); - - // Returns created actionItemCategory. - return createdActionItemCategory.toObject(); -}; +export const createActionItemCategory: MutationResolvers["createActionItemCategory"] = + async (_parent, args, context) => { + const currentUser = await User.findOne({ + _id: context.userId, + }); + + // Checks whether currentUser with _id == context.userId exists. + if (currentUser === null) { + throw new errors.NotFoundError( + requestContext.translate(USER_NOT_FOUND_ERROR.MESSAGE), + USER_NOT_FOUND_ERROR.CODE, + USER_NOT_FOUND_ERROR.PARAM + ); + } + + let organization; + + const organizationFoundInCache = await findOrganizationsInCache([ + args.organizationId, + ]); + + organization = organizationFoundInCache[0]; + + if (organizationFoundInCache[0] == null) { + organization = await Organization.findOne({ + _id: args.organizationId, + }).lean(); + + await cacheOrganizations([organization!]); + } + + // Checks whether + + // Checks whether the organization with _id === args.organizationId exists. + if (!organization) { + throw new errors.NotFoundError( + requestContext.translate(ORGANIZATION_NOT_FOUND_ERROR.MESSAGE), + ORGANIZATION_NOT_FOUND_ERROR.CODE, + ORGANIZATION_NOT_FOUND_ERROR.PARAM + ); + } + + // Checks whether the user is authorized to perform the operation + await adminCheck(context.userId, organization); + + // Checks whether an actionItemCategory with given name already exists for the current organization + const existingActionItemCategory = await ActionItemCategory.findOne({ + organizationId: organization?._id, + name: args.name, + }); + + if (existingActionItemCategory) { + throw new errors.ConflictError( + requestContext.translate(ACTION_ITEM_CATEGORY_ALREADY_EXISTS.MESSAGE), + ACTION_ITEM_CATEGORY_ALREADY_EXISTS.CODE, + ACTION_ITEM_CATEGORY_ALREADY_EXISTS.PARAM + ); + } + + // Creates new actionItemCategory. + const createdActionItemCategory = await ActionItemCategory.create({ + name: args.name, + organizationId: args.organizationId, + creatorId: context.userId, + }); + + // Returns created actionItemCategory. + return createdActionItemCategory.toObject(); + }; diff --git a/src/resolvers/Mutation/index.ts b/src/resolvers/Mutation/index.ts index 823a70fe8f..68e6c4c916 100644 --- a/src/resolvers/Mutation/index.ts +++ b/src/resolvers/Mutation/index.ts @@ -31,7 +31,7 @@ import { createPlugin } from "./createPlugin"; import { createAdvertisement } from "./createAdvertisement"; import { createPost } from "./createPost"; import { createSampleOrganization } from "./createSampleOrganization"; -import { createCategory } from "./createActionItemCategory"; +import { createActionItemCategory } from "./createActionItemCategory"; import { createUserTag } from "./createUserTag"; import { deleteDonationById } from "./deleteDonationById"; import { forgotPassword } from "./forgotPassword"; @@ -78,7 +78,7 @@ import { unlikeComment } from "./unlikeComment"; import { unlikePost } from "./unlikePost"; import { unregisterForEventByUser } from "./unregisterForEventByUser"; import { updateActionItem } from "./updateActionItem"; -import { updateCategory } from "./updateActionItemCategory"; +import { updateActionItemCategory } from "./updateActionItemCategory"; import { updateEvent } from "./updateEvent"; import { updateLanguage } from "./updateLanguage"; import { updateOrganization } from "./updateOrganization"; @@ -124,7 +124,7 @@ export const Mutation: MutationResolvers = { createPlugin, createPost, createSampleOrganization, - createCategory, + createActionItemCategory, createUserTag, deleteDonationById, deleteAdvertisementById, @@ -172,7 +172,7 @@ export const Mutation: MutationResolvers = { unlikePost, unregisterForEventByUser, updateActionItem, - updateCategory, + updateActionItemCategory, updateEvent, updateLanguage, updateOrganization, diff --git a/src/resolvers/Mutation/removeActionItem.ts b/src/resolvers/Mutation/removeActionItem.ts index 06eecc943a..ae1c023213 100644 --- a/src/resolvers/Mutation/removeActionItem.ts +++ b/src/resolvers/Mutation/removeActionItem.ts @@ -59,7 +59,9 @@ export const removeActionItem: MutationResolvers["removeActionItem"] = async ( const currentUserIsOrgAdmin = currentUser.adminFor.some( (ogranizationId) => ogranizationId === actionItem.actionItemCategoryId.organizationId || - Types.ObjectId(ogranizationId).equals(actionItem.actionItemCategoryId.organizationId) + Types.ObjectId(ogranizationId).equals( + actionItem.actionItemCategoryId.organizationId + ) ); let currentUserIsEventAdmin = false; diff --git a/src/resolvers/Mutation/removeOrganization.ts b/src/resolvers/Mutation/removeOrganization.ts index 38cffbcada..5396eaaef8 100644 --- a/src/resolvers/Mutation/removeOrganization.ts +++ b/src/resolvers/Mutation/removeOrganization.ts @@ -128,11 +128,17 @@ export const removeOrganization: MutationResolvers["removeOrganization"] = ); // Get the ids of all ActionItemCategories associated with the organization - const actionItemCategories = await ActionItemCategory.find({ organizationId: organization?._id }); - const actionItemCategoriesIds = actionItemCategories.map(category => category._id); + const actionItemCategories = await ActionItemCategory.find({ + organizationId: organization?._id, + }); + const actionItemCategoriesIds = actionItemCategories.map( + (category) => category._id + ); // Remove all ActionItemCategory documents whose id is in the actionItemCategories array - await ActionItemCategory.deleteMany({ _id: { $in: actionItemCategoriesIds } }); + await ActionItemCategory.deleteMany({ + _id: { $in: actionItemCategoriesIds }, + }); // Remove all ActionItem documents whose actionItemCategory is in the actionItemCategories array await ActionItem.deleteMany({ diff --git a/src/resolvers/Mutation/updateActionItem.ts b/src/resolvers/Mutation/updateActionItem.ts index 9aadef364d..c0fadbe810 100644 --- a/src/resolvers/Mutation/updateActionItem.ts +++ b/src/resolvers/Mutation/updateActionItem.ts @@ -110,7 +110,9 @@ export const updateActionItem: MutationResolvers["updateActionItem"] = async ( const currentUserIsOrgAdmin = currentUser.adminFor.some( (ogranizationId) => ogranizationId === actionItem.actionItemCategoryId.organizationId || - Types.ObjectId(ogranizationId).equals(actionItem.actionItemCategoryId.organizationId) + Types.ObjectId(ogranizationId).equals( + actionItem.actionItemCategoryId.organizationId + ) ); let currentUserIsEventAdmin = false; diff --git a/src/resolvers/Mutation/updateActionItemCategory.ts b/src/resolvers/Mutation/updateActionItemCategory.ts index 0767fd3b2c..d2deaf31f8 100644 --- a/src/resolvers/Mutation/updateActionItemCategory.ts +++ b/src/resolvers/Mutation/updateActionItemCategory.ts @@ -23,52 +23,49 @@ type UpdateActionItemCategoryInputType = { isDisabled: boolean; }; -export const updateActionItemCategory: MutationResolvers["updateActionItemCategory"] = async ( - _parent, - args, - context -) => { - const currentUser = await User.findOne({ - _id: context.userId, - }); +export const updateActionItemCategory: MutationResolvers["updateActionItemCategory"] = + async (_parent, args, context) => { + const currentUser = await User.findOne({ + _id: context.userId, + }); - // Checks if the user exists - if (currentUser === null) { - throw new errors.NotFoundError( - requestContext.translate(USER_NOT_FOUND_ERROR.MESSAGE), - USER_NOT_FOUND_ERROR.CODE, - USER_NOT_FOUND_ERROR.PARAM - ); - } + // Checks if the user exists + if (currentUser === null) { + throw new errors.NotFoundError( + requestContext.translate(USER_NOT_FOUND_ERROR.MESSAGE), + USER_NOT_FOUND_ERROR.CODE, + USER_NOT_FOUND_ERROR.PARAM + ); + } - const actionItemCategory = await ActionItemCategory.findOne({ - _id: args.id, - }) - .populate("organizationId") - .lean(); + const actionItemCategory = await ActionItemCategory.findOne({ + _id: args.id, + }) + .populate("organizationId") + .lean(); - // Checks if the actionItemCategory exists - if (!actionItemCategory) { - throw new errors.NotFoundError( - requestContext.translate(ACTION_ITEM_CATEGORY_NOT_FOUND_ERROR.MESSAGE), - ACTION_ITEM_CATEGORY_NOT_FOUND_ERROR.CODE, - ACTION_ITEM_CATEGORY_NOT_FOUND_ERROR.PARAM - ); - } + // Checks if the actionItemCategory exists + if (!actionItemCategory) { + throw new errors.NotFoundError( + requestContext.translate(ACTION_ITEM_CATEGORY_NOT_FOUND_ERROR.MESSAGE), + ACTION_ITEM_CATEGORY_NOT_FOUND_ERROR.CODE, + ACTION_ITEM_CATEGORY_NOT_FOUND_ERROR.PARAM + ); + } - await adminCheck(context.userId, actionItemCategory.organizationId); + await adminCheck(context.userId, actionItemCategory.organizationId); - const updatedCategory = await ActionItemCategory.findOneAndUpdate( - { - _id: args.id, - }, - { - ...(args.data as UpdateActionItemCategoryInputType), - }, - { - new: true, - } - ).lean(); + const updatedCategory = await ActionItemCategory.findOneAndUpdate( + { + _id: args.id, + }, + { + ...(args.data as UpdateActionItemCategoryInputType), + }, + { + new: true, + } + ).lean(); - return updatedCategory; -}; + return updatedCategory; + }; diff --git a/src/resolvers/Organization/actionItemCategories.ts b/src/resolvers/Organization/actionItemCategories.ts index e958d304b6..37dbe69f26 100644 --- a/src/resolvers/Organization/actionItemCategories.ts +++ b/src/resolvers/Organization/actionItemCategories.ts @@ -8,6 +8,6 @@ import type { OrganizationResolvers } from "../../types/generatedGraphQLTypes"; export const actionItemCategories: OrganizationResolvers["actionItemCategories"] = async (parent) => { return await ActionItemCategory.find({ - organizationId: parent._id + organizationId: parent._id, }).lean(); }; diff --git a/src/resolvers/Query/actionItemCategory.ts b/src/resolvers/Query/actionItemCategory.ts index 8219851357..e0cfb1232e 100644 --- a/src/resolvers/Query/actionItemCategory.ts +++ b/src/resolvers/Query/actionItemCategory.ts @@ -10,7 +10,10 @@ import { ACTION_ITEM_CATEGORY_NOT_FOUND_ERROR } from "../../constants"; * @remarks You can learn about GraphQL `Resolvers` * {@link https://www.apollographql.com/docs/apollo-server/data/resolvers/ | here}. */ -export const actionItemCategory: QueryResolvers["actionItemCategory"] = async (_parent, args) => { +export const actionItemCategory: QueryResolvers["actionItemCategory"] = async ( + _parent, + args +) => { const actionItemCategory = await ActionItemCategory.findOne({ _id: args.id, }).lean(); diff --git a/src/typeDefs/mutations.ts b/src/typeDefs/mutations.ts index c775defa78..0b3be5e4c8 100644 --- a/src/typeDefs/mutations.ts +++ b/src/typeDefs/mutations.ts @@ -61,7 +61,10 @@ export const mutations = gql` actionItemCategoryId: ID! ): ActionItem! @auth - createActionItemCategory(name: String!, organizationId: ID!): ActionItemCategory! @auth + createActionItemCategory( + name: String! + organizationId: ID! + ): ActionItemCategory! @auth createComment(postId: ID!, data: CommentInput!): Comment @auth @@ -211,7 +214,10 @@ export const mutations = gql` updateActionItem(id: ID!, data: UpdateActionItemInput!): ActionItem @auth - updateActionItemCategory(id: ID!, data: UpdateActionItemCategoryInput!): ActionItemCategory @auth + updateActionItemCategory( + id: ID! + data: UpdateActionItemCategoryInput! + ): ActionItemCategory @auth updateAdvertisement( input: UpdateAdvertisementInput! diff --git a/src/typeDefs/queries.ts b/src/typeDefs/queries.ts index cef093bc6f..7706e82a13 100644 --- a/src/typeDefs/queries.ts +++ b/src/typeDefs/queries.ts @@ -13,7 +13,9 @@ export const queries = gql` actionItemCategory(id: ID!): ActionItemCategory - actionItemCategoriesByOrganization(organizationId: ID!): [ActionItemCategory] + actionItemCategoriesByOrganization( + organizationId: ID! + ): [ActionItemCategory] checkAuth: User! @auth diff --git a/src/typeDefs/types.ts b/src/typeDefs/types.ts index 833009849f..622b2e4cd9 100644 --- a/src/typeDefs/types.ts +++ b/src/typeDefs/types.ts @@ -158,15 +158,15 @@ export const types = gql` longitude: Longitude organization: Organization creator: User - attendees: [User!] - # For each attendee, gives information about whether he/she has checked in yet or not - attendeesCheckInStatus: [CheckInStatus!] - admins(adminId: ID): [User!] - actionItems: [ActionItem] createdAt: DateTime! updatedAt: DateTime! + attendees: [User] + # For each attendee, gives information about whether he/she has checked in yet or not + attendeesCheckInStatus: [CheckInStatus!]! + actionItems: [ActionItem] + admins(adminId: ID): [User!] status: Status! - feedback: [Feedback!] + feedback: [Feedback!]! averageFeedbackScore: Float } @@ -256,11 +256,11 @@ export const types = gql` description: String! location: String creator: User - members: [User!] - admins(adminId: ID): [User!] - actionItemCategories: [ActionItemCategory!] createdAt: DateTime! updatedAt: DateTime! + members: [User] + actionItemCategories: [ActionItemCategory] + admins(adminId: ID): [User!] membershipRequests: [MembershipRequest] userRegistrationRequired: Boolean! visibleInSearch: Boolean! @@ -273,7 +273,7 @@ export const types = gql` first: PositiveInt last: PositiveInt ): UserTagsConnection - customFields: [OrganizationCustomField!] + customFields: [OrganizationCustomField!]! } type OrganizationCustomField { diff --git a/src/types/generatedGraphQLTypes.ts b/src/types/generatedGraphQLTypes.ts index f9c0c725c9..9002a9cbd3 100644 --- a/src/types/generatedGraphQLTypes.ts +++ b/src/types/generatedGraphQLTypes.ts @@ -305,15 +305,15 @@ export type Event = { actionItems?: Maybe>>; admins?: Maybe>; allDay: Scalars['Boolean']['output']; - attendees?: Maybe>; - attendeesCheckInStatus?: Maybe>; + attendees?: Maybe>>; + attendeesCheckInStatus: Array; averageFeedbackScore?: Maybe; createdAt: Scalars['DateTime']['output']; creator?: Maybe; description: Scalars['String']['output']; endDate: Scalars['Date']['output']; endTime?: Maybe; - feedback?: Maybe>; + feedback: Array; isPublic: Scalars['Boolean']['output']; isRegisterable: Scalars['Boolean']['output']; latitude?: Maybe; @@ -1154,17 +1154,17 @@ export type OtpInput = { export type Organization = { __typename?: 'Organization'; _id: Scalars['ID']['output']; - actionItemCategories?: Maybe>; + actionItemCategories?: Maybe>>; admins?: Maybe>; apiUrl: Scalars['URL']['output']; blockedUsers?: Maybe>>; createdAt: Scalars['DateTime']['output']; creator?: Maybe; - customFields?: Maybe>; + customFields: Array; description: Scalars['String']['output']; image?: Maybe; location?: Maybe; - members?: Maybe>; + members?: Maybe>>; membershipRequests?: Maybe>>; name: Scalars['String']['output']; pinnedPosts?: Maybe>>; @@ -2507,15 +2507,15 @@ export type EventResolvers>>, ParentType, ContextType>; admins?: Resolver>, ParentType, ContextType, Partial>; allDay?: Resolver; - attendees?: Resolver>, ParentType, ContextType>; - attendeesCheckInStatus?: Resolver>, ParentType, ContextType>; + attendees?: Resolver>>, ParentType, ContextType>; + attendeesCheckInStatus?: Resolver, ParentType, ContextType>; averageFeedbackScore?: Resolver, ParentType, ContextType>; createdAt?: Resolver; creator?: Resolver, ParentType, ContextType>; description?: Resolver; endDate?: Resolver; endTime?: Resolver, ParentType, ContextType>; - feedback?: Resolver>, ParentType, ContextType>; + feedback?: Resolver, ParentType, ContextType>; isPublic?: Resolver; isRegisterable?: Resolver; latitude?: Resolver, ParentType, ContextType>; @@ -2772,17 +2772,17 @@ export type MutationResolvers = { _id?: Resolver; - actionItemCategories?: Resolver>, ParentType, ContextType>; + actionItemCategories?: Resolver>>, ParentType, ContextType>; admins?: Resolver>, ParentType, ContextType, Partial>; apiUrl?: Resolver; blockedUsers?: Resolver>>, ParentType, ContextType>; createdAt?: Resolver; creator?: Resolver, ParentType, ContextType>; - customFields?: Resolver>, ParentType, ContextType>; + customFields?: Resolver, ParentType, ContextType>; description?: Resolver; image?: Resolver, ParentType, ContextType>; location?: Resolver, ParentType, ContextType>; - members?: Resolver>, ParentType, ContextType>; + members?: Resolver>>, ParentType, ContextType>; membershipRequests?: Resolver>>, ParentType, ContextType>; name?: Resolver; pinnedPosts?: Resolver>>, ParentType, ContextType>; diff --git a/tests/resolvers/ActionItem/category.spec.ts b/tests/resolvers/ActionItem/category.spec.ts index 19edbc30d0..d034f89468 100644 --- a/tests/resolvers/ActionItem/category.spec.ts +++ b/tests/resolvers/ActionItem/category.spec.ts @@ -25,7 +25,11 @@ describe("resolvers -> ActionItem -> actionItemCategory", () => { it(`returns the actionItemCategory for parent action item`, async () => { const parent = testActionItem?.toObject(); - const actionItemCategoryPayload = await actionItemCategoryResolver?.(parent, {}, {}); + const actionItemCategoryPayload = await actionItemCategoryResolver?.( + parent, + {}, + {} + ); const actionItemCategoryObject = await ActionItemCategory.findOne({ _id: testCategory?._id, diff --git a/tests/resolvers/Event/actionItems.spec.ts b/tests/resolvers/Event/actionItems.spec.ts index a084779776..a984e00f05 100644 --- a/tests/resolvers/Event/actionItems.spec.ts +++ b/tests/resolvers/Event/actionItems.spec.ts @@ -23,11 +23,7 @@ describe("resolvers -> Organization -> actionItems", () => { it(`returns all actionItems for parent Event`, async () => { const parent = testEvent?.toObject(); if (parent) { - const actionItemsPayload = await actionItemsResolver?.( - parent, - {}, - {} - ); + const actionItemsPayload = await actionItemsResolver?.(parent, {}, {}); const actionItems = await ActionItem.find({ eventId: testEvent?._id, diff --git a/tests/resolvers/Mutation/createActionItem.spec.ts b/tests/resolvers/Mutation/createActionItem.spec.ts index 779102e31d..c2b0ec22fc 100644 --- a/tests/resolvers/Mutation/createActionItem.spec.ts +++ b/tests/resolvers/Mutation/createActionItem.spec.ts @@ -110,7 +110,9 @@ describe("resolvers -> Mutation -> createActionItem", () => { await createActionItemResolver?.({}, args, context); } catch (error: any) { - expect(error.message).toEqual(ACTION_ITEM_CATEGORY_NOT_FOUND_ERROR.MESSAGE); + expect(error.message).toEqual( + ACTION_ITEM_CATEGORY_NOT_FOUND_ERROR.MESSAGE + ); } }); diff --git a/tests/resolvers/Mutation/createActionItemCategory.spec.ts b/tests/resolvers/Mutation/createActionItemCategory.spec.ts index 68f4b9a6bd..f796341472 100644 --- a/tests/resolvers/Mutation/createActionItemCategory.spec.ts +++ b/tests/resolvers/Mutation/createActionItemCategory.spec.ts @@ -8,6 +8,7 @@ import { ORGANIZATION_NOT_FOUND_ERROR, USER_NOT_FOUND_ERROR, USER_NOT_AUTHORIZED_ADMIN, + ACTION_ITEM_CATEGORY_ALREADY_EXISTS, } from "../../../src/constants"; import { beforeAll, afterAll, describe, it, expect, vi } from "vitest"; import { @@ -133,7 +134,7 @@ describe("resolvers -> Mutation -> createCategory", () => { const args: MutationCreateActionItemCategoryArgs = { organizationId: testOrganization?._id, - name: "Default", + name: "Default2", }; const context = { @@ -149,8 +150,27 @@ describe("resolvers -> Mutation -> createCategory", () => { expect(createCategoryPayload).toEqual( expect.objectContaining({ organizationId: testOrganization?._id, - name: "Default", + name: "Default2", }) ); }); + + it(`throws ConflictError when the actionItemCategory with given name already exists for the current organization`, async () => { + try { + const args: MutationCreateActionItemCategoryArgs = { + organizationId: testOrganization?._id, + name: "Default2", + }; + + const context = { + userId: randomUser?._id, + }; + + await createActionItemCategoryResolver?.({}, args, context); + } catch (error: any) { + expect(error.message).toEqual( + ACTION_ITEM_CATEGORY_ALREADY_EXISTS.MESSAGE + ); + } + }); }); diff --git a/tests/resolvers/Mutation/updateActionItemCategory.spec.ts b/tests/resolvers/Mutation/updateActionItemCategory.spec.ts index 2ac8dd200c..e2718e69cc 100644 --- a/tests/resolvers/Mutation/updateActionItemCategory.spec.ts +++ b/tests/resolvers/Mutation/updateActionItemCategory.spec.ts @@ -79,7 +79,9 @@ describe("resolvers -> Mutation -> updateActionItemCategoryResolver", () => { await updateActionItemCategoryResolver?.({}, args, context); } catch (error: any) { - expect(error.message).toEqual(ACTION_ITEM_CATEGORY_NOT_FOUND_ERROR.MESSAGE); + expect(error.message).toEqual( + ACTION_ITEM_CATEGORY_NOT_FOUND_ERROR.MESSAGE + ); } }); @@ -116,7 +118,11 @@ describe("resolvers -> Mutation -> updateActionItemCategoryResolver", () => { userId: testUser?._id, }; - const updatedCategory = await updateActionItemCategoryResolver?.({}, args, context); + const updatedCategory = await updateActionItemCategoryResolver?.( + {}, + args, + context + ); expect(updatedCategory).toEqual( expect.objectContaining({ @@ -152,7 +158,11 @@ describe("resolvers -> Mutation -> updateActionItemCategoryResolver", () => { userId: superAdminTestUser?._id, }; - const updatedCategory = await updateActionItemCategoryResolver?.({}, args, context); + const updatedCategory = await updateActionItemCategoryResolver?.( + {}, + args, + context + ); expect(updatedCategory).toEqual( expect.objectContaining({ diff --git a/tests/resolvers/Query/actionItemCategory.spec.ts b/tests/resolvers/Query/actionItemCategory.spec.ts index bd7f736778..dbccdfd506 100644 --- a/tests/resolvers/Query/actionItemCategory.spec.ts +++ b/tests/resolvers/Query/actionItemCategory.spec.ts @@ -40,7 +40,11 @@ describe("resolvers -> Query -> actionItemCategory", () => { id: testCategory?._id, }; - const actionItemCategoryPayload = await actionItemCategoryResolver?.({}, args, {}); + const actionItemCategoryPayload = await actionItemCategoryResolver?.( + {}, + args, + {} + ); expect(actionItemCategoryPayload).toEqual( expect.objectContaining({