Feat: トークンを削除できる機能 / Fix: meエンドポイントでレスポンスヘッダーにapplication/jsonがない問題 / Chg: エンドポイントの関数名をL.jsを統一
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { DatabaseError } from "@/errors";
|
||||
import Logger from "@/lib/logger";
|
||||
import { TokenEntity } from "@/modules/entities/Token";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
|
||||
export default function TokenDelete(fastify: FastifyInstance) {
|
||||
const logger = new Logger("Endpoint | token/delete");
|
||||
|
||||
fastify.post("/", async (req, res) => {
|
||||
res.header("Content-Type", "application/json");
|
||||
|
||||
if ("error" in req.token)
|
||||
return res.code(400).send(req.token);
|
||||
|
||||
try {
|
||||
await fastify.orm.em.getRepository(TokenEntity).deleteToken(req.token, fastify);
|
||||
|
||||
return res.send({
|
||||
success: true,
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error("Database Error: Server initialization failed:", err);
|
||||
|
||||
return res.code(500).send(DatabaseError());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import TokenDelete from "./delete";
|
||||
|
||||
export default async function Token(fastify: FastifyInstance) {
|
||||
await fastify.register(TokenDelete, {
|
||||
prefix: "/delete",
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user