🚨 fix all linting error
This commit is contained in:
@ -4,6 +4,9 @@ import tseslint from "typescript-eslint";
|
|||||||
import { defineConfig } from "eslint/config";
|
import { defineConfig } from "eslint/config";
|
||||||
|
|
||||||
export default defineConfig([
|
export default defineConfig([
|
||||||
|
{
|
||||||
|
ignores: ["src/modules/debug/**"],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
files: ["src/**/*.{js,mjs,cjs,ts,mts,cts}"],
|
files: ["src/**/*.{js,mjs,cjs,ts,mts,cts}"],
|
||||||
plugins: { js },
|
plugins: { js },
|
||||||
|
|||||||
@ -9,6 +9,6 @@ export const unautenticatedMiddleware = (ctx: Context) => {
|
|||||||
if (cookie && cookie.auth_token)
|
if (cookie && cookie.auth_token)
|
||||||
return returnErrorResponse(ctx.set, 401, "You are already logged in. ");
|
return returnErrorResponse(ctx.set, 401, "You are already logged in. ");
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// Pass
|
void _; // Pass
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { Prisma } from "@prisma/client";
|
|
||||||
import { AppError } from "../../../helpers/error/instances/app";
|
import { AppError } from "../../../helpers/error/instances/app";
|
||||||
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
||||||
import { jwtDecode } from "../../../helpers/http/jwt/decode";
|
import { jwtDecode } from "../../../helpers/http/jwt/decode";
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
import { Context } from "elysia";
|
import { Context } from "elysia";
|
||||||
import {
|
import { returnWriteResponse } from "../../../helpers/callback/httpResponse";
|
||||||
returnErrorResponse,
|
|
||||||
returnWriteResponse,
|
|
||||||
} from "../../../helpers/callback/httpResponse";
|
|
||||||
import { mainErrorHandler } from "../../../helpers/error/handler";
|
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { editUserService } from "../services/editUser.service";
|
import { editUserService } from "../services/editUser.service";
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
import {
|
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
|
||||||
returnErrorResponse,
|
|
||||||
returnReadResponse,
|
|
||||||
} from "../../../helpers/callback/httpResponse";
|
|
||||||
import { Context } from "elysia";
|
import { Context } from "elysia";
|
||||||
import { getAllUsersService } from "../services/getAllUser.service";
|
import { getAllUsersService } from "../services/getAllUser.service";
|
||||||
import { mainErrorHandler } from "../../../helpers/error/handler";
|
import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||||
|
|||||||
@ -5,20 +5,13 @@ export const checkUserEmailAndUsernameAvailabillityRepo = async (
|
|||||||
username: string,
|
username: string,
|
||||||
email: string
|
email: string
|
||||||
) => {
|
) => {
|
||||||
try {
|
const checkUsernameAndEmailAvailabillity = await userModel.findFirst({
|
||||||
const checkUsernameAndEmailAvailabillity = await userModel.findFirst({
|
where: {
|
||||||
where: {
|
OR: [{ username: username ?? undefined }, { email: email ?? undefined }],
|
||||||
OR: [
|
NOT: {
|
||||||
{ username: username ?? undefined },
|
id: id,
|
||||||
{ email: email ?? undefined },
|
|
||||||
],
|
|
||||||
NOT: {
|
|
||||||
id: id,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
return checkUsernameAndEmailAvailabillity;
|
});
|
||||||
} catch (error) {
|
return checkUsernameAndEmailAvailabillity;
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,16 +2,12 @@ import { Prisma } from "@prisma/client";
|
|||||||
import { userModel } from "../user.model";
|
import { userModel } from "../user.model";
|
||||||
|
|
||||||
export const createUserRepo = async (data: Prisma.UserCreateInput) => {
|
export const createUserRepo = async (data: Prisma.UserCreateInput) => {
|
||||||
try {
|
const userData = await userModel.create({
|
||||||
const userData = await userModel.create({
|
data,
|
||||||
data,
|
omit: {
|
||||||
omit: {
|
password: true,
|
||||||
password: true,
|
},
|
||||||
},
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return userData;
|
return userData;
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,39 +1,34 @@
|
|||||||
import { AppError } from "../../../helpers/error/instances/app";
|
|
||||||
import { userModel } from "../user.model";
|
import { userModel } from "../user.model";
|
||||||
|
|
||||||
export const findUserByEmailOrUsernameRepo = async (identifier: string) => {
|
export const findUserByEmailOrUsernameRepo = async (identifier: string) => {
|
||||||
try {
|
const userData =
|
||||||
const userData =
|
(await userModel.findUnique({
|
||||||
(await userModel.findUnique({
|
where: { email: identifier },
|
||||||
where: { email: identifier },
|
include: {
|
||||||
include: {
|
roles: {
|
||||||
roles: {
|
omit: {
|
||||||
omit: {
|
createdBy: true,
|
||||||
createdBy: true,
|
createdAt: true,
|
||||||
createdAt: true,
|
updatedAt: true,
|
||||||
updatedAt: true,
|
deletedAt: true,
|
||||||
deletedAt: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})) ||
|
},
|
||||||
(await userModel.findUnique({
|
})) ||
|
||||||
where: { username: identifier },
|
(await userModel.findUnique({
|
||||||
include: {
|
where: { username: identifier },
|
||||||
roles: {
|
include: {
|
||||||
omit: {
|
roles: {
|
||||||
createdBy: true,
|
omit: {
|
||||||
createdAt: true,
|
createdBy: true,
|
||||||
updatedAt: true,
|
createdAt: true,
|
||||||
deletedAt: true,
|
updatedAt: true,
|
||||||
},
|
deletedAt: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}));
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
if (!userData) return false;
|
if (!userData) return false;
|
||||||
return userData;
|
return userData;
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,15 +1,11 @@
|
|||||||
import { userModel } from "../user.model";
|
import { userModel } from "../user.model";
|
||||||
|
|
||||||
export const getAllUserRepo = async () => {
|
export const getAllUserRepo = async () => {
|
||||||
try {
|
const data = await userModel.findMany({
|
||||||
const data = await userModel.findMany({
|
where: {
|
||||||
where: {
|
deletedAt: null,
|
||||||
deletedAt: null,
|
},
|
||||||
},
|
});
|
||||||
});
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,20 +1,16 @@
|
|||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { userModel } from "../user.model";
|
import { userModel } from "../user.model";
|
||||||
import { JWTSessionPayload } from "../../auth/auth.types";
|
|
||||||
|
|
||||||
export const updateUserRepo = async (
|
export const updateUserRepo = async (
|
||||||
username: string,
|
username: string,
|
||||||
payload: Prisma.UserUpdateInput
|
payload: Prisma.UserUpdateInput
|
||||||
) => {
|
) => {
|
||||||
try {
|
const userData = await userModel.update({
|
||||||
const userData = await userModel.update({
|
where: {
|
||||||
where: {
|
username,
|
||||||
username,
|
},
|
||||||
},
|
data: payload,
|
||||||
data: payload,
|
});
|
||||||
});
|
|
||||||
return userData;
|
return userData;
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
||||||
import { getAllUserRepo } from "../repositories/getAllUser.repository";
|
import { getAllUserRepo } from "../repositories/getAllUser.repository";
|
||||||
|
|
||||||
export const getAllUsersService = async () => {
|
export const getAllUsersService = async () => {
|
||||||
@ -5,6 +6,6 @@ export const getAllUsersService = async () => {
|
|||||||
const allUser = await getAllUserRepo();
|
const allUser = await getAllUserRepo();
|
||||||
return allUser;
|
return allUser;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
ErrorForwarder(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -4,12 +4,8 @@ import { userRoleModel } from "../userRole.model";
|
|||||||
export const createUserRoleRepo = async (
|
export const createUserRoleRepo = async (
|
||||||
data: Prisma.UserRoleUncheckedCreateInput
|
data: Prisma.UserRoleUncheckedCreateInput
|
||||||
) => {
|
) => {
|
||||||
try {
|
const newUserRole = await userRoleModel.create({
|
||||||
const newUserRole = await userRoleModel.create({
|
data,
|
||||||
data,
|
});
|
||||||
});
|
return newUserRole;
|
||||||
return newUserRole;
|
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { createUserRoleRepo } from "../repositories/createUserRole.repository";
|
import { createUserRoleRepo } from "../repositories/createUserRole.repository";
|
||||||
|
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
||||||
|
|
||||||
export const createUserRoleService = async (
|
export const createUserRoleService = async (
|
||||||
userRoleData: Prisma.UserRoleUncheckedCreateInput
|
userRoleData: Prisma.UserRoleUncheckedCreateInput
|
||||||
@ -23,6 +24,6 @@ export const createUserRoleService = async (
|
|||||||
const newUserRole = await createUserRoleRepo(dataPayload);
|
const newUserRole = await createUserRoleRepo(dataPayload);
|
||||||
return newUserRole;
|
return newUserRole;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
ErrorForwarder(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,31 +1,27 @@
|
|||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { userSessionModel } from "../userSession.model";
|
import { userSessionModel } from "../userSession.model";
|
||||||
import { AppError } from "../../../helpers/error/instances/app";
|
|
||||||
|
|
||||||
export const createUserSessionRepo = async (
|
export const createUserSessionRepo = async (
|
||||||
data: Prisma.UserSessionUncheckedCreateInput
|
data: Prisma.UserSessionUncheckedCreateInput
|
||||||
) => {
|
) => {
|
||||||
try {
|
const newUserSession = await userSessionModel.create({
|
||||||
const newUserSession = await userSessionModel.create({
|
data: data,
|
||||||
data: data,
|
include: {
|
||||||
include: {
|
user: {
|
||||||
user: {
|
omit: {
|
||||||
omit: {
|
password: true,
|
||||||
password: true,
|
},
|
||||||
},
|
include: {
|
||||||
include: {
|
roles: true,
|
||||||
roles: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
omit: {
|
},
|
||||||
lastOnline: true,
|
omit: {
|
||||||
createdAt: true,
|
lastOnline: true,
|
||||||
updatedAt: true,
|
createdAt: true,
|
||||||
},
|
updatedAt: true,
|
||||||
});
|
},
|
||||||
return newUserSession;
|
});
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
return newUserSession;
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,19 +1,14 @@
|
|||||||
import { Prisma } from "@prisma/client";
|
import { Prisma } from "@prisma/client";
|
||||||
import { AppError } from "../../../helpers/error/instances/app";
|
|
||||||
import { redis } from "../../../utils/databases/redis/connection";
|
import { redis } from "../../../utils/databases/redis/connection";
|
||||||
|
|
||||||
export const storeUserSessionToCacheRepo = async (
|
export const storeUserSessionToCacheRepo = async (
|
||||||
userSession: Prisma.UserSessionUncheckedCreateInput,
|
userSession: Prisma.UserSessionUncheckedCreateInput,
|
||||||
timeExpires: number
|
timeExpires: number
|
||||||
) => {
|
) => {
|
||||||
try {
|
await redis.set(
|
||||||
await redis.set(
|
`${process.env.APP_NAME}:users:${userSession.userId}:sessions:${userSession.id}`,
|
||||||
`${process.env.APP_NAME}:users:${userSession.userId}:sessions:${userSession.id}`,
|
String(userSession.validUntil),
|
||||||
String(userSession.validUntil),
|
"EX",
|
||||||
"EX",
|
timeExpires
|
||||||
timeExpires
|
);
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
throw new AppError(401, "Failed to store user session to cache");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,10 +2,10 @@
|
|||||||
* @typedef {Object} ErrorResponse
|
* @typedef {Object} ErrorResponse
|
||||||
* @property {number} status - The HTTP status code corresponding to the error.
|
* @property {number} status - The HTTP status code corresponding to the error.
|
||||||
* @property {string} message - A human-readable error message.
|
* @property {string} message - A human-readable error message.
|
||||||
* @property {any} [details] - Additional details about the error, if available.
|
* @property {unknown} [details] - Additional details about the error, if available.
|
||||||
*/
|
*/
|
||||||
export interface PrismaErrorTypes {
|
export interface PrismaErrorTypes {
|
||||||
status: number;
|
status: number;
|
||||||
message: string;
|
message: string;
|
||||||
details?: any;
|
details?: unknown;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user