DiamondDragon
DiamondDragon
Explore posts from servers
HHono
Created by DiamondDragon on 6/8/2024 in #help
Serialization of Date?
Hi, do you have any code samples on this? Basically, my code is looking ugly like this in order to handle typing the date strings back to Date 😦
const res = await apiClient.auth['auth-state'][':workOsUserId'].$get({
param: { workOsUserId },
})
if (!res.ok) {
throw new Error(`Error fetching auth state: ${res.status}`)
}
const data = await res.json()

if (data.user) {
return {
user: data.user
? {
...data.user,
createdAt: new Date(data.user.createdAt),
updatedAt: data.user.updatedAt ? new Date(data.user.updatedAt) : null,
}
: null,
organizations: data.organizations.map((org) => ({
...org,
createdAt: new Date(org.createdAt),
updatedAt: org.updatedAt ? new Date(org.updatedAt) : null,
})),
workspaces: data.workspaces.map((workspace) => ({
...workspace,
createdAt: new Date(workspace.createdAt),
updatedAt: workspace.updatedAt ? new Date(workspace.updatedAt) : null,
})),
}
}
return {
user: null,
organizations: [],
workspaces: [],
}
},
const res = await apiClient.auth['auth-state'][':workOsUserId'].$get({
param: { workOsUserId },
})
if (!res.ok) {
throw new Error(`Error fetching auth state: ${res.status}`)
}
const data = await res.json()

if (data.user) {
return {
user: data.user
? {
...data.user,
createdAt: new Date(data.user.createdAt),
updatedAt: data.user.updatedAt ? new Date(data.user.updatedAt) : null,
}
: null,
organizations: data.organizations.map((org) => ({
...org,
createdAt: new Date(org.createdAt),
updatedAt: org.updatedAt ? new Date(org.updatedAt) : null,
})),
workspaces: data.workspaces.map((workspace) => ({
...workspace,
createdAt: new Date(workspace.createdAt),
updatedAt: workspace.updatedAt ? new Date(workspace.updatedAt) : null,
})),
}
}
return {
user: null,
organizations: [],
workspaces: [],
}
},
10 replies
HHono
Created by DiamondDragon on 6/8/2024 in #help
Serialization of Date?
Still not solved, can you provide a working code sample? https://zenn.dev/kosei28/articles/hono-superjson for example I tried to implement this but most of the types used in this hcs proxy are not exported from hono today it seems? So the modified hcs client is not typesafe, or at least my attempt
10 replies
HHono
Created by DiamondDragon on 6/8/2024 in #help
Serialization of Date?
Ok - all my tables have a created/updated on field. One thing I’m trying to grok is I’m using drizzle queries which are returning nested arrays of different table data so will have think more on that
10 replies