diff --git a/packages/plugin-meetings-api/src/graphql/resolvers/mutations/pinnedUser.ts b/packages/plugin-meetings-api/src/graphql/resolvers/mutations/pinnedUser.ts index 17f7c55e8c..bab784bb0b 100644 --- a/packages/plugin-meetings-api/src/graphql/resolvers/mutations/pinnedUser.ts +++ b/packages/plugin-meetings-api/src/graphql/resolvers/mutations/pinnedUser.ts @@ -4,18 +4,11 @@ const pinnedUserMutations = { // /** // * Creates a new pinnedUser // */ - async meetingPinnedUserAdd( - _root, - { pinnedUserIds }, - { models, user }: IContext - ) { - return await models.PinnedUsers.createPinnedUser(pinnedUserIds, user); - }, // /** // * Edits a pinnedUser // */ - async meetingPinnedUserEdit( + async meetingPinnedUserUpdate( _root, { pinnedUserIds }, { models, user }: IContext diff --git a/packages/plugin-meetings-api/src/graphql/schema/pinnedUser.ts b/packages/plugin-meetings-api/src/graphql/schema/pinnedUser.ts index 22c922e942..d90bf01b6c 100644 --- a/packages/plugin-meetings-api/src/graphql/schema/pinnedUser.ts +++ b/packages/plugin-meetings-api/src/graphql/schema/pinnedUser.ts @@ -2,8 +2,7 @@ const params = ` pinnedUserIds: [String] `; export const mutations = ` - meetingPinnedUserAdd(${params}): PinnedUsers - meetingPinnedUserEdit(${params}): PinnedUsers + meetingPinnedUserUpdate(${params}): PinnedUsers `; export const queries = ` diff --git a/packages/plugin-meetings-api/src/models/pinnedUsers.ts b/packages/plugin-meetings-api/src/models/pinnedUsers.ts index 3f3bc24374..ef6364f22b 100644 --- a/packages/plugin-meetings-api/src/models/pinnedUsers.ts +++ b/packages/plugin-meetings-api/src/models/pinnedUsers.ts @@ -8,10 +8,6 @@ import { import { checkLogin } from '@erxes/api-utils/src'; export interface IPinnedUserModel extends Model { - createPinnedUser( - pinnedUserIds: String[], - user: IUser - ): Promise; updatePinnedUser( pinnedUserIds: String[], user: IUser @@ -20,21 +16,21 @@ export interface IPinnedUserModel extends Model { export const loadPinnedUserClass = (model: IModels) => { class PinnedUser { - // create - public static async createPinnedUser(pinnedUserIds, user) { + // update + public static async updatePinnedUser(pinnedUserIds, user) { + const pinnedUsers = await model.PinnedUsers.findOne({ userId: user._id }); + + if (pinnedUsers) { + return await model.PinnedUsers.updateOne( + { userId: user._id }, + { $set: { pinnedUserIds } } + ).then(err => console.error(err)); + } return await model.PinnedUsers.create({ pinnedUserIds, userId: user._id }); } - - // update - public static async updatePinnedUser(pinnedUserIds, user) { - return await model.PinnedUsers.updateOne( - { userId: user._id }, - { $set: { pinnedUserIds } } - ).then(err => console.error(err)); - } } pinnedUserSchema.loadClass(PinnedUser); diff --git a/packages/plugin-meetings-ui/src/containers/myCalendar/ChooseOwnerForm.tsx b/packages/plugin-meetings-ui/src/containers/myCalendar/ChooseOwnerForm.tsx index af8d310a6f..58d6793f99 100644 --- a/packages/plugin-meetings-ui/src/containers/myCalendar/ChooseOwnerForm.tsx +++ b/packages/plugin-meetings-ui/src/containers/myCalendar/ChooseOwnerForm.tsx @@ -19,11 +19,7 @@ export const ChooseOwnerFormContainer = (props: Props) => { }: IButtonMutateProps) => { return (