elm-pages-v3-beta/examples/pokedex/custom-backend-task.ts
2023-01-26 16:07:40 -08:00

38 lines
855 B
TypeScript

import kleur from "kleur";
import something from "./something.ts";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export async function users() {
try {
const users = await prisma.user.findMany({
include: { profile: true },
});
return users;
} catch (error) {
console.trace(error);
return ["PRISMA ERROR"];
}
}
export async function environmentVariable(name) {
const result = process.env[name];
if (result) {
return result;
} else {
throw `No environment variable called ${kleur
.yellow()
.underline(name)}\n\nAvailable:\n\n${Object.keys(process.env)
.slice(0, 5)
.join("\n")}`;
}
}
export async function hello(name) {
return `${something} 149 ${name}!!`;
}
function waitFor(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}