import { createUserKvs } from "../../../api-utils/userKvs" ; import { getSpreadSheet } from "../../api/spreadsheet/get" ; import { GetServerSidePropsContext } from "next" ; export async function getServerSideProps ( { params , res } ) { const userId = params ?. userId ; if ( typeof userId !== "string" ) { throw new Error ( "No user" ) ; } const userKVS = await createUserKvs ( ) ; const user = await userKVS . findByUserId ( userId ) ; if ( ! user ) { throw new Error ( "No user" ) ; } const spreadSheet = await getSpreadSheet ( { spreadsheetId : user . spreadsheetId , credentials : user . credentials , defaultCurrency : user . defaultCurrency } ) ; res . statusCode = 200 ; const cacheTime = 60 * 60 ; res . setHeader ( "Cache-Control" , `s-maxage=${ cacheTime }, stale-while-revalidate` ) ; res . setHeader ( "Content-Type" , "application/json" ) ; res . end ( JSON . stringify ( { userName : user . name , userId : user . id , userAvatarUrl : user . avatarUrl , spreadSheet } ) ) ; return { props : { } } ; } const NOOP = ( ) => null ; export default NOOP ;