in legacy/src/Calendar/EventSources/VSOCapacityEventSource.ts [369:434]
public updateEvent(
oldEvent: Calendar_Contracts.CalendarEvent,
newEvent: Calendar_Contracts.CalendarEvent,
): PromiseLike<Calendar_Contracts.CalendarEvent> {
const dayOffStart = new Date(oldEvent.startDate);
const memberId = oldEvent.member.id;
const iterationId = oldEvent.iterationId;
const isTeam: boolean = oldEvent.member.uniqueName === undefined;
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 };
const updated: boolean = teamDaysOffPatch.daysOff.some(
(dateRange: Work_Contracts.DateRange, index: number, array: Work_Contracts.DateRange[]) => {
if (dateRange.start.valueOf() === dayOffStart.valueOf()) {
teamDaysOffPatch.daysOff[index].start = new Date(newEvent.startDate);
teamDaysOffPatch.daysOff[index].end = new Date(newEvent.endDate);
return true;
}
return false;
},
);
return workClient
.updateTeamDaysOff(teamDaysOffPatch, teamContext, iterationId)
.then((value: Work_Contracts.TeamSettingsDaysOff) => {
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[index].start = new Date(newEvent.startDate);
capacityPatch.daysOff[index].end = new Date(newEvent.endDate);
return true;
}
return false;
},
);
return workClient
.updateCapacity(capacityPatch, teamContext, iterationId, memberId)
.then((value: Work_Contracts.TeamMemberCapacity) => {
return null;
});
});
}
}