Implement whereAndSelect decorator
This commit is contained in:
parent
db7c467d73
commit
ffd99d02bb
1 changed files with 26 additions and 33 deletions
|
@ -2,10 +2,10 @@ import { useEffect, useState } from "react";
|
||||||
import { GetServerSideProps } from "next";
|
import { GetServerSideProps } from "next";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import { ChevronDownIcon, ClockIcon, GlobeIcon } from "@heroicons/react/solid";
|
import { ChevronDownIcon, ClockIcon, GlobeIcon } from "@heroicons/react/solid";
|
||||||
import prisma from "../../lib/prisma";
|
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { Dayjs } from "dayjs";
|
import { Dayjs } from "dayjs";
|
||||||
|
|
||||||
|
import prisma, { whereAndSelect } from "@lib/prisma";
|
||||||
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "../../lib/telemetry";
|
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "../../lib/telemetry";
|
||||||
import AvailableTimes from "../../components/booking/AvailableTimes";
|
import AvailableTimes from "../../components/booking/AvailableTimes";
|
||||||
import TimeOptions from "../../components/booking/TimeOptions";
|
import TimeOptions from "../../components/booking/TimeOptions";
|
||||||
|
@ -149,26 +149,27 @@ export default function Type(props): Type {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
const user = await prisma.user.findFirst({
|
const user = await whereAndSelect(
|
||||||
where: {
|
prisma.user.findFirst,
|
||||||
|
{
|
||||||
username: context.query.user.toLowerCase(),
|
username: context.query.user.toLowerCase(),
|
||||||
},
|
},
|
||||||
select: {
|
[
|
||||||
id: true,
|
"id",
|
||||||
username: true,
|
"username",
|
||||||
name: true,
|
"name",
|
||||||
email: true,
|
"email",
|
||||||
bio: true,
|
"bio",
|
||||||
avatar: true,
|
"avatar",
|
||||||
eventTypes: true,
|
"eventTypes",
|
||||||
startTime: true,
|
"startTime",
|
||||||
timeZone: true,
|
"endTime",
|
||||||
endTime: true,
|
"timeZone",
|
||||||
weekStart: true,
|
"weekStart",
|
||||||
availability: true,
|
"availability",
|
||||||
hideBranding: true,
|
"hideBranding",
|
||||||
},
|
]
|
||||||
});
|
);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
|
@ -176,22 +177,14 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const eventType = await prisma.eventType.findFirst({
|
const eventType = await whereAndSelect(
|
||||||
where: {
|
prisma.eventType.findFirst,
|
||||||
|
{
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
slug: {
|
slug: context.query.type,
|
||||||
equals: context.query.type,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
select: {
|
["id", "title", "description", "length", "availability", "timeZone"]
|
||||||
id: true,
|
);
|
||||||
title: true,
|
|
||||||
description: true,
|
|
||||||
length: true,
|
|
||||||
availability: true,
|
|
||||||
timeZone: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!eventType) {
|
if (!eventType) {
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue