Skip to content

Commit

Permalink
Feature Admin update role 187584923 (#36)
Browse files Browse the repository at this point in the history
* [delivers #187584923] Delivered with testing

* [finished #187584923] Feature admin should update user role

* [finishes #187584923] Feature admin should update user role

* mend

* [finishes #187584923] Feature admin should update user role 1

* mend

* mend

* mend

* mend

* [delivers #187584915] Added user login (#35)

* mend

* mend

* mend

* mend

* [delivers #187584923] Delivered with testing

* [finished #187584923] Feature admin should update user role

* mend

* [finishes #187584923] Feature admin should update user role 1

* mend

* mend

* mend

* mend

* mend

* mend

* mend

* mend

* [Delivers #187584922] Admin should be able to disable an account (#25)

* [Delivers #187584922] Admin should be able to disable an account

* Admin should be able to disable or enable an account

* Admin should be able to disable or enable an account

* Admin should be able to disable or enable an account

* Admin should be able to disable or enable an account

* Admin should be able to disable or enable an account

* Adjusted the database

* DB adjusted

* adjusted info

* done rebase

* mend

* mend

* [delivers #187584923] Delivered with testing

* [finished #187584923] Feature admin should update user role

* mend

* mend

* mend

* mend

* mend

* mend

* mend

* mend

* mend

* [delivers #187584923] Delivered with testing

* [finished #187584923] Feature admin should update user role

* mend

* [finishes #187584923] Feature admin should update user role 1

* mend

* mend

* mend

* mend

* mend

* mend

* mend

* mend

* mend

* mend

* [finishes #187584923] finishes fix the errors

* mend

* mend

* mend

* mend

---------

Co-authored-by: Mr. David <[email protected]>
Co-authored-by: Saddock Kabandana <[email protected]>
  • Loading branch information
3 people authored May 30, 2024
1 parent 64cf94d commit 7582873
Show file tree
Hide file tree
Showing 14 changed files with 342 additions and 113 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ This is the backend for E-Commerce-Ninjas, written in Node.js with TypeScript.
- Verification Email Endpoint
- Resend verification Endpoint
- Login Endpoint
- Admin change status Endpoint
- Admin Update Status Endpoint
- Admin Update Role Endpoint

## TABLE OF API ENDPOINTS SPECIFICATION AND DESCRIPTION

Expand All @@ -42,8 +43,9 @@ This is the backend for E-Commerce-Ninjas, written in Node.js with TypeScript.
| 3 | GET | /api/auth/verify-email/:token | 200 OK | public | Verifying email |
| 4 | POST | /api/auth/send-verify-email | 200 OK | public | Resend verification email |
| 5 | POST | /api/auth/login | 200 OK | public | Login with Email and Password |
| 6 | PUT | /api/users/admin-update-user-status/:id | 200 OK | private | Admin change status |

| 5 | PUT | /api/users/admin-update-role/:id | 200 OK | private | Update the user role by admin|
| 6 | PUT | /api/users/admin-update-user-status/:id | 200 OK | private | Admin Update Status Endpoint |
| 7 | PUT | /api/users/admin-update-role/:id | 200 OK | private | Admin Update Role Endpoint |

## INSTALLATION

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"start": "ts-node-dev src/index.ts",
"dev": "ts-node-dev src/index.ts",
"test": "cross-env NODE_ENV=test npm run deleteAllTables && cross-env NODE_ENV=test npm run createAllTables && cross-env NODE_ENV=test npm run createAllSeeders && nyc cross-env NODE_ENV=test mocha --require ts-node/register 'src/**/*.spec.ts' --timeout 600000 --exit",
"test-dev": "cross-env NODE_ENV=development npm run deleteAllTables && cross-env NODE_ENV=development npm run createAllTables && cross-env NODE_ENV=development npm run createAllSeeders && nyc cross-env NODE_ENV=development mocha --require ts-node/register 'src/**/*.spec.ts' --timeout 600000 --exit",
"coveralls": "nyc --reporter=lcov --reporter=text-lcov npm test | coveralls",
"coverage": "cross-env NODE_ENV=test nyc mocha --require ts-node/register 'src/**/*.spec.ts' --timeout 600000 --exit",
"lint": "eslint . --ext .ts",
Expand Down
11 changes: 0 additions & 11 deletions public/BUILD.txt

This file was deleted.

Binary file removed public/ProjectManagement.jpg
Binary file not shown.
Empty file removed src/middlewares/index.ts
Empty file.
5 changes: 4 additions & 1 deletion src/middlewares/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,7 @@ const verifyUserCredentials = async (req: Request, res: Response, next: NextFunc



export { validation, isUserExist, isAccountVerified, verifyUserCredentials };



export { validation, isUserExist, isAccountVerified,verifyUserCredentials };
2 changes: 1 addition & 1 deletion src/modules/auth/controller/authControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const sendVerifyEmail = async (req: any, res: Response) => {
const verifyEmail = async (req: any, res: Response) => {
try {
await authRepositories.destroySession(req.user.id, req.session.token)
await authRepositories.UpdateUserByAttributes("isVerified", true, "id", req.user.id);
await authRepositories.updateUserByAttributes("isVerified", true, "id", req.user.id);
res.status(httpStatus.OK).json({ status: httpStatus.OK, message: "Account verified successfully, now login." });
} catch (error) {
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ status: httpStatus.INTERNAL_SERVER_ERROR, message: error.message });
Expand Down
4 changes: 2 additions & 2 deletions src/modules/auth/repository/authRepositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const findUserByAttributes = async (key:string, value:any) =>{
return await Users.findOne({ where: { [key]: value} })
}

const UpdateUserByAttributes = async (updatedKey:string, updatedValue:any, whereKey:string, whereValue:any) =>{
const updateUserByAttributes = async (updatedKey:string, updatedValue:any, whereKey:string, whereValue:any) =>{
await Users.update({ [updatedKey]: updatedValue }, { where: { [whereKey]: whereValue} });
return await findUserByAttributes(whereKey, whereValue)
}
Expand All @@ -28,4 +28,4 @@ const destroySession = async (userId: number, token:string) =>{
return await Session.destroy({ where: {userId, token } });
}

export default { createUser, createSession, findUserByAttributes, destroySession, UpdateUserByAttributes, findSessionByUserId }
export default { createUser, createSession, findUserByAttributes, destroySession, updateUserByAttributes, findSessionByUserId }
27 changes: 24 additions & 3 deletions src/modules/user/controller/userControllers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
// user Controllers
import { Request, Response } from "express";
import httpStatus from "http-status";

import authRepositories from "../../auth/repository/authRepositories";
import httpStatus from "http-status";

const updateUserRole = async (req: Request, res: Response) => {
try {
const data = await authRepositories.updateUserByAttributes("role", req.body.role, "id", req.params.id)
return res.status(httpStatus.OK).json({
message: "User role updated successfully",
data
});
} catch (error) {
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({
status: httpStatus.INTERNAL_SERVER_ERROR,
message: error.message
});
}
};


const updateUserStatus = async (req: Request, res: Response): Promise<void> => {
try {
const userId: number = Number(req.params.id);
const data = await authRepositories.UpdateUserByAttributes("status", req.body.status, "id", userId);
const data = await authRepositories.updateUserByAttributes("status", req.body.status, "id", userId);
res.status(httpStatus.OK).json({ message: "Status updated successfully.", data });
} catch (error) {
res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ status: httpStatus.INTERNAL_SERVER_ERROR, message: error.message });
}
};
export default { updateUserStatus };



export default { updateUserStatus,updateUserRole };
Loading

0 comments on commit 7582873

Please sign in to comment.