Skip to content

Commit

Permalink
trying to merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bellaabdelouahab committed Jun 25, 2023
2 parents 710ccbf + a6fe803 commit 8ebd680
Show file tree
Hide file tree
Showing 39 changed files with 493 additions and 464 deletions.
47 changes: 23 additions & 24 deletions backend-app/app.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const globalErrHandler = require("./middlewares/globalErrorHandler");
const AppError = require("./utils/appError");
const express = require("express");
const limiter = require("./middlewares/rate_limit");
const compression = require("compression");
const helmet = require("helmet");
const mongoSanitize = require("express-mongo-sanitize");
const xss = require("xss-clean");
const hpp = require("hpp");
const cors = require("cors");
const morgan = require("./middlewares/morgan");
const swaggerDocs = require("./utils/swagger");
const { CURRENT_ENV, API_VERSION } = require("./config/appConfig");
const globalErrHandler = require('./middlewares/global_error_handler');
const AppError = require('./utils/app_error');
const express = require('express');
const limiter = require('./middlewares/rate_limit');
const compression = require('compression');
const helmet = require('helmet');
const mongoSanitize = require('express-mongo-sanitize');
const xss = require('xss-clean');
const hpp = require('hpp');
const cors = require('cors');
const morgan = require('./middlewares/morgan');
const swaggerDocs = require('./utils/swagger');
const { CURRENT_ENV, API_VERSION } = require('./config/app_config');

const app = express();

Expand All @@ -34,14 +34,14 @@ app.use(helmet());
// Body parser, reading data from body into req.body
app.use(
express.json({
limit: "15kb",
limit: '15kb',
})
);

// Data sanitization against Nosql query injection
app.use(
mongoSanitize({
replaceWith: "_",
replaceWith: '_',
})
);

Expand All @@ -54,26 +54,25 @@ app.use(hpp());
// Compress all responses
app.use(compression());

if (CURRENT_ENV.toLocaleLowerCase() === "production") {
if (CURRENT_ENV.toLocaleLowerCase() === 'production') {
//Limiting request form same IP
app.use("/api", limiter);
app.use('/api', limiter);
}

// routes
app.use(`/api/${API_VERSION}`, require("./routes/index"));
app.use(`/api/${API_VERSION}`, require('./routes/index'));


app.get("/", (req, res) => {
app.get('/', (req, res) => {
res.status(200).json({
status: "success",
message: "Welcome to the backend app",
status: 'success',
message: 'Welcome to the backend app',
env: CURRENT_ENV,
});
});

// handle undefined Routes
app.use("*", (req, res, next) => {
const err = new AppError(404, "fail", "Route Not Found", req.path);
app.use('*', (req, res, next) => {
const err = new AppError(404, 'fail', 'Route Not Found', req.path);
next(err, req, res, next);
});

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { addColors, format } = require('winston');
const { logFilePath } = require('./appConfig');
const { logFilePath } = require('./app_config');
// Define the current environment
const currentEnv = process.env.NODE_ENV || 'development';

Expand Down Expand Up @@ -63,4 +63,4 @@ const fileOptions = {
module.exports = {
fileOptions,
consoleOptions,
}
};
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Actions = require('./Actions');
const Actions = require('./actions');
const Roles = {
SUPER_ADMIN: {
type: 'SUPER_ADMIN',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const userModel = require('../models/userModel');
const Actions = require('../constants/Actions');
const validateActions = require('../utils/authorization/validateActions');
const Role = require('../utils/authorization/role/Role');
const AppError = require('../utils/appError');
const userModel = require('../models/user_model');
const Actions = require('../constants/actions');
const validateActions = require('../utils/authorization/validate_actions');
const Role = require('../utils/authorization/role/role');
const AppError = require('../utils/app_error');
const role = new Role();

exports.addAdmin = async (req, res, next) => {
Expand Down Expand Up @@ -133,8 +133,8 @@ exports.authorizeOrRestrict = async (req, res, next) => {
const user = await userModel.findById(userId);
if (!user) throw new AppError(404, 'fail', 'No user found with this id');
// if the user is a super admin, he can't be restricted
if (user.roles?.includes("SUPER_ADMIN"))
throw new AppError(400, "fail", "User is a super admin");
if (user.roles?.includes('SUPER_ADMIN'))
throw new AppError(400, 'fail', 'User is a super admin');
const existingAuthorities = user.authorities;
const existingRestrictions = user.restrictions;
user.authorities = Array.from(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { promisify } = require('util');
const jwt = require('jsonwebtoken');
const User = require('../models/userModel');
const AppError = require('../utils/appError');
const Role = require('../utils/authorization/role/Role');
const { JWT_SECRET , JWT_EXPIRES_IN } = require("../config/appConfig");
const User = require('../models/user_model');
const AppError = require('../utils/app_error');
const Role = require('../utils/authorization/role/role');
const { JWT_SECRET, JWT_EXPIRES_IN } = require('../config/app_config');
const role = new Role();

const createToken = (id) => {
Expand Down Expand Up @@ -178,7 +178,7 @@ exports.restrictTo = (...roles) => {
});
if (!roleExist) {
return next(
new AppError(403, "fail", "You are not allowed to do this action"),
new AppError(403, 'fail', 'You are not allowed to do this action'),
req,
res,
next
Expand Down
124 changes: 0 additions & 124 deletions backend-app/controllers/baseController.js

This file was deleted.

Loading

0 comments on commit 8ebd680

Please sign in to comment.