Skip to content
Snippets Groups Projects
Commit b4cf8785 authored by alrwasheda's avatar alrwasheda :speech_balloon:
Browse files

showAnAccount controller: using id (email)

parent 0d772081
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ import bcrypt from "bcrypt";
import { Request, Response } from "express";
import Worker from "../db/models/Worker";
//create new account
const createAccountController = async (req: Request, res: Response) => {
try {
if (!(res.locals.user.role === "coordinator")) {
......@@ -47,7 +48,7 @@ const createAccountController = async (req: Request, res: Response) => {
return res.status(500).json({ success: false, error: "serverError" });
}
};
//show all accounts
const showAllAccounts = async (req: Request, res: Response) => {
try {
if (!(res.locals.user.role === "coordinator")) {
......@@ -63,6 +64,29 @@ const showAllAccounts = async (req: Request, res: Response) => {
}
};
const accountsControllers = { createAccountController, showAllAccounts };
//show a specific account using given id: email is the primary key for a worker
const showAccountById = async (req: Request, res: Response) => {
try {
if (!(res.locals.user.role === "coordinator")) {
return res
.status(403)
.json({ success: false, error: "MustBeCoordinator" });
}
const givenId = req.params.id;
const account = await Worker.findByPk(givenId);
if (account) {
return res.status(200).json({ success: true, result: account });
}
return res.status(404).json({ success: false, error: "accountIdNotFound" });
} catch (error) {
console.error("server error: ", error.message);
return res.status(500).json({ success: false, error: "serverError" });
}
};
const accountsControllers = {
createAccountController,
showAllAccounts,
showAccountById,
};
export default accountsControllers;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment