init. moved lil website for madeline into fuse project so I can write apis in here

This commit is contained in:
2024-09-09 22:39:25 -05:00
commit 28f44c35c6
23 changed files with 4867 additions and 0 deletions

55
src/server/functions.ts Executable file
View File

@@ -0,0 +1,55 @@
import 'server-only';
import { db } from '~/server/db';
import * as schema from '~/server/db/schema';
import { eq } from 'drizzle-orm';
export const getMessage = async (userId: number) => {
try {
let message = 1;
if (userId === 1)
message = 2;
const result = await db.select({
receivedMessage: schema.users.message,
}).from(schema.users)
.where(eq(schema.users.id, message))
return result;
} catch (error) {
console.error("Error fetching message", error);
throw new Error("Failed to fetch message");
}
};
export const setMessage = async (userId: number, message: string) => {
try {
await db.update(schema.users)
.set({ message: message })
.where(eq(schema.users.id, userId));
} catch (error) {
console.error("Error setting message", error);
throw new Error("Failed to set message");
}
};
export const getCountdown = async () => {
try {
const result = await db.select({
countdown: schema.countdown.date,
}).from(schema.countdown)
.where(eq(schema.countdown.id, 1))
return result;
} catch (error) {
console.error("Error fetching countdown", error);
throw new Error("Failed to fetch countdown");
}
};
export const setCountdown = async (date: Date) => {
try {
await db.update(schema.countdown)
.set({ date: date })
.where(eq(schema.countdown.id, 1));
} catch (error) {
console.error("Error setting countdown", error);
throw new Error("Failed to set countdown");
}
};