-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract prisma to it's own package (#1823)
* Moved prisma to packages * Add missing prisma configs * Extracts common libs and types * Build and pipeline fixes * Adds missing package * Prisma scripts cleanup * Updates lint staged * Type fixes * Sort imports * Updates yarn lock file * Fixes for yarn dx * Revert "Sort imports" This reverts commit 076109decab9b9ba307fc03696c3b0da5c4896f3. * Formatting * Prevent double TS version * Fix conflict * Extracted e2e configs
- Loading branch information
Showing
128 changed files
with
349 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
# It now lives at `apps/web/.env.example` | ||
# DATABASE_URL got moved to `packages/prisma/.env.example` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
node_modules | ||
apps/web/prisma/zod | ||
packages/prisma/zod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ public | |
.prettierignore | ||
.DS_Store | ||
.eslintignore | ||
apps/web/prisma/zod | ||
packages/prisma/zod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "@calcom/prisma/client"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1 @@ | ||
import { Availability } from "@prisma/client"; | ||
import dayjs, { ConfigType } from "dayjs"; | ||
import customParseFormat from "dayjs/plugin/customParseFormat"; | ||
import timezone from "dayjs/plugin/timezone"; | ||
import utc from "dayjs/plugin/utc"; | ||
|
||
import { Schedule, TimeRange, WorkingHours } from "./types/schedule"; | ||
|
||
dayjs.extend(utc); | ||
dayjs.extend(timezone); | ||
dayjs.extend(customParseFormat); | ||
// sets the desired time in current date, needs to be current date for proper DST translation | ||
export const defaultDayRange: TimeRange = { | ||
start: new Date(new Date().setUTCHours(9, 0, 0, 0)), | ||
end: new Date(new Date().setUTCHours(17, 0, 0, 0)), | ||
}; | ||
|
||
export const DEFAULT_SCHEDULE: Schedule = [ | ||
[], | ||
[defaultDayRange], | ||
[defaultDayRange], | ||
[defaultDayRange], | ||
[defaultDayRange], | ||
[defaultDayRange], | ||
[], | ||
]; | ||
|
||
export function getAvailabilityFromSchedule(schedule: Schedule): Availability[] { | ||
return schedule.reduce((availability: Availability[], times: TimeRange[], day: number) => { | ||
const addNewTime = (time: TimeRange) => | ||
({ | ||
days: [day], | ||
startTime: time.start, | ||
endTime: time.end, | ||
} as Availability); | ||
|
||
const filteredTimes = times.filter((time) => { | ||
let idx; | ||
if ( | ||
(idx = availability.findIndex( | ||
(schedule) => schedule.startTime === time.start && schedule.endTime === time.end | ||
)) !== -1 | ||
) { | ||
availability[idx].days.push(day); | ||
return false; | ||
} | ||
return true; | ||
}); | ||
filteredTimes.forEach((time) => { | ||
availability.push(addNewTime(time)); | ||
}); | ||
return availability; | ||
}, [] as Availability[]); | ||
} | ||
|
||
export const MINUTES_IN_DAY = 60 * 24; | ||
export const MINUTES_DAY_END = MINUTES_IN_DAY - 1; | ||
export const MINUTES_DAY_START = 0; | ||
|
||
/** | ||
* Allows "casting" availability (days, startTime, endTime) given in UTC to a timeZone or utcOffset | ||
*/ | ||
export function getWorkingHours( | ||
relativeTimeUnit: { | ||
timeZone?: string; | ||
utcOffset?: number; | ||
}, | ||
availability: { days: number[]; startTime: ConfigType; endTime: ConfigType }[] | ||
) { | ||
// clearly bail when availability is not set, set everything available. | ||
if (!availability.length) { | ||
return [ | ||
{ | ||
days: [0, 1, 2, 3, 4, 5, 6], | ||
// shorthand for: dayjs().startOf("day").tz(timeZone).diff(dayjs.utc().startOf("day"), "minutes") | ||
startTime: MINUTES_DAY_START, | ||
endTime: MINUTES_DAY_END, | ||
}, | ||
]; | ||
} | ||
|
||
const utcOffset = relativeTimeUnit.utcOffset ?? dayjs().tz(relativeTimeUnit.timeZone).utcOffset(); | ||
|
||
const workingHours = availability.reduce((workingHours: WorkingHours[], schedule) => { | ||
// Get times localised to the given utcOffset/timeZone | ||
const startTime = | ||
dayjs.utc(schedule.startTime).get("hour") * 60 + | ||
dayjs.utc(schedule.startTime).get("minute") - | ||
utcOffset; | ||
const endTime = | ||
dayjs.utc(schedule.endTime).get("hour") * 60 + dayjs.utc(schedule.endTime).get("minute") - utcOffset; | ||
|
||
// add to working hours, keeping startTime and endTimes between bounds (0-1439) | ||
const sameDayStartTime = Math.max(MINUTES_DAY_START, Math.min(MINUTES_DAY_END, startTime)); | ||
const sameDayEndTime = Math.max(MINUTES_DAY_START, Math.min(MINUTES_DAY_END, endTime)); | ||
if (sameDayStartTime !== sameDayEndTime) { | ||
workingHours.push({ | ||
days: schedule.days, | ||
startTime: sameDayStartTime, | ||
endTime: sameDayEndTime, | ||
}); | ||
} | ||
// check for overflow to the previous day | ||
if (startTime < MINUTES_DAY_START || endTime < MINUTES_DAY_START) { | ||
workingHours.push({ | ||
days: schedule.days.map((day) => day - 1), | ||
startTime: startTime + MINUTES_IN_DAY, | ||
endTime: Math.min(endTime + MINUTES_IN_DAY, MINUTES_DAY_END), | ||
}); | ||
} | ||
// else, check for overflow in the next day | ||
else if (startTime > MINUTES_DAY_END || endTime > MINUTES_DAY_END) { | ||
workingHours.push({ | ||
days: schedule.days.map((day) => day + 1), | ||
startTime: Math.max(startTime - MINUTES_IN_DAY, MINUTES_DAY_START), | ||
endTime: endTime - MINUTES_IN_DAY, | ||
}); | ||
} | ||
|
||
return workingHours; | ||
}, []); | ||
|
||
workingHours.sort((a, b) => a.startTime - b.startTime); | ||
|
||
return workingHours; | ||
} | ||
export * from "@calcom/lib/availability"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1 @@ | ||
export enum LocationType { | ||
InPerson = "inPerson", | ||
Phone = "phone", | ||
GoogleMeet = "integrations:google:meet", | ||
Zoom = "integrations:zoom", | ||
Daily = "integrations:daily", | ||
Jitsi = "integrations:jitsi", | ||
Huddle01 = "integrations:huddle01", | ||
Tandem = "integrations:tandem", | ||
} | ||
export * from "@calcom/lib/location"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.