tokens fr
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
import { prisma } from "./db/db";
|
||||
import { Elysia, t } from "elysia";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { simpleApi } from "./games/simple";
|
||||
import { human } from "./human";
|
||||
import dayjs from "dayjs";
|
||||
import db from "./db";
|
||||
|
||||
const api = new Elysia({ prefix: "/api" })
|
||||
.post("/whoami", async ({ cookie: { token } }) => {
|
||||
if (token.value == null) {
|
||||
const newHuman = await prisma.human.create({
|
||||
const newHuman = await db.human.create({
|
||||
data: {},
|
||||
});
|
||||
token.value = newHuman.key;
|
||||
token.set({
|
||||
value: newHuman.token,
|
||||
expires: dayjs().add(1, "year").toDate(),
|
||||
httpOnly: true,
|
||||
});
|
||||
}
|
||||
return token.value;
|
||||
})
|
||||
@@ -18,7 +22,7 @@ const api = new Elysia({ prefix: "/api" })
|
||||
.post(
|
||||
"/setName",
|
||||
({ body: { name }, humanKey }) =>
|
||||
prisma.human.update({
|
||||
db.human.update({
|
||||
where: {
|
||||
key: humanKey,
|
||||
},
|
||||
@@ -33,16 +37,21 @@ const api = new Elysia({ prefix: "/api" })
|
||||
}
|
||||
)
|
||||
.get("/profile", ({ humanKey }) =>
|
||||
prisma.human.findFirst({ where: { key: humanKey } })
|
||||
db.human.findFirst({ where: { key: humanKey } })
|
||||
)
|
||||
.get("/games", () => prisma.game.findMany())
|
||||
.get("/games", () => [{ key: "simple", name: "simple" }])
|
||||
|
||||
.get("/instances", ({ query: { game } }) =>
|
||||
prisma.instance.findMany({
|
||||
.get("/instances", ({ query: { game }, humanKey }) =>
|
||||
db.instance.findMany({
|
||||
where: {
|
||||
game: {
|
||||
name: game,
|
||||
},
|
||||
players: {
|
||||
some: {
|
||||
key: humanKey,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
Reference in New Issue
Block a user