Skip to content

Commit

Permalink
fix(controller): fix assignment to constant variable when assigning m…
Browse files Browse the repository at this point in the history
…wb month
  • Loading branch information
rhahao authored Oct 3, 2022
1 parent 48749c6 commit 7cdfc23
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
34 changes: 32 additions & 2 deletions src/controllers/admin-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
} from '../utils/announcement-utils.js';
import {
getCongregations,
getCongregationInfo,
getCongregationsRequests,
} from '../utils/congregation-utils.js';
import { getUserInfo, getUsers } from '../utils/user-utils.js';
import { getUsers } from '../utils/user-utils.js';

// get firestore
const db = getFirestore();
Expand Down Expand Up @@ -254,3 +254,33 @@ export const publishAnnouncementAdmin = async (req, res, next) => {
next(err);
}
};

export const getAdminDashboard = async (req, res, next) => {
try {
const finalResult = await getCongregationsRequests();
const congsList = await getCongregations();
const users = await getUsers();

const obj = {
users: {
total: users.length,
active: users.filter((user) => user.mfaEnabled === true).length,
mfaPending: users.filter(
(user) => user.emailVerified === true && user.mfaEnabled === false
).length,
unverified: users.filter((user) => user.emailVerified === false).length,
pockets: users.filter((user) => user.global_role === 'pocket').length,
},
congregations: {
requests: finalResult.length,
active: congsList.length,
},
};

res.locals.type = 'info';
res.locals.message = 'admin fetched dashboard';
res.status(200).json(obj);
} catch (err) {
next(err);
}
};
2 changes: 1 addition & 1 deletion src/controllers/public-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getSchedules = async (req, res, next) => {
const weekDate = new Date(today.setDate(diff));
const currentMonth = weekDate.getMonth() + 1;
const monthOdd = currentMonth % 2 === 0 ? false : true;
let monthMwb = monthOdd ? currentMonth : currentMonth--;
let monthMwb = monthOdd ? currentMonth : currentMonth - 1;
let currentYear = weekDate.getFullYear();

let notFound = false;
Expand Down
4 changes: 4 additions & 0 deletions src/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { adminAuthChecker } from '../middleware/admin-auth-checker.js';
// import controllers
import {
deleteAnnouncementAdmin,
getAdminDashboard,
getAllAnnouncements,
getAnnouncementAdmin,
getBlockedRequests,
Expand All @@ -36,6 +37,9 @@ router.use('/users', usersRoute);
// validate user admin => passed middleware
router.get('/', validateAdmin);

// publish announcement
router.get('/dashboard', getAdminDashboard);

// logout admin
router.get('/logout', logoutAdmin);

Expand Down

0 comments on commit 7cdfc23

Please sign in to comment.