Reapply "feat: use v1 profile api"

This reverts commit d7766a89de.
This commit is contained in:
Michael Zetterberg
2024-05-23 13:18:50 +02:00
parent 38872567bf
commit e00da4278d
3 changed files with 6 additions and 7 deletions

View File

@@ -11,7 +11,7 @@ export const getUserSchema = z.object({
}), }),
dateOfBirth: z.string(), dateOfBirth: z.string(),
email: z.string().email(), email: z.string().email(),
name: z.string(), firstName: z.string(),
language: z.string(), language: z.string(),
lastName: z.string(), lastName: z.string(),
membership: z membership: z

View File

@@ -22,7 +22,7 @@ function fakingRequest<T>(payload: T): Promise<T> {
export const userQueryRouter = router({ export const userQueryRouter = router({
get: protectedProcedure.query(async function ({ ctx }) { get: protectedProcedure.query(async function ({ ctx }) {
const apiResponse = await api.get(api.endpoints.v0.profile, { const apiResponse = await api.get(api.endpoints.v1.profile, {
cache: "no-store", cache: "no-store",
headers: { headers: {
Authorization: `Bearer ${ctx.session.token.access_token}`, Authorization: `Bearer ${ctx.session.token.access_token}`,
@@ -43,11 +43,11 @@ export const userQueryRouter = router({
} }
const apiJson = await apiResponse.json() const apiJson = await apiResponse.json()
if (!apiJson.data?.length) { if (!apiJson.data?.attributes) {
throw notFound(apiJson) throw notFound(apiJson)
} }
const verifiedData = getUserSchema.safeParse(apiJson.data[0].attributes) const verifiedData = getUserSchema.safeParse(apiJson.data.attributes)
if (!verifiedData.success) { if (!verifiedData.success) {
throw internalServerError(verifiedData.error) throw internalServerError(verifiedData.error)
} }
@@ -55,8 +55,7 @@ export const userQueryRouter = router({
return { return {
...extendedUser, ...extendedUser,
...verifiedData.data, ...verifiedData.data,
firstName: verifiedData.data.name, name: `${verifiedData.data.firstName} ${verifiedData.data.lastName}`,
name: `${verifiedData.data.name} ${verifiedData.data.lastName}`,
} }
}), }),

View File

@@ -22,7 +22,7 @@ type Victory = {
* we have to get the values from elsewhere * we have to get the values from elsewhere
*/ */
export interface User extends z.infer<typeof getUserSchema> { export interface User extends z.infer<typeof getUserSchema> {
firstName: string name: string
journeys: Journey[] journeys: Journey[]
nights: number nights: number
shortcuts: ShortcutLink[] shortcuts: ShortcutLink[]