-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created dashboard stats and included authentication and authorization…
… rules
- Loading branch information
1 parent
57fcc76
commit f550484
Showing
22 changed files
with
807 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// const CheckAccessRight = (rightsArray, user) => { | ||
// if (!user) return false; | ||
// const accessLevel = user.accessLevel; | ||
// const accessIndex = rightsArray.indexOf(accessLevel.toLowerCase()); | ||
// if (accessIndex != -1) return true; | ||
// return false; | ||
// }; | ||
|
||
// export default CheckAccessRight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import JusibeModule from "./jusibeModule"; | ||
import EBulkSms from "./ebulkSms"; | ||
import CheapGlobalSMS from "./cheapGlobalSMS"; | ||
import SendErrorEmail from "./sendErrorEmail"; | ||
|
||
export default { | ||
//JusibeModule, | ||
//EBulkSms, | ||
CheapGlobalSMS, | ||
SendErrorEmail, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const nodemailer = require("nodemailer"); | ||
const { DeveloperBugsEmailSupport, DeveloperBugsEmailPassword } = process.env; | ||
|
||
const transporter = nodemailer.createTransport({ | ||
service: "gmail", | ||
auth: { | ||
user: DeveloperBugsEmailSupport, | ||
pass: DeveloperBugsEmailPassword, | ||
}, | ||
}); | ||
|
||
export const sendErrorMailToDeveloper = async (message) => { | ||
var mailOptions = { | ||
from: DeveloperBugsEmailSupport, | ||
to: DeveloperBugsEmailSupport, | ||
subject: "Bugs Report from UUHOSTEL", | ||
text: message, | ||
}; | ||
try { | ||
transporter.sendMail(mailOptions); | ||
} catch (error) { | ||
console.log("error send email to developer"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
import { ForbiddenError } from 'apollo-server'; | ||
import { skip } from 'graphql-resolvers'; | ||
|
||
export const isAuthenticated = (parent, args, { me }) => | ||
me ? skip : new ForbiddenError('Not authenticated as user.'); | ||
import { ForbiddenError } from "apollo-server"; | ||
import { skip } from "graphql-resolvers"; | ||
|
||
export const isAuthenticated = (parent, args, ctx) => { | ||
return ctx && ctx.user | ||
? skip | ||
: new ForbiddenError("Not authenticated as user."); | ||
}; | ||
|
||
export const isAdmin = (parent, args, { user }) => { | ||
if (user) { | ||
return user.accessLevel === "super-admin" || user.accessLevel === "admin" | ||
? skip | ||
: new ForbiddenError("only an administrator can perform this task"); | ||
} else { | ||
return new ForbiddenError("You must be authenticated to continue"); | ||
} | ||
}; | ||
|
||
export const isSuperAdmin = (parent, args, { user }) => { | ||
return user && user.accessLevel === "super-admin" | ||
? skip | ||
: new ForbiddenError( | ||
"you must be login as a super administrator to continue."`1` | ||
); | ||
}; | ||
|
||
export const isStudent = (parent, args, { user }) => { | ||
return user && user.userType === "student" | ||
? skip | ||
: new ForbiddenError("only a student can perform this task."); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { combineResolvers } from "graphql-resolvers"; | ||
import { isAuthenticated, isAdmin } from "./authorization"; | ||
|
||
export default { | ||
Query: { | ||
getAdminDashBoardStats: combineResolvers( | ||
isAuthenticated, | ||
isAdmin, | ||
async (_, {}, { fastConn }) => { | ||
const [ | ||
studentAccounts, | ||
hostelNumber, | ||
vacantBeds, | ||
lockedBeds, | ||
occupiedBeds, | ||
] = await Promise.all([ | ||
fastConn.models.StudentBio.countDocuments(), | ||
fastConn.models.Hostel.countDocuments(), | ||
fastConn.models.BedSpace.find({ | ||
bedStatus: "vacant", | ||
}).countDocuments(), | ||
fastConn.models.BedSpace.find({ | ||
bedStatus: "locked", | ||
}).countDocuments(), | ||
|
||
fastConn.models.BedSpace.find({ | ||
bedStatus: "occupied", | ||
}).countDocuments(), | ||
]); | ||
|
||
return { | ||
studentAccounts: +studentAccounts, | ||
hostelNumber: +hostelNumber, | ||
vacantBeds: +vacantBeds, | ||
lockedBeds: +lockedBeds, | ||
occupiedBeds: +occupiedBeds, | ||
}; | ||
} | ||
), | ||
getBedAlloctedStats: async (_, {}, {}) => {}, | ||
}, | ||
Mutation: { | ||
updateBedAlloctedStats: async (parent, {}, {}) => {}, | ||
}, | ||
}; |
Oops, something went wrong.