public removeEvent()

in legacy/src/Calendar/EventSources/VSOCapacityEventSource.ts [305:367]


    public removeEvent(event: Calendar_Contracts.CalendarEvent): PromiseLike<Calendar_Contracts.CalendarEvent[]> {
        const dayOffStart = new Date(event.startDate);
        const memberId = event.member.id;
        const isTeam: boolean = event.member.uniqueName === undefined;
        const iterationId: string = event.iterationId;
        const webContext = VSS.getWebContext();
        const teamContext: TFS_Core_Contracts.TeamContext = {
            projectId: webContext.project.id,
            teamId: this._team.id,
            project: "",
            team: "",
        };
        const workClient: Work_Client.WorkHttpClient2_1 = Service.VssConnection
            .getConnection()
            .getHttpClient(Work_Client.WorkHttpClient2_1, WebApi_Constants.ServiceInstanceTypes.TFS);

        if (isTeam) {
            return realPromise(
                this._getTeamDaysOff(workClient, teamContext, iterationId),
            ).then((teamDaysOff: Work_Contracts.TeamSettingsDaysOff) => {
                const teamDaysOffPatch: Work_Contracts.TeamSettingsDaysOffPatch = { daysOff: teamDaysOff.daysOff };
                teamDaysOffPatch.daysOff.some(
                    (dateRange: Work_Contracts.DateRange, index: number, array: Work_Contracts.DateRange[]) => {
                        if (dateRange.start.valueOf() === dayOffStart.valueOf()) {
                            teamDaysOffPatch.daysOff.splice(index, 1);
                            return true;
                        }
                        return false;
                    },
                );
                return workClient
                    .updateTeamDaysOff(teamDaysOffPatch, teamContext, iterationId)
                    .then((value: Work_Contracts.TeamSettingsDaysOff) => {
                        // Resolve null to tell views.js to reload the entire event source instead removing one event
                        return null;
                    });
            });
        } else {
            return realPromise(
                this._getCapacity(workClient, teamContext, iterationId, memberId),
            ).then((capacity: Work_Contracts.TeamMemberCapacity) => {
                const capacityPatch: Work_Contracts.CapacityPatch = {
                    activities: capacity.activities,
                    daysOff: capacity.daysOff,
                };
                capacityPatch.daysOff.some(
                    (dateRange: Work_Contracts.DateRange, index: number, array: Work_Contracts.DateRange[]) => {
                        if (dateRange.start.valueOf() === dayOffStart.valueOf()) {
                            capacityPatch.daysOff.splice(index, 1);
                            return true;
                        }
                        return false;
                    },
                );
                return workClient
                    .updateCapacity(capacityPatch, teamContext, iterationId, memberId)
                    .then((value: Work_Contracts.TeamMemberCapacity) => {
                        // Resolve null to tell views.js to reload the entire event source instead removing one event
                        return null;
                    });
            });
        }
    }