Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Admin update role 187584923 #36

Merged
merged 69 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
c05dd76
[delivers #187584923] Delivered with testing
ndahimana154 May 28, 2024
f437de8
[finished #187584923] Feature admin should update user role
ndahimana154 May 29, 2024
12e1cd9
[finishes #187584923] Feature admin should update user role
ndahimana154 May 29, 2024
2fa629b
mend
ndahimana154 May 29, 2024
04525d1
[finishes #187584923] Feature admin should update user role 1
ndahimana154 May 29, 2024
a4847d6
mend
ndahimana154 May 29, 2024
58dd3b7
mend
ndahimana154 May 29, 2024
99209eb
mend
ndahimana154 May 29, 2024
23d8246
mend
ndahimana154 May 29, 2024
f8e8970
[delivers #187584915] Added user login (#35)
ProgrammerDATCH May 29, 2024
179c4af
mend
ndahimana154 May 29, 2024
670312f
mend
ndahimana154 May 29, 2024
b6e5eaa
mend
ndahimana154 May 29, 2024
6448d3f
mend
ndahimana154 May 29, 2024
ebe946d
[delivers #187584923] Delivered with testing
ndahimana154 May 28, 2024
7205375
[finished #187584923] Feature admin should update user role
ndahimana154 May 29, 2024
98ab372
mend
ndahimana154 May 29, 2024
d1a0fce
[finishes #187584923] Feature admin should update user role 1
ndahimana154 May 29, 2024
1a8c837
mend
ndahimana154 May 29, 2024
4361e54
mend
ndahimana154 May 29, 2024
afb2e1c
mend
ndahimana154 May 29, 2024
069ba78
mend
ndahimana154 May 29, 2024
fabee8f
mend
ndahimana154 May 29, 2024
afcab82
mend
ndahimana154 May 29, 2024
ee1ae32
mend
ndahimana154 May 29, 2024
e74661b
mend
ndahimana154 May 29, 2024
64cf94d
[Delivers #187584922] Admin should be able to disable an account (#25)
SaddockAime May 29, 2024
5c9e827
mend
ndahimana154 May 29, 2024
720a99b
mend
ndahimana154 May 29, 2024
cb059ba
Merge branch 'admin-update-role-187584923' of https://github.com/atlp…
ndahimana154 May 29, 2024
afc2658
[delivers #187584923] Delivered with testing
ndahimana154 May 28, 2024
2ae64d3
[finished #187584923] Feature admin should update user role
ndahimana154 May 29, 2024
a56e0af
mend
ndahimana154 May 29, 2024
be6feb1
mend
ndahimana154 May 29, 2024
5387078
mend
ndahimana154 May 29, 2024
ba536ab
mend
ndahimana154 May 29, 2024
acabb49
mend
ndahimana154 May 29, 2024
78c9861
mend
ndahimana154 May 29, 2024
fc3a7aa
mend
ndahimana154 May 29, 2024
b6b993b
mend
ndahimana154 May 29, 2024
91d8045
mend
ndahimana154 May 29, 2024
91cca0e
[delivers #187584923] Delivered with testing
ndahimana154 May 28, 2024
7f0ecb5
[finished #187584923] Feature admin should update user role
ndahimana154 May 29, 2024
d3c83eb
mend
ndahimana154 May 29, 2024
b838d92
[finishes #187584923] Feature admin should update user role 1
ndahimana154 May 29, 2024
f452943
mend
ndahimana154 May 29, 2024
6d2a460
mend
ndahimana154 May 29, 2024
7d918d6
mend
ndahimana154 May 29, 2024
d4596e2
mend
ndahimana154 May 29, 2024
326b4cc
mend
ndahimana154 May 29, 2024
8790618
mend
ndahimana154 May 29, 2024
7c64101
mend
ndahimana154 May 29, 2024
c11bed9
mend
ndahimana154 May 29, 2024
97d43c2
Merge branch 'admin-update-role-187584923' of https://github.com/atlp…
ndahimana154 May 29, 2024
f5d93cc
mend
ndahimana154 May 29, 2024
15332c3
mend
ndahimana154 May 29, 2024
8b3f5dd
[finishes #187584923] finishes fix the errors
ndahimana154 May 29, 2024
9a8614c
Merge branch 'admin-update-role-187584923' of https://github.com/atlp…
ndahimana154 May 29, 2024
77dafc3
mend
ndahimana154 May 29, 2024
8f757e0
mend
ndahimana154 May 30, 2024
da88ef1
mend
ndahimana154 May 30, 2024
ed83dee
Merge branch 'admin-update-role-187584923' of https://github.com/atlp…
ndahimana154 May 30, 2024
a2e439f
Merge branch 'admin-update-role-187584923' of https://github.com/atlp…
ndahimana154 May 30, 2024
34077ab
Merge branch 'admin-update-role-187584923' of https://github.com/atlp…
ndahimana154 May 30, 2024
f1fa7bc
Merge branch 'admin-update-role-187584923' of https://github.com/atlp…
ndahimana154 May 30, 2024
7d6a5f7
Merge branch 'admin-update-role-187584923' of https://github.com/atlp…
ndahimana154 May 30, 2024
bb3976e
Merge branch 'admin-update-role-187584923' of https://github.com/atlp…
ndahimana154 May 30, 2024
15c3fb9
Merge branch 'admin-update-role-187584923' of https://github.com/atlp…
ndahimana154 May 30, 2024
2d6c348
mend
ndahimana154 May 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
PORT=
NODE_ENV=
NODE_EN=
DOCKER_DATABASE_HOST_AUTH_METHOD=
DOCKER_DATABASE_NAME=
DOCKER_DATABASE_PASSWORD=
JWT_SECRET=
NODE_ENV=

SMTP_HOST_PORT=
MP=
SMTP_HOST=
MAIL_ID=

CLOUD_NAME=
API_KEY=
API_SECRET=

SERVER_URL_DEV=
SERVER_URL_PRO=

DATABASE_URL_DEV=
DATABASE_URL_TEST=
DATABASE_URL_PRO=
DB_HOST_TYPE=



DB_HOST_TYPE=
DOCKER_DATABASE_USER=
DOCKER_DATABASE_HOST_AUTH_METHOD=
DOCKER_DATABASE_NAME=
DOCKER_DATABASE_PASSWORD=
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ jobs:
- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@v2
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
8 changes: 8 additions & 0 deletions .hintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": [
"development"
],
"hints": {
"typescript-config/strict": "off"
}
}
10 changes: 5 additions & 5 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require("path");
module.exports = {
'config': path.resolve('dist/src','databases', 'config', 'config.js'),
'models-path': path.resolve('dist/src','databases', 'models'),
'seeders-path': path.resolve('dist/src','databases', 'seeders'),
'migrations-path': path.resolve('dist/src','databases', 'migrations')
};
'config': path.resolve('dist/src', 'databases', 'config', 'config.js'),
'models-path': path.resolve('dist/src', 'databases', 'models'),
'seeders-path': path.resolve('dist/src', 'databases', 'seeders'),
'migrations-path': path.resolve('dist/src', 'databases', 'migrations')
};
72 changes: 19 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Team Ninjas Backend
# TEAM NINJAS BACKEND

This is the backend for E-Commerce-Ninjas, written in Node.js with TypeScript.

Expand All @@ -23,26 +23,31 @@ This is the backend for E-Commerce-Ninjas, written in Node.js with TypeScript.
[https://github.com/atlp-rwanda/e-commerce-ninjas-bn](https://github.com/atlp-rwanda/e-commerce-ninjas-bn)


## Completed Features
## COMPLETED FEATURES

- Welcome Endpoint
- Register Endpoint
- Verification Email Endpoint
- Resend verification Endpoint
- Login Endpoint
- Admin Update Status Endpoint
- Admin Update Role Endpoint

## TABLE OF API ENDPOINTS SPECIFICATION AND DESCRIPTION


| No | VERBS | ENDPOINTS | STATUS | ACCESS | DESCRIPTION |
|----|-------|------------------------------|-------------|--------|---------------------------|
| 1 | GET | / | 200 OK | public | Show welcome message |
| 2 | GET | /api/auth/verify-email/:token| 200 OK | public | Verifying email |
| 3 | POST | /api/auth/register | 201 CREATED | public | create user account |
| 4 | POST | /api/auth/send-verify-email | 200 OK | public | Resend verification email |
| No | VERBS | ENDPOINTS | STATUS | ACCESS | DESCRIPTION |
|----|-------|-----------------------------------------|-------------|---------|-------------------------------|
| 1 | GET | / | 200 OK | public | Show welcome message |
| 2 | POST | /api/auth/register | 201 CREATED | public | create user account |
| 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 |
| 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
## INSTALLATION

1. Clone the repository:

Expand All @@ -63,7 +68,7 @@ This is the backend for E-Commerce-Ninjas, written in Node.js with TypeScript.
npm run dev
```

## Folder Structure
## FOLDER STRUCTURE

- `.env`: Secure environment variables.
- `src/`: Source code directory.
Expand All @@ -84,7 +89,7 @@ This is the backend for E-Commerce-Ninjas, written in Node.js with TypeScript.
- `services/`: Service functions like sendEmails.
- `index.ts`: Startup file for all requests.

## Initialize Sequelize CLI
## INITILIAZE SEQUELIZE CLI

1. Initialize Sequelize CLI:
```sh
Expand Down Expand Up @@ -117,43 +122,4 @@ This is the backend for E-Commerce-Ninjas, written in Node.js with TypeScript.
9. Delete the Migration:
```sh
npm run deleteAllTables
```



## Initialize Sequelize CLI

1. Initialize Sequelize CLI:
```sh
npx sequelize-cli init
```
2. Generate Seeder:
```sh
npx sequelize-cli seed:generate --name name-of-your-seeder
```
3. Generate Migrations:
```sh
npx sequelize-cli migration:generate --name name-of-your-migration
```
4. Define Migration:
Edit the generated migration file to include the tables you want to create.
5. Define Seeder Data:
Edit the generated seeder file to include the data you want to insert.
6. Run the Seeder:
```sh
npm run createAllSeeders
```
7. Run the Migration:
```sh
npm run createAllTables
```
8. Delete the Seeder:
```sh
npm run deleteAllSeeders
```
9. Delete the Migration:
```sh
npm run deleteAllTables
```


```
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@
"eslint-plugin-import": "^2.29.1",
"lint-staged": "^15.2.2"
}
}
}
11 changes: 0 additions & 11 deletions public/BUILD.txt

This file was deleted.

Binary file removed public/ProjectManagement.jpg
Binary file not shown.
2 changes: 1 addition & 1 deletion src/databases/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ const sequelizeConfig = {
}
};

module.exports = sequelizeConfig;
module.exports = sequelizeConfig;
88 changes: 44 additions & 44 deletions src/databases/config/db.config.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import { config } from "dotenv"
import { Sequelize } from "sequelize"
config()
const NODE_ENV: string = process.env.NODE_ENV || "development"
const DB_HOST_MODE: string = process.env.DB_HOST_TYPE || "remote"
/**
* Get the URI for the database connection.
* @returns {string} The URI string.
*/
function getDbUri(): string {
switch (NODE_ENV) {
case "development":
return process.env.DATABASE_URL_DEV as string
case "test":
return process.env.DATABASE_URL_TEST as string
default:
return process.env.DATABASE_URL_PRO as string
}
}
/**
* Get dialect options for Sequelize.
* @returns {DialectOptions} The dialect options.
*/
function getDialectOptions() {
return DB_HOST_MODE === "local"
? {}
: {
ssl: {
require: true,
rejectUnauthorized: false
}
}
}
const sequelizeConnection: Sequelize = new Sequelize(getDbUri(), {
dialect: "postgres",
dialectOptions: getDialectOptions(),
logging: false
})
export default sequelizeConnection
import { config } from "dotenv"
import { Sequelize } from "sequelize"

config()
const NODE_ENV: string = process.env.NODE_ENV || "development"
const DB_HOST_MODE: string = process.env.DB_HOST_TYPE || "remote"

/**
* Get the URI for the database connection.
* @returns {string} The URI string.
*/
function getDbUri(): string {
switch (NODE_ENV) {
case "development":
return process.env.DATABASE_URL_DEV as string
case "test":
return process.env.DATABASE_URL_TEST as string
default:
return process.env.DATABASE_URL_PRO as string
}
}

/**
* Get dialect options for Sequelize.
* @returns {DialectOptions} The dialect options.
*/
function getDialectOptions() {
return DB_HOST_MODE === "local"
? {}
: {
ssl: {
require: true,
rejectUnauthorized: false
}
}
}

const sequelizeConnection: Sequelize = new Sequelize(getDbUri(), {
dialect: "postgres",
dialectOptions: getDialectOptions(),
logging: false
})

export default sequelizeConnection
4 changes: 2 additions & 2 deletions src/databases/migrations/20240520180022-create-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default {
status: {
type: new DataTypes.STRING(128),
allowNull: false,
defaultValue: true
defaultValue: "enabled"
},
createdAt: {
allowNull: false,
Expand All @@ -99,4 +99,4 @@ export default {
DROP TYPE IF EXISTS "enum_users_gender";
`);
}
};
};
8 changes: 4 additions & 4 deletions src/databases/models/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface UsersAttributes {
role?: string;
isVerified?: boolean;
is2FAEnabled?: boolean;
status?: boolean;
status?: string;
createdAt?: Date;
updatedAt?: Date;
}
Expand All @@ -42,7 +42,7 @@ class Users extends Model<UsersAttributes, UsersCreationAttributes> implements U
declare role?: string;
declare isVerified?: boolean;
declare is2FAEnabled?: boolean;
declare status?: boolean;
declare status?: string;
declare password: string;
declare createdAt?: Date;
declare updatedAt?: Date;
Expand Down Expand Up @@ -122,7 +122,7 @@ Users.init(
status: {
type: new DataTypes.STRING(128),
allowNull: true,
defaultValue: true
defaultValue: "enabled"
},
createdAt: {
field: "createdAt",
Expand Down Expand Up @@ -152,4 +152,4 @@ Users.init(
}
);

export default Users;
export default Users;
9 changes: 6 additions & 3 deletions src/databases/seeders/20240520202759-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const userOne = {
birthDate: "2-2-2014",
language: "english",
currency: "USD",
role: "buyer"
role: "buyer",
status: "enabled"
}
const userTwo = {
createdAt: new Date(),
Expand All @@ -27,7 +28,8 @@ const userTwo = {
birthDate: "1990-01-01",
language: "English",
currency: "USD",
role: "buyer"
role: "buyer",
status: "enabled"
}

const userThree = {
Expand All @@ -43,7 +45,8 @@ const userThree = {
birthDate: "2-2-2014",
language: "english",
currency: "USD",
role: "buyer"
role: "buyer",
status: "enabled"
}

const up = (queryInterface: QueryInterface) => queryInterface.bulkInsert("users",[userOne, userTwo, userThree])
Expand Down
Loading
Loading