Skip to content

Commit e3e94d2

Browse files
committed
Fixed the GET searchUser API body issue
1 parent 13a16e2 commit e3e94d2

File tree

11 files changed

+445
-331
lines changed

11 files changed

+445
-331
lines changed

.github/job.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ const getUserNameFromCodeBaseFile = (fileName) => {
2929

3030
// function to connect to mongodb using mongoose
3131
const connectMongoDB = () => {
32-
mongoose.connect(process.env.MONGODB_URI, {
33-
useNewUrlParser: true,
34-
useUnifiedTopology: true,
35-
})
32+
mongoose.connect(process.env.MONGODB_URI)
3633
const db = mongoose.connection
3734
db.on('error', console.error.bind(console, 'Connection error:'))
3835
return db
@@ -58,13 +55,13 @@ const insertDataInMongo = (records) => {
5855
const callGithubCodeBaseAPI = () => {
5956
axios
6057
.get(
61-
`https://api.github.com/repos/TECHOUS/${process.env.CODE_SRC}/contents/CodeBase`
58+
`https://api.github.com/repos/TECHOUS/${process.env.CODE_SRC}/contents/CodeBase`,
6259
)
6360
.then((res) => {
6461
// get all the names from the files
6562
const filePromises = res.data.map((codeObject) => {
6663
return getUserNameFromCodeBaseFile(
67-
`${process.env.CODE_SRC}/${codeObject.path}`
64+
`${process.env.CODE_SRC}/${codeObject.path}`,
6865
)
6966
})
7067

@@ -77,7 +74,7 @@ const callGithubCodeBaseAPI = () => {
7774
fileObject.value.fileName,
7875
fileObject.value.username,
7976
]
80-
})
77+
}),
8178
)
8279

8380
const dataToInsert = res.data.map((data) => {

.github/workflows/Vercel Deployment.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
14-
- uses: actions/setup-node@v2
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
1515
with:
16-
node-version: '18.x'
16+
node-version: '20.x'
1717
- run: yarn install
1818
- run: yarn run test
1919
env:
@@ -25,8 +25,8 @@ jobs:
2525
needs: test
2626
runs-on: ubuntu-latest
2727
steps:
28-
- uses: actions/checkout@v2
29-
- uses: amondnet/vercel-action@v20
28+
- uses: actions/checkout@v4
29+
- uses: amondnet/vercel-action@v25
3030
with:
3131
vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required
3232
vercel-args: '--prod' #Optional

.github/workflows/Vercel Dev Deployment.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
14-
- uses: actions/setup-node@v2
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
1515
with:
16-
node-version: '18.x'
16+
node-version: '20.x'
1717
- run: yarn install
1818
- run: yarn run test
1919
env:
@@ -25,8 +25,8 @@ jobs:
2525
needs: test
2626
runs-on: ubuntu-latest
2727
steps:
28-
- uses: actions/checkout@v2
29-
- uses: amondnet/vercel-action@v20
28+
- uses: actions/checkout@v4
29+
- uses: amondnet/vercel-action@v25
3030
with:
3131
vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required
3232
vercel-org-id: ${{ secrets.ORG_ID}} #Required

.github/workflows/codebase-engine.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ jobs:
66
init-setup:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
10-
- uses: actions/setup-node@v2
9+
- uses: actions/checkout@v4
10+
- uses: actions/setup-node@v4
1111
with:
12-
node-version: '18.x'
12+
node-version: '20.x'
1313
- run: yarn install
1414
- run: bash .github/job.sh
1515
env:

api/public/assets/main.bundle.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/public/index.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
<meta name="description" content="Engine to handle the rating mechanisms for the clean code">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
8-
<link href="assets/bootstrap.min.css?v=1697340676180" rel="stylesheet" media="screen">
9-
<link href="assets/prism.css?v=1697340676180" rel="stylesheet" />
10-
<link href="assets/prism-toolbar.css?v=1697340676180" rel="stylesheet" />
11-
<link href="assets/prism-diff-highlight.css?v=1697340676180" rel="stylesheet" />
12-
<link href="assets/main.css?v=1697340676180" rel="stylesheet" media="screen, print">
13-
<link href="assets/favicon.ico?v=1697340676180" rel="icon" type="image/x-icon">
14-
<link href="assets/apple-touch-icon.png?v=1697340676180" rel="apple-touch-icon" sizes="180x180">
15-
<link href="assets/favicon-32x32.png?v=1697340676180" rel="icon" type="image/png" sizes="32x32">
16-
<link href="assets/favicon-16x16.png?v=1697340676180" rel="icon" type="image/png" sizes="16x16">
8+
<link href="assets/bootstrap.min.css?v=1727848448632" rel="stylesheet" media="screen">
9+
<link href="assets/prism.css?v=1727848448632" rel="stylesheet" />
10+
<link href="assets/prism-toolbar.css?v=1727848448632" rel="stylesheet" />
11+
<link href="assets/prism-diff-highlight.css?v=1727848448632" rel="stylesheet" />
12+
<link href="assets/main.css?v=1727848448632" rel="stylesheet" media="screen, print">
13+
<link href="assets/favicon.ico?v=1727848448632" rel="icon" type="image/x-icon">
14+
<link href="assets/apple-touch-icon.png?v=1727848448632" rel="apple-touch-icon" sizes="180x180">
15+
<link href="assets/favicon-32x32.png?v=1727848448632" rel="icon" type="image/png" sizes="32x32">
16+
<link href="assets/favicon-16x16.png?v=1727848448632" rel="icon" type="image/png" sizes="16x16">
1717
</head>
1818

1919
<body class="container-fluid">
@@ -1042,6 +1042,6 @@ <h2>{{__ "Request Body"}}</h2>
10421042
</div>
10431043
</div>
10441044

1045-
<script src="assets/main.bundle.js?v=1697340676180"></script>
1045+
<script src="assets/main.bundle.js?v=1727848448632"></script>
10461046
</body>
10471047
</html>

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "coderatingengine",
3-
"version": "1.0.0",
3+
"version": "1.20.0",
44
"engines": {
5-
"node": "18.x",
5+
"node": "20.x",
66
"yarn": "1.x"
77
},
88
"description": "Engine to handle the rating mechanisms for the clean code",
@@ -17,22 +17,22 @@
1717
"author": "Gaurav Walia",
1818
"license": "ISC",
1919
"dependencies": {
20-
"axios": "^1.5.1",
20+
"axios": "^1.7.7",
2121
"cors": "^2.8.5",
22-
"express": "^4.18.2",
23-
"express-rate-limit": "^7.1.1",
24-
"mongoose": "^7.6.2",
25-
"uuid": "^9.0.1"
22+
"express": "^4.21.0",
23+
"express-rate-limit": "^7.4.0",
24+
"mongoose": "^8.7.0",
25+
"uuid": "^10.0.0"
2626
},
2727
"devDependencies": {
2828
"apidoc": "^1.2.0",
2929
"dotenv": "^16.3.1",
3030
"husky": "^8.0.3",
3131
"lint-staged": "^14.0.1",
32-
"mocha": "^10.2.0",
33-
"nodemon": "^3.0.1",
32+
"mocha": "^10.7.3",
33+
"nodemon": "^3.1.7",
3434
"prettier": "^3.0.3",
35-
"supertest": "^6.3.3"
35+
"supertest": "^7.0.0"
3636
},
3737
"lint-staged": {
3838
"*.js": "prettier --write"

routes/api/v1/API.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,12 @@ router.put(
250250
* @apiName searchUser
251251
* @apiDescription search and return the code rating for the specific user
252252
* @apiVersion 1.0.0
253-
* @apiBody {String} codeRatingEngineToken Access token received from randomCodes request
253+
* @apiHeader {String} authorization Access token received from randomCodes request
254+
* @apiHeaderExample {json} Request Header example
255+
* {
256+
* "Authorization": "Bearer <ACCESS_TOKEN>"
257+
* }
258+
*
254259
* @apiQuery {String} username Username to search
255260
* @apiQuery {Boolean} sendContent Whether content is needed from the API or not
256261
*

src/auth.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
const {validateToken} = require('./engine')
22

33
async function authenticateAPI(req, res, next) {
4-
const {codeRatingEngineToken} = req.body
4+
const {authorization} = req.headers
55

6-
if (codeRatingEngineToken === undefined) {
7-
return res.status(401).json({
8-
status: 401,
9-
message: 'Invalid Token !! Please send the valid token',
10-
})
11-
} else {
6+
if (authorization && authorization.startsWith('Bearer ')) {
7+
const codeRatingEngineToken = authorization.replace('Bearer ', '')
128
const tokenFound = await validateToken(codeRatingEngineToken)
139
if (Array.isArray(tokenFound) && tokenFound.length > 0) {
1410
next()
1511
} else {
1612
return res.status(401).json({
1713
status: 401,
18-
message: 'Invalid Token !! Please send the valid token',
14+
message:
15+
'Invalid Authorization Token !! Please send the valid token',
1916
})
2017
}
18+
} else {
19+
return res.status(401).json({
20+
status: 401,
21+
message:
22+
'Invalid Authorization Token !! Please send the valid token',
23+
})
2124
}
2225
}
2326

src/engine.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ const accessTokenModel = require('../models/accessToken')
44
const {default: axios} = require('axios')
55
const {v4: uuidv4} = require('uuid')
66

7-
mongoose.connect(process.env.MONGODB_URI, {
8-
useNewUrlParser: true,
9-
useUnifiedTopology: true,
10-
})
7+
mongoose.connect(process.env.MONGODB_URI)
118
const db = mongoose.connection
129
db.on('error', console.error.bind(console, 'Connection error:'))
1310

0 commit comments

Comments
 (0)