fix code validation when the google calendar integration does not have all permission (#1425)
Co-authored-by: Edward Fernandez <[email protected]>
This commit is contained in:
1 parent
bd2a795d7a
commit
6e7359ae96
5 files changed
+28
-15
No files matched your search
@@ -9,7 +9,7 @@ import notEmpty from "@lib/notEmpty";
|
||||
|
||||
import { ALL_INTEGRATIONS } from "../getIntegrations";
|
||||
import { CALENDAR_INTEGRATIONS_TYPES } from "./constants/generals";
|
||||
import { CalendarServiceType } from "./constants/types";
|
||||
import { CalendarServiceType, EventBusyDate } from "./constants/types";
|
||||
import { Calendar, CalendarEvent } from "./interfaces/Calendar";
|
||||
import AppleCalendarService from "./services/AppleCalendarService";
|
||||
import CalDavCalendarService from "./services/CalDavCalendarService";
|
||||
@@ -111,9 +111,12 @@ export const getBusyCalendarTimes = async (
|
||||
.map((credential) => getCalendar(credential))
|
||||
.filter(notEmpty);
|
||||
|
||||
const results = await Promise.all(
|
||||
calendars.map((c) => c.getAvailability(dateFrom, dateTo, selectedCalendars))
|
||||
);
|
||||
let results: EventBusyDate[][] = [];
|
||||
try {
|
||||
results = await Promise.all(calendars.map((c) => c.getAvailability(dateFrom, dateTo, selectedCalendars)));
|
||||
} catch (error) {
|
||||
log.warn(error);
|
||||
}
|
||||
|
||||
return results.reduce((acc, availability) => acc.concat(availability), []);
|
||||
};
|
||||
|
||||
@@ -31,8 +31,7 @@ export default abstract class BaseCalendarService implements Calendar {
|
||||
private credentials: Record<string, string> = {};
|
||||
private headers: Record<string, string> = {};
|
||||
protected integrationName = "";
|
||||
|
||||
log = logger.getChildLogger({ prefix: [`[[lib] ${this.integrationName}`] });
|
||||
private log: typeof logger;
|
||||
|
||||
constructor(credential: Credential, integrationName: string, url?: string) {
|
||||
this.integrationName = integrationName;
|
||||
@@ -47,6 +46,8 @@ export default abstract class BaseCalendarService implements Calendar {
|
||||
|
||||
this.credentials = { username, password };
|
||||
this.headers = getBasicAuthHeaders({ username, password });
|
||||
|
||||
this.log = logger.getChildLogger({ prefix: [`[[lib] ${this.integrationName}`] });
|
||||
}
|
||||
|
||||
async createEvent(event: CalendarEvent): Promise<NewCalendarEventType> {
|
||||
|
||||
@@ -17,13 +17,14 @@ export default class GoogleCalendarService implements Calendar {
|
||||
private url = "";
|
||||
private integrationName = "";
|
||||
private auth: { getToken: () => Promise<MyGoogleAuth> };
|
||||
|
||||
log = logger.getChildLogger({ prefix: [`[[lib] ${this.integrationName}`] });
|
||||
private log: typeof logger;
|
||||
|
||||
constructor(credential: Credential) {
|
||||
this.integrationName = CALENDAR_INTEGRATIONS_TYPES.google;
|
||||
|
||||
this.auth = this.googleAuth(credential);
|
||||
|
||||
this.log = logger.getChildLogger({ prefix: [`[[lib] ${this.integrationName}`] });
|
||||
}
|
||||
|
||||
private googleAuth = (credential: Credential) => {
|
||||
@@ -299,7 +300,7 @@ export default class GoogleCalendarService implements Calendar {
|
||||
}) || []
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch((err: Error) => {
|
||||
this.log.error("There was an error contacting google calendar service: ", err);
|
||||
|
||||
reject(err);
|
||||
|
||||
@@ -17,13 +17,14 @@ const MS_GRAPH_CLIENT_SECRET = process.env.MS_GRAPH_CLIENT_SECRET || "";
|
||||
export default class Office365CalendarService implements Calendar {
|
||||
private url = "";
|
||||
private integrationName = "";
|
||||
private log: typeof logger;
|
||||
auth: { getToken: () => Promise<string> };
|
||||
|
||||
log = logger.getChildLogger({ prefix: [`[[lib] ${this.integrationName}`] });
|
||||
|
||||
constructor(credential: Credential) {
|
||||
this.integrationName = CALENDAR_INTEGRATIONS_TYPES.office365;
|
||||
this.auth = this.o365Auth(credential);
|
||||
|
||||
this.log = logger.getChildLogger({ prefix: [`[[lib] ${this.integrationName}`] });
|
||||
}
|
||||
|
||||
async createEvent(event: CalendarEvent): Promise<NewCalendarEventType> {
|
||||
|
||||
Reference in new issue
Block a user