Compare commits
2 Commits
959af8abdc
...
133ebb4668
| Author | SHA1 | Date | |
|---|---|---|---|
| 133ebb4668 | |||
| 7a3c46c6c1 |
@ -395,6 +395,8 @@ model UserSession {
|
|||||||
logs UserLog[] @relation("UserSessionLogs")
|
logs UserLog[] @relation("UserSessionLogs")
|
||||||
episode_likes EpisodeLike[] @relation("SessionEpisodeLikes")
|
episode_likes EpisodeLike[] @relation("SessionEpisodeLikes")
|
||||||
watch_histories WatchHistory[] @relation("SessionWatchHistories")
|
watch_histories WatchHistory[] @relation("SessionWatchHistories")
|
||||||
|
|
||||||
|
@@index([userId, isAuthenticated, deletedAt])
|
||||||
@@map("user_sessions")
|
@@map("user_sessions")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,18 @@
|
|||||||
|
import { Context } from "elysia";
|
||||||
|
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||||
|
import { returnWriteResponse } from "../../../helpers/callback/httpResponse";
|
||||||
|
import { purgeUnusedSessionService } from "../services/http/purgeUnusedSession.service";
|
||||||
|
|
||||||
|
export const purgeUnusedSessionController = async (ctx: Context) => {
|
||||||
|
try {
|
||||||
|
const result = await purgeUnusedSessionService();
|
||||||
|
return returnWriteResponse(
|
||||||
|
ctx.set,
|
||||||
|
200,
|
||||||
|
"Successfully purged all unused user sessions",
|
||||||
|
result,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
return mainErrorHandler(ctx.set, error);
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -4,10 +4,12 @@ import { bulkInsertMediaController } from "./controllers/bulkInsertMedia.control
|
|||||||
import { createVideoServiceInternalController } from "./controllers/createVideoService.controller";
|
import { createVideoServiceInternalController } from "./controllers/createVideoService.controller";
|
||||||
import { bulkInsertVideoController } from "./controllers/bulkInsertVideo.controller";
|
import { bulkInsertVideoController } from "./controllers/bulkInsertVideo.controller";
|
||||||
import { updateAllEpisodeThumbnailController } from "./controllers/updateAllEpisodeThumbnail.controller";
|
import { updateAllEpisodeThumbnailController } from "./controllers/updateAllEpisodeThumbnail.controller";
|
||||||
|
import { purgeUnusedSessionController } from "./controllers/purgeUnusedSession.controller";
|
||||||
|
|
||||||
export const internalModule = new Elysia({ prefix: "/internal" })
|
export const internalModule = new Elysia({ prefix: "/internal" })
|
||||||
.post("/media/bulk-insert", bulkInsertMediaController)
|
.post("/media/bulk-insert", bulkInsertMediaController)
|
||||||
.post("/episode/bulk-insert", bulkInsertEpisodeController)
|
.post("/episode/bulk-insert", bulkInsertEpisodeController)
|
||||||
.put("/episode/update-thumbnails", updateAllEpisodeThumbnailController)
|
.put("/episode/update-thumbnails", updateAllEpisodeThumbnailController)
|
||||||
.post("/video/bulk-insert", bulkInsertVideoController)
|
.post("/video/bulk-insert", bulkInsertVideoController)
|
||||||
.post("/video-service", createVideoServiceInternalController);
|
.post("/video-service", createVideoServiceInternalController)
|
||||||
|
.post("/user-session/purge-unused", purgeUnusedSessionController);
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
import { AppError } from "../../../helpers/error/instances/app";
|
||||||
|
import { prisma } from "../../../utils/databases/prisma/connection";
|
||||||
|
|
||||||
|
export const deleteAllUnusedUserSessionRepository = async () => {
|
||||||
|
try {
|
||||||
|
return await prisma.userSession.deleteMany({
|
||||||
|
where: {
|
||||||
|
isAuthenticated: false,
|
||||||
|
deletedAt: {
|
||||||
|
not: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw new AppError(500, "Failed to delete all unused user sessions", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||||
|
import { deleteAllUnusedUserSessionRepository } from "../../repositories/deleteAllUnusedUserSession.repository";
|
||||||
|
|
||||||
|
export const purgeUnusedSessionService = async () => {
|
||||||
|
try {
|
||||||
|
return await deleteAllUnusedUserSessionRepository();
|
||||||
|
} catch (error) {
|
||||||
|
ErrorForwarder(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user