Skip to content

Commit

Permalink
Adding user standarization 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MOHAMMED1MEDHAT committed Sep 10, 2023
1 parent 4b9760c commit 3b89c64
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/controllers/controllerUtils/handlerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ exports.getAll = Model => {
const doc = await Model.find();
if (!doc) return next(new AppError(`No ${Model} found at all`, 404));

const docObj =
`${Model}`.toLowerCase() === 'mentor'
? doc.map(d => standarizeMentor(d))
: doc.map(d => standarizeUser(d));
let docObj = {};

if (`${Model}`.toLowerCase() === 'mentor') {
docObj = doc.map(d => standarizeMentor(d));
} else if (`${Model}`.toLowerCase() === 'user') {
docObj = doc.map(d => standarizeUser(d));
} else {
docObj = doc;
}

res.status(res.locals.statusCode || res.locals.statusCode || 200).json({
status: 'success',
Expand All @@ -28,10 +33,15 @@ exports.activateOne = Model => {
if (!doc)
return next(new AppError(`No ${Model} found with that ID`, 404));

const docObj =
`${Model}`.toLowerCase() === 'mentor'
? standarizeMentor(doc)
: standarizeUser(doc);
let docObj = {};

if (`${Model}`.toLowerCase() === 'mentor') {
docObj = standarizeMentor(doc);
} else if (`${Model}`.toLowerCase() === 'user') {
docObj = standarizeMentor(doc);
} else {
docObj = doc;
}

res.status(res.locals.statusCode || 200).json({
status: 'success',
Expand Down Expand Up @@ -59,10 +69,15 @@ exports.getOne = Model => {
if (!doc)
return next(new AppError(`No ${Model} found with that ID`, 404));

const docObj =
`${Model}`.toLowerCase() === 'mentor'
? standarizeMentor(doc)
: standarizeUser(doc);
let docObj = {};

if (`${Model}`.toLowerCase() === 'mentor') {
docObj = standarizeMentor(doc);
} else if (`${Model}`.toLowerCase() === 'user') {
docObj = standarizeMentor(doc);
} else {
docObj = doc;
}

res.status(res.locals.statusCode || 200).json({
status: 'success',
Expand Down

0 comments on commit 3b89c64

Please sign in to comment.