Greenman999
Greenman999
Explore posts from servers
HHono
Created by Greenman999 on 10/23/2024 in #help
How to prevent Server Error if no req body?
Hi I have this code:
userRouter.patch("/self", async (c) => {
const reqUserId = c.get("authUser").user?.id;

if (reqUserId == null) {
throw new HTTPException(401);
}

const { name } = await c.req.json();

if (!name) {
throw new HTTPException(400, { message: "Please include a new name in body." });
}

return c.json({});
});
userRouter.patch("/self", async (c) => {
const reqUserId = c.get("authUser").user?.id;

if (reqUserId == null) {
throw new HTTPException(401);
}

const { name } = await c.req.json();

if (!name) {
throw new HTTPException(400, { message: "Please include a new name in body." });
}

return c.json({});
});
If no json is passed in the body i get this error: [ERROR] SyntaxError: Unexpected end of JSON input Is there anyway to replace this with my own error message? Like the one in my code ^ ?
5 replies
SSolidJS
Created by Greenman999 on 10/19/2024 in #support
custom css classes not applied somehow
Hi, i have this code:
<For each={alertsManager.getAlerts()}>
{(alert) => (
<div class={"flex alert alert-" + alert.type}>
<For each={alertsManager.getAlerts()}>
{(alert) => (
<div class={"flex alert alert-" + alert.type}>
alert.type is success and with daisyui and tailwindcss the div should have a green background color. However the div is colored like default just like alert-success wasnt there. If i manually add alert-success to the class prop it works. If I remove it after the concatinated version works somehow.. Can someone help me?
2 replies
SSolidJS
Created by Greenman999 on 10/19/2024 in #support
Display relative time as signal
Hi, I want to display the relative time of a date. I have this file:
const units: { unit: Intl.RelativeTimeFormatUnit; ms: number }[] = [
{ unit: "year", ms: 31536000000 },
{ unit: "month", ms: 2628000000 },
{ unit: "day", ms: 86400000 },
{ unit: "hour", ms: 3600000 },
{ unit: "minute", ms: 60000 },
{ unit: "second", ms: 1000 },
];
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });

/**
* Get language-sensitive relative time message from Dates.
* @param relative - the relative dateTime, generally is in the past or future
* @param pivot - the dateTime of reference, generally is the current time
*/
export function relativeTimeFromDates(relative: Date | null, pivot: Date = new Date()): string {
if (!relative) return "";
const elapsed = relative.getTime() - pivot.getTime();
return relativeTimeFromElapsed(elapsed);
}

/**
* Get language-sensitive relative time message from elapsed time.
* @param elapsed - the elapsed time in milliseconds
*/
export function relativeTimeFromElapsed(elapsed: number): string {
for (const { unit, ms } of units) {
if (Math.abs(elapsed) >= ms || unit === "second") {
return rtf.format(Math.round(elapsed / ms), unit);
}
}
return "";
}
const units: { unit: Intl.RelativeTimeFormatUnit; ms: number }[] = [
{ unit: "year", ms: 31536000000 },
{ unit: "month", ms: 2628000000 },
{ unit: "day", ms: 86400000 },
{ unit: "hour", ms: 3600000 },
{ unit: "minute", ms: 60000 },
{ unit: "second", ms: 1000 },
];
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });

/**
* Get language-sensitive relative time message from Dates.
* @param relative - the relative dateTime, generally is in the past or future
* @param pivot - the dateTime of reference, generally is the current time
*/
export function relativeTimeFromDates(relative: Date | null, pivot: Date = new Date()): string {
if (!relative) return "";
const elapsed = relative.getTime() - pivot.getTime();
return relativeTimeFromElapsed(elapsed);
}

/**
* Get language-sensitive relative time message from elapsed time.
* @param elapsed - the elapsed time in milliseconds
*/
export function relativeTimeFromElapsed(elapsed: number): string {
for (const { unit, ms } of units) {
if (Math.abs(elapsed) >= ms || unit === "second") {
return rtf.format(Math.round(elapsed / ms), unit);
}
}
return "";
}
but if i run the relativeTimeFromDates(new Date(2024, 9, 19, 14, 30)) inside of the html part it does not update when a minute more has passed and the output of the function should change. Solid does not react to this. How can i fix this? Do i need to wrap the function in something? Thanks!
7 replies
SSolidJS
Created by Greenman999 on 8/16/2024 in #support
Redirect on Client
Hi how can i redirect clientside? redirect("/home") doesnt work
3 replies
SSolidJS
Created by Greenman999 on 6/22/2024 in #support
this is undefined
No description
4 replies
DTDrizzle Team
Created by Greenman999 on 6/21/2024 in #help
`Argument of type 'SQL<unknown>' is not assignable to parameter of type 'IndexColumn'.`
Hello I am creating a schema like this guide (https://orm.drizzle.team/learn/guides/unique-case-insensitive-email) but i get the error in the title on .on(lower(table.email)). This is my code:
import { SQL, sql } from "drizzle-orm";
import {
AnyPgColumn,
pgTable,
timestamp,
uniqueIndex,
uuid,
varchar,
} from "drizzle-orm/pg-core";

export const users = pgTable(
"users",
{
id: uuid("id").defaultRandom().notNull().primaryKey(),
email: varchar("email", { length: 256 }).notNull(),
username: varchar("username", { length: 16 }).notNull(),
displayname: varchar("displayname", { length: 32 }).notNull(),
created_at: timestamp("created_at", { mode: "date" }).notNull(),
},
(table) => ({
emailUniqueIndex: uniqueIndex("emailUniqueIndex").on(lower(table.email)),
usernameUniqueIndex: uniqueIndex("usernameUniqueIndex").on(lower(table.username))
}),
);

export function lower(email: AnyPgColumn): SQL {
return sql`lower(${email})`;
}
import { SQL, sql } from "drizzle-orm";
import {
AnyPgColumn,
pgTable,
timestamp,
uniqueIndex,
uuid,
varchar,
} from "drizzle-orm/pg-core";

export const users = pgTable(
"users",
{
id: uuid("id").defaultRandom().notNull().primaryKey(),
email: varchar("email", { length: 256 }).notNull(),
username: varchar("username", { length: 16 }).notNull(),
displayname: varchar("displayname", { length: 32 }).notNull(),
created_at: timestamp("created_at", { mode: "date" }).notNull(),
},
(table) => ({
emailUniqueIndex: uniqueIndex("emailUniqueIndex").on(lower(table.email)),
usernameUniqueIndex: uniqueIndex("usernameUniqueIndex").on(lower(table.username))
}),
);

export function lower(email: AnyPgColumn): SQL {
return sql`lower(${email})`;
}
2 replies