fix: update rejectOnNotFound -> find(Fist|Unique)OrThrow (#3829)
* fix: update rejectOnNotFound -> find(Fist|Unique)OrThrow * fix: add back custom errohandling * feat: handle notfounderror in getServerErrorFromUnknown Co-authored-by: Agusti Fernandez Pardo <[email protected]> Co-authored-by: Omar López <[email protected]>
This commit is contained in:
26 files changed
+37
-67
No files matched your search
@@ -112,8 +112,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,
|
||||
},
|
||||
@@ -662,10 +661,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,
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -107,7 +107,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,
|
||||
},
|
||||
@@ -117,7 +117,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
timeZone: true,
|
||||
locale: true,
|
||||
},
|
||||
rejectOnNotFound: true,
|
||||
});
|
||||
|
||||
const attendeesListPromises = bookingToDelete.attendees.map(async (attendee) => {
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -19,8 +19,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,
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -61,8 +61,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,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user