Skip to content

Commit

Permalink
changing the status
Browse files Browse the repository at this point in the history
  • Loading branch information
bekiTil committed Jan 20, 2023
1 parent daca219 commit 9b409e4
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
4 changes: 2 additions & 2 deletions middlewares/check_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const jwt = require("jsonwebtoken");

module.exports = (req, res, next) => {
const authHeader = req.headers.authorization;
console.log(authHeader)

if (authHeader) {
const token = authHeader.split(" ")[1];
console.log(token)


jwt.verify(token, process.env.ACCESS_TOKEN_SECRET, (err, user) => {

Expand Down
1 change: 1 addition & 0 deletions middlewares/check_role.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const jwt = require("jsonwebtoken");

const check_role = (inputRole) => (req, res, next) => {
console.log(inputRole)
const authHeader = req.headers.authorization;
if (authHeader) {
const token = authHeader.split(" ")[1];
Expand Down
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,5 @@ enum Status {
PENDING
FAILED
SUCCESS
REJECTED
}
2 changes: 1 addition & 1 deletion routes/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ router.delete(
console.log(deletedUser)
res.json({ success: true, message: `Deleted parent ${id}`, deletedUser });
} catch (error) {
console.log(errro)
console.log(errror)
next(error);
}
}
Expand Down
35 changes: 35 additions & 0 deletions routes/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,36 @@ router.get("/one/:id", check_auth, async (req, res, next) => {
next(error);
}
});

router.get("/one/rejected/:id", check_auth, async (req, res, next) => {
const val = req.params.id;
console.log(req.params);
console.log(val);
try {
const reports = await prisma.report.findMany({
where: {
tutorId: Number(val),
status:"FAILED"
},
include: {
tutor: true,
},
});
console.log(reports);
if (reports) {
res.json({
success: true,
message: " List of reports",
reports: reports,
});
} else {
res.json({ success: false, message: `report not found` });
}
} catch (error) {
next(error);
}
});

router.get("/", check_auth, async (req, res, next) => {
try {
const users = await prisma.report.findMany({
Expand All @@ -156,6 +186,7 @@ router.get("/", check_auth, async (req, res, next) => {
router.get("/:id", check_auth, async (req, res, next) => {
const { id } = req.params;
console.log(id);
console.log("hi")

try {
const user = await prisma.report.findUnique({
Expand All @@ -174,6 +205,7 @@ router.get("/:id", check_auth, async (req, res, next) => {
res.json({ success: false, message: `report not found` });
}
} catch (error) {
console.log(error)
next(error);
}
});
Expand Down Expand Up @@ -202,6 +234,7 @@ router.patch("/:id", async (req, res, next) => {

router.delete("/:id", async (req, res, next) => {
const { id } = req.params;
console.log(id,'find')
try {
const deletedUser = await prisma.report.delete({
where: {
Expand All @@ -210,7 +243,9 @@ router.delete("/:id", async (req, res, next) => {
});
res.json({ success: true, message: `Deleted report ${id}`, deletedUser });
} catch (error) {
console.log(error)
next(error);

}
});

Expand Down
4 changes: 4 additions & 0 deletions routes/tutor.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ router.get("/pending", check_auth, async (req, res, next) => {
}
});
router.get("/", check_auth, async (req, res, next) => {
console.log('hi')
try {
const users = await prisma.tutor.findMany({
where :{
Expand All @@ -52,8 +53,10 @@ router.get("/", check_auth, async (req, res, next) => {
jobs: true,
},
});
console.log(users)
res.json({ success: true, message: "List of Tutors", users: users });
} catch (error) {
console.log(error)
next(error);
}
});
Expand Down Expand Up @@ -121,6 +124,7 @@ router.patch("/:id", check_auth, async (req, res, next) => {
});
res.json({ success: true, message: `Updated tutor ${id}`, updatedUser });
} catch (error) {
console.log(error)
next(error);
}
});
Expand Down

0 comments on commit 9b409e4

Please sign in to comment.