Refactor backend folder structure (#4505)
* Refactor backend folder structure Co-authored-by: Charles Bochet <charles@twenty.com> * fix tests * fix * move yoga hooks --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -0,0 +1,52 @@
|
||||
import { calendar_v3 } from 'googleapis';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
import { CalendarEventWithAttendees } from 'src/modules/calendar/types/calendar-event';
|
||||
import { CalendarEventAttendeeResponseStatus } from 'src/modules/calendar/standard-objects/calendar-event-attendee.object-metadata';
|
||||
|
||||
export const formatGoogleCalendarEvent = (
|
||||
event: calendar_v3.Schema$Event,
|
||||
): CalendarEventWithAttendees => {
|
||||
const id = v4();
|
||||
|
||||
const formatResponseStatus = (status: string | null | undefined) => {
|
||||
switch (status) {
|
||||
case 'accepted':
|
||||
return CalendarEventAttendeeResponseStatus.ACCEPTED;
|
||||
case 'declined':
|
||||
return CalendarEventAttendeeResponseStatus.DECLINED;
|
||||
case 'tentative':
|
||||
return CalendarEventAttendeeResponseStatus.TENTATIVE;
|
||||
default:
|
||||
return CalendarEventAttendeeResponseStatus.NEEDS_ACTION;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
id,
|
||||
title: event.summary ?? '',
|
||||
isCanceled: event.status === 'cancelled',
|
||||
isFullDay: event.start?.dateTime == null,
|
||||
startsAt: event.start?.dateTime ?? event.start?.date ?? null,
|
||||
endsAt: event.end?.dateTime ?? event.end?.date ?? null,
|
||||
externalId: event.id ?? '',
|
||||
externalCreatedAt: event.created ?? null,
|
||||
externalUpdatedAt: event.updated ?? null,
|
||||
description: event.description ?? '',
|
||||
location: event.location ?? '',
|
||||
iCalUID: event.iCalUID ?? '',
|
||||
conferenceSolution:
|
||||
event.conferenceData?.conferenceSolution?.key?.type ?? '',
|
||||
conferenceUri: event.conferenceData?.entryPoints?.[0]?.uri ?? '',
|
||||
recurringEventExternalId: event.recurringEventId ?? '',
|
||||
attendees:
|
||||
event.attendees?.map((attendee) => ({
|
||||
calendarEventId: id,
|
||||
iCalUID: event.iCalUID ?? '',
|
||||
handle: attendee.email ?? '',
|
||||
displayName: attendee.displayName ?? '',
|
||||
isOrganizer: attendee.organizer === true,
|
||||
responseStatus: formatResponseStatus(attendee.responseStatus),
|
||||
})) ?? [],
|
||||
};
|
||||
};
|
||||
@ -0,0 +1,56 @@
|
||||
export const valuesStringForBatchRawQuery = (
|
||||
values: {
|
||||
[key: string]: any;
|
||||
}[],
|
||||
typesArray: string[] = [],
|
||||
) => {
|
||||
const castedValues = values.reduce((acc, _, rowIndex) => {
|
||||
const numberOfColumns = typesArray.length;
|
||||
|
||||
const rowValues = Array.from(
|
||||
{ length: numberOfColumns },
|
||||
(_, columnIndex) => {
|
||||
const placeholder = `$${rowIndex * numberOfColumns + columnIndex + 1}`;
|
||||
const typeCast = typesArray[columnIndex]
|
||||
? `::${typesArray[columnIndex]}`
|
||||
: '';
|
||||
|
||||
return `${placeholder}${typeCast}`;
|
||||
},
|
||||
).join(', ');
|
||||
|
||||
acc.push(`(${rowValues})`);
|
||||
|
||||
return acc;
|
||||
}, [] as string[]);
|
||||
|
||||
return castedValues.join(', ');
|
||||
};
|
||||
|
||||
export const getFlattenedValuesAndValuesStringForBatchRawQuery = (
|
||||
values: {
|
||||
[key: string]: any;
|
||||
}[],
|
||||
keyTypeMap: {
|
||||
[key: string]: string;
|
||||
},
|
||||
): {
|
||||
flattenedValues: any[];
|
||||
valuesString: string;
|
||||
} => {
|
||||
const keysToInsert = Object.keys(keyTypeMap);
|
||||
|
||||
const flattenedValues = values.flatMap((value) =>
|
||||
keysToInsert.map((key) => value[key]),
|
||||
);
|
||||
|
||||
const valuesString = valuesStringForBatchRawQuery(
|
||||
values,
|
||||
Object.values(keyTypeMap),
|
||||
);
|
||||
|
||||
return {
|
||||
flattenedValues,
|
||||
valuesString,
|
||||
};
|
||||
};
|
||||
@ -0,0 +1,9 @@
|
||||
export const googleCalendarSearchFilterExcludeEmails = (
|
||||
emails: string[],
|
||||
): string => {
|
||||
if (emails.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return `email=-${emails.join(', -')}`;
|
||||
};
|
||||
Reference in New Issue
Block a user