🚚 create backup folder
create backup folder for archive the old modules
This commit is contained in:
@ -0,0 +1,13 @@
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { redis } from "../../../utils/databases/redis/connection";
|
||||
|
||||
export const checkUserSessionInCacheRepo = async (redisKeyName: string) => {
|
||||
try {
|
||||
const userSessionInRedis = await redis.exists(redisKeyName);
|
||||
if (!userSessionInRedis) return false;
|
||||
|
||||
return userSessionInRedis;
|
||||
} catch (error) {
|
||||
throw new AppError(500, "Server cache error", error);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,16 @@
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { redis } from "../../../utils/databases/redis/connection";
|
||||
|
||||
export const deleteUserSessionFromCacheRepo = async (
|
||||
userId: string,
|
||||
sessionId: string
|
||||
) => {
|
||||
try {
|
||||
const deleteUserSessionFromCache = redis.del(
|
||||
`${process.env.APP_NAME}:users:${userId}:sessions:${sessionId}`
|
||||
);
|
||||
return deleteUserSessionFromCache;
|
||||
} catch (error) {
|
||||
throw new AppError(500, "Error while remove data from cache", error);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,19 @@
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { prisma } from "../../../utils/databases/prisma/connection";
|
||||
|
||||
export const deleteUserSessionFromDBRepo = async (sessionId: string) => {
|
||||
try {
|
||||
const deleteUserSessionFromCacheDB = await prisma.userSession.update({
|
||||
where: {
|
||||
id: sessionId,
|
||||
},
|
||||
data: {
|
||||
deletedAt: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
return deleteUserSessionFromCacheDB;
|
||||
} catch (error) {
|
||||
throw new AppError(500, "Error while remove delete from database", error);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,32 @@
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { prisma } from "../../../utils/databases/prisma/connection";
|
||||
|
||||
export const findUniqueUserSessionInDBRepo = async (identifier: string) => {
|
||||
try {
|
||||
const userSession = await prisma.userSession.findUnique({
|
||||
where: {
|
||||
id: identifier,
|
||||
},
|
||||
include: {
|
||||
user: {
|
||||
omit: {
|
||||
password: true,
|
||||
updatedAt: true,
|
||||
},
|
||||
include: {
|
||||
roles: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
omit: {
|
||||
updatedAt: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!userSession) return false;
|
||||
|
||||
return userSession;
|
||||
} catch (error) {
|
||||
throw new AppError(500, "Database Error", error);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,27 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { userSessionModel } from "../userSession.model";
|
||||
|
||||
export const createUserSessionRepo = async (
|
||||
data: Prisma.UserSessionUncheckedCreateInput
|
||||
) => {
|
||||
const newUserSession = await userSessionModel.create({
|
||||
data: data,
|
||||
include: {
|
||||
user: {
|
||||
omit: {
|
||||
password: true,
|
||||
},
|
||||
include: {
|
||||
roles: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
omit: {
|
||||
lastOnline: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
},
|
||||
});
|
||||
|
||||
return newUserSession;
|
||||
};
|
||||
@ -0,0 +1,14 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { redis } from "../../../utils/databases/redis/connection";
|
||||
|
||||
export const storeUserSessionToCacheRepo = async (
|
||||
userSession: Prisma.UserSessionUncheckedCreateInput,
|
||||
timeExpires: number
|
||||
) => {
|
||||
await redis.set(
|
||||
`${process.env.APP_NAME}:users:${userSession.userId}:sessions:${userSession.id}`,
|
||||
String(userSession.validUntil),
|
||||
"EX",
|
||||
timeExpires
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user