Compare commits

...

2 Commits

Author SHA1 Message Date
Agusti Fernandez Pardo c5d4d281ea fix: add some fixes/extra featurs to button tooltip needed for console 2022-08-18 01:42:31 +02:00
Agusti Fernandez Pardo 0e24a9e22a fix: update rejectOnNotFound -> find(Fist|Unique)OrThrow 2022-08-17 23:41:17 +02:00
29 changed files with 61 additions and 95 deletions

View File

@ -78,10 +78,7 @@ async function patchHandler(req: NextApiRequest) {
confirmed,
} = bookingConfirmPatchBodySchema.parse(req.body);
const currentUser = await prisma.user.findFirst({
rejectOnNotFound() {
throw new HttpError({ statusCode: 404, message: "User not found" });
},
const currentUser = await prisma.user.findFirstOrThrow({
where: {
id: session.user.id,
},
@ -101,13 +98,10 @@ async function patchHandler(req: NextApiRequest) {
const tOrganizer = await getTranslation(currentUser.locale ?? "en", "common");
const booking = await prisma.booking.findFirst({
const booking = await prisma.booking.findFirstOrThrow({
where: {
id: bookingId,
},
rejectOnNotFound() {
throw new HttpError({ statusCode: 404, message: "Booking not found" });
},
select: {
title: true,
description: true,

View File

@ -111,8 +111,7 @@ function isAvailable(busyTimes: BufferedBusyTimes, time: dayjs.ConfigType, lengt
}
const getEventTypesFromDB = async (eventTypeId: number) => {
const eventType = await prisma.eventType.findUnique({
rejectOnNotFound: true,
const eventType = await prisma.eventType.findUniqueOrThrow({
where: {
id: eventTypeId,
},
@ -645,10 +644,8 @@ async function handler(req: NextApiRequest) {
if (typeof eventType.price === "number" && eventType.price > 0) {
/* Validate if there is any stripe_payment credential for this user */
await prisma.credential.findFirst({
rejectOnNotFound(err) {
throw new HttpError({ statusCode: 400, message: "Missing stripe credentials", cause: err });
},
/* note: removes custom error message about stripe */
await prisma.credential.findFirstOrThrow({
where: {
type: "stripe_payment",
userId: organizerUser.id,

View File

@ -40,8 +40,7 @@ const rescheduleSchema = z.object({
});
const findUserDataByUserId = async (userId: number) => {
return await prisma.user.findUnique({
rejectOnNotFound: true,
return await prisma.user.findUniqueOrThrow({
where: {
id: userId,
},
@ -76,7 +75,7 @@ const handler = async (
return res.status(501).end();
}
const bookingToReschedule = await prisma.booking.findFirst({
const bookingToReschedule = await prisma.booking.findFirstOrThrow({
select: {
id: true,
uid: true,
@ -95,7 +94,6 @@ const handler = async (
dynamicGroupSlugRef: true,
destinationCalendar: true,
},
rejectOnNotFound: true,
where: {
uid: bookingId,
NOT: {
@ -127,14 +125,13 @@ const handler = async (
if (bookingToReschedule && user) {
let event: Partial<EventType> = {};
if (bookingToReschedule.eventTypeId) {
event = await prisma.eventType.findFirst({
event = await prisma.eventType.findFirstOrThrow({
select: {
title: true,
users: true,
schedulingType: true,
recurringEvent: true,
},
rejectOnNotFound: true,
where: {
id: bookingToReschedule.eventTypeId,
},

View File

@ -106,7 +106,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
throw new HttpError({ statusCode: 404, message: "User not found" });
}
const organizer = await prisma.user.findFirst({
const organizer = await prisma.user.findFirstOrThrow({
where: {
id: bookingToDelete.userId,
},
@ -116,7 +116,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
timeZone: true,
locale: true,
},
rejectOnNotFound: true,
});
const attendeesListPromises = bookingToDelete.attendees.map(async (attendee) => {

View File

@ -32,8 +32,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
},
});
const user = await prisma.user.findUnique({
rejectOnNotFound: true,
const user = await prisma.user.findUniqueOrThrow({
where: {
id: session.user.id,
},

View File

@ -15,8 +15,7 @@ type CalendlyEventType = {
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const session = await getSession({ req });
const authenticatedUser = await prisma.user.findFirst({
rejectOnNotFound: true,
const authenticatedUser = await prisma.user.findFirstOrThrow({
where: {
id: session?.user.id,
},

View File

@ -15,8 +15,7 @@ type SavvyCalEventType = {
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const session = await getSession({ req });
const authenticatedUser = await prisma.user.findFirst({
rejectOnNotFound: true,
const authenticatedUser = await prisma.user.findFirstOrThrow({
where: {
id: session?.user.id,
},

View File

@ -12,13 +12,12 @@ export async function getHandler(req: NextApiRequest, res: NextApiResponse) {
try {
const session = await getSession({ req });
const userId = session?.user?.id;
const user = await prisma.user.findFirst({
const user = await prisma.user.findFirstOrThrow({
select: {
id: true,
metadata: true,
},
where: { id: userId },
rejectOnNotFound: true,
});
const checkPremiumUsernameResult = await checkUsername(intentUsername);

View File

@ -15,8 +15,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return;
}
const user = await prisma.user.findUnique({
rejectOnNotFound: true,
const user = await prisma.user.findUniqueOrThrow({
where: {
id: session.user.id,
},

View File

@ -17,8 +17,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
throw new HttpCode({ statusCode: 405, message: "Method Not Allowed" });
}
const user = await prisma.user.findUnique({
rejectOnNotFound: true,
const user = await prisma.user.findUniqueOrThrow({
where: {
id: session.user.id,
},

View File

@ -24,8 +24,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return res.status(400).json({ message: "No user id provided" });
}
const authenticatedUser = await prisma.user.findFirst({
rejectOnNotFound: true,
const authenticatedUser = await prisma.user.findFirstOrThrow({
where: {
id: session.user.id,
},

View File

@ -18,8 +18,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
if (req.method === "DELETE") {
// Get user
const user = await prisma.user.findUnique({
rejectOnNotFound: true,
const user = await prisma.user.findUniqueOrThrow({
where: {
id: session.user?.id,
},

View File

@ -206,8 +206,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
const id = context.params?.id as string;
try {
const resetPasswordRequest = await prisma.resetPasswordRequest.findUnique({
rejectOnNotFound: true,
const resetPasswordRequest = await prisma.resetPasswordRequest.findUniqueOrThrow({
where: {
id,
},

View File

@ -54,8 +54,7 @@ export const createUsersFixture = (page: Page, workerInfo: WorkerInfo) => {
length: 30,
},
});
const user = await prisma.user.findUnique({
rejectOnNotFound: true,
const user = await prisma.user.findUniqueOrThrow({
where: { id: _user.id },
include: userIncludes,
});

View File

@ -10,8 +10,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
if (req.method === "POST") {
const { username, password } = req.body;
// Get user
const user = await prisma.user.findFirst({
rejectOnNotFound: true,
const user = await prisma.user.findFirstOrThrow({
where: {
id: req.session?.user?.id,
},

View File

@ -10,8 +10,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
if (req.method === "POST") {
const { username, password, url } = req.body;
// Get user
const user = await prisma.user.findFirst({
rejectOnNotFound: true,
const user = await prisma.user.findFirstOrThrow({
where: {
id: req.session?.user?.id,
},

View File

@ -19,8 +19,7 @@ const bodySchema = z
async function postHandler(req: NextApiRequest, res: NextApiResponse) {
const body = bodySchema.parse(req.body);
// Get user
const user = await prisma.user.findFirst({
rejectOnNotFound: true,
const user = await prisma.user.findFirstOrThrow({
where: {
id: req.session?.user?.id,
},

View File

@ -19,8 +19,7 @@ const bodySchema = z
async function postHandler(req: NextApiRequest, res: NextApiResponse) {
const body = bodySchema.parse(req.body);
// Get user
const user = await prisma.user.findFirst({
rejectOnNotFound: true,
const user = await prisma.user.findFirstOrThrow({
where: {
id: req.session?.user?.id,
},

View File

@ -16,8 +16,7 @@ async function handler(req: NextApiRequest) {
const { client_id } = await getSlackAppKeys();
// Get user
await prisma.user.findFirst({
rejectOnNotFound: true,
await prisma.user.findFirstOrThrow({
where: {
id: req.session.user.id,
},

View File

@ -42,8 +42,7 @@ export default async function createEvent(req: NextApiRequest, res: NextApiRespo
// Im sure this query can be made more efficient... The JSON filtering wouldnt work when doing it directly on user.
const foundUser = await db.credential
.findFirst({
rejectOnNotFound: true,
.findFirstOrThrow({
...WhereCredsEqualsId(user.id),
})
.user({

View File

@ -12,8 +12,7 @@ let base_url = "";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === "GET") {
// Get user
await prisma.user.findFirst({
rejectOnNotFound: true,
await prisma.user.findFirstOrThrow({
where: {
id: req.session?.user?.id,
},

View File

@ -57,8 +57,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
try {
if (event.data.user_id) {
const json = { userVitalId: event.data.user_id as string };
const credential = await prisma.credential.findFirst({
rejectOnNotFound: true,
const credential = await prisma.credential.findFirstOrThrow({
where: {
type: "vital_other",
key: {

View File

@ -17,7 +17,7 @@ import { getCalendar } from "../../_utils/getCalendar";
type PersonAttendeeCommonFields = Pick<User, "id" | "email" | "name" | "locale" | "timeZone" | "username">;
const Reschedule = async (bookingUid: string, cancellationReason: string) => {
const bookingToReschedule = await prisma.booking.findFirst({
const bookingToReschedule = await prisma.booking.findFirstOrThrow({
select: {
id: true,
uid: true,
@ -42,7 +42,6 @@ const Reschedule = async (bookingUid: string, cancellationReason: string) => {
},
},
},
rejectOnNotFound: true,
where: {
uid: bookingUid,
NOT: {
@ -55,13 +54,12 @@ const Reschedule = async (bookingUid: string, cancellationReason: string) => {
if (bookingToReschedule && bookingToReschedule.eventTypeId && bookingToReschedule.user) {
const userOwner = bookingToReschedule.user;
const event = await prisma.eventType.findFirst({
const event = await prisma.eventType.findFirstOrThrow({
select: {
title: true,
users: true,
schedulingType: true,
},
rejectOnNotFound: true,
where: {
id: bookingToReschedule.eventTypeId,
},

View File

@ -17,7 +17,7 @@ import { getCalendar } from "../../_utils/getCalendar";
type PersonAttendeeCommonFields = Pick<User, "id" | "email" | "name" | "locale" | "timeZone" | "username">;
const Reschedule = async (bookingUid: string, cancellationReason: string) => {
const bookingToReschedule = await prisma.booking.findFirst({
const bookingToReschedule = await prisma.booking.findFirstOrThrow({
select: {
id: true,
uid: true,
@ -42,7 +42,6 @@ const Reschedule = async (bookingUid: string, cancellationReason: string) => {
},
},
},
rejectOnNotFound: true,
where: {
uid: bookingUid,
NOT: {
@ -55,13 +54,12 @@ const Reschedule = async (bookingUid: string, cancellationReason: string) => {
if (bookingToReschedule && bookingToReschedule.eventTypeId && bookingToReschedule.user) {
const userOwner = bookingToReschedule.user;
const event = await prisma.eventType.findFirst({
const event = await prisma.eventType.findFirstOrThrow({
select: {
title: true,
users: true,
schedulingType: true,
},
rejectOnNotFound: true,
where: {
id: bookingToReschedule.eventTypeId,
},

View File

@ -9,8 +9,7 @@ import { getZoomAppKeys } from "../lib";
async function handler(req: NextApiRequest) {
// Get user
await prisma.user.findFirst({
rejectOnNotFound: true,
await prisma.user.findFirstOrThrow({
where: {
id: req.session?.user?.id,
},

View File

@ -95,8 +95,7 @@ export class CalendarEventBuilder implements ICalendarEventBuilder {
private async getUserById(userId: number) {
let resultUser: User | null;
try {
resultUser = await prisma.user.findUnique({
rejectOnNotFound: true,
resultUser = await prisma.user.findUniqueOrThrow({
where: {
id: userId,
},
@ -111,8 +110,7 @@ export class CalendarEventBuilder implements ICalendarEventBuilder {
private async getEventFromEventId(eventTypeId: number) {
let resultEventType;
try {
resultEventType = await prisma.eventType.findUnique({
rejectOnNotFound: true,
resultEventType = await prisma.eventType.findUniqueOrThrow({
where: {
id: eventTypeId,
},
@ -223,8 +221,7 @@ export class CalendarEventBuilder implements ICalendarEventBuilder {
public async setUsersFromId(userId: User["id"]) {
let resultUser: User | null;
try {
resultUser = await prisma.user.findUnique({
rejectOnNotFound: true,
resultUser = await prisma.user.findUniqueOrThrow({
where: {
id: userId,
},

View File

@ -81,7 +81,7 @@ export const bookingsRouter = createProtectedRouter()
const { booking } = ctx;
try {
const organizer = await ctx.prisma.user.findFirst({
const organizer = await ctx.prisma.user.findFirstOrThrow({
where: {
id: booking.userId || 0,
},
@ -91,7 +91,6 @@ export const bookingsRouter = createProtectedRouter()
timeZone: true,
locale: true,
},
rejectOnNotFound: true,
});
const tOrganizer = await getTranslation(organizer.locale ?? "en", "common");

View File

@ -14,6 +14,7 @@ export type ButtonBaseProps = {
StartIcon?: SVGComponent;
startIconClassName?: string;
EndIcon?: SVGComponent;
endIconClassName?: string;
shallow?: boolean;
};
export type ButtonProps = ButtonBaseProps &
@ -32,6 +33,7 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
size = "base",
StartIcon,
startIconClassName,
endIconClassName,
EndIcon,
shallow,
// attributes propagated from `HTMLAnchorProps` or `HTMLButtonProps`
@ -130,7 +132,9 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
</svg>
</div>
)}
{EndIcon && <EndIcon className="-mr-1 inline h-5 w-5 ltr:ml-2 rtl:mr-2" />}
{EndIcon && (
<EndIcon className={classNames("-mr-1 inline h-5 w-5 ltr:ml-2 rtl:mr-2", endIconClassName || "")} />
)}
</>
);
return props.href ? (

View File

@ -20,24 +20,26 @@ export function Tooltip({
onOpenChange?: (open: boolean) => void;
}) {
return (
<TooltipPrimitive.Root
delayDuration={50}
open={open}
defaultOpen={defaultOpen}
onOpenChange={onOpenChange}>
<TooltipPrimitive.Trigger asChild>{children}</TooltipPrimitive.Trigger>
<TooltipPrimitive.Content
className={classNames(
side === "top" && "-mt-2",
side === "right" && "ml-2",
"rounded-sm bg-black px-1 py-0.5 text-xs text-white shadow-lg"
)}
side={side}
align="center"
{...props}>
{content}
</TooltipPrimitive.Content>
</TooltipPrimitive.Root>
<TooltipPrimitive.Provider>
<TooltipPrimitive.Root
delayDuration={50}
open={open}
defaultOpen={defaultOpen}
onOpenChange={onOpenChange}>
<TooltipPrimitive.Trigger asChild>{children}</TooltipPrimitive.Trigger>
<TooltipPrimitive.Content
className={classNames(
side === "top" && "-mt-2",
side === "right" && "ml-2",
"rounded-sm bg-black px-1 py-0.5 text-xs text-white shadow-lg"
)}
side={side}
align="center"
{...props}>
{content}
</TooltipPrimitive.Content>
</TooltipPrimitive.Root>
</TooltipPrimitive.Provider>
);
}