random login image!

This commit is contained in:
Sean Morley
2024-06-12 17:38:34 +00:00
parent 20b6f826d9
commit 6385f9f46b
11 changed files with 646 additions and 20 deletions

View File

@@ -0,0 +1,20 @@
import { eq } from "drizzle-orm";
import { db } from "./db.server";
import { imagesTable } from "./schema";
export const getBackgroundImages = async (numberOfResults: number | null) => {
const images = await db
.select({ url: imagesTable.url })
.from(imagesTable)
.where(eq(imagesTable.type, "background"))
.execute();
if (numberOfResults) {
let randomIndex = Math.floor(Math.random() * images.length);
return images.slice(randomIndex, randomIndex + numberOfResults) as {
url: string;
}[];
}
return images as { url: string }[];
};

View File

@@ -103,3 +103,10 @@ export const adventureTable = pgTable("adventures", {
date: text("date"),
tripId: integer("tripId").references(() => userPlannedTrips.id),
});
export const imagesTable = pgTable("images", {
id: serial("id").primaryKey(),
url: text("url").notNull(),
type: text("type").notNull(),
adventureId: integer("adventureId").references(() => adventureTable.id),
});