Skip to content

Commit

Permalink
Fixed the GET searchUser API body issue
Browse files Browse the repository at this point in the history
  • Loading branch information
GauravWalia19 committed Oct 2, 2024
1 parent 13a16e2 commit e3e94d2
Show file tree
Hide file tree
Showing 11 changed files with 445 additions and 331 deletions.
11 changes: 4 additions & 7 deletions .github/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ const getUserNameFromCodeBaseFile = (fileName) => {

// function to connect to mongodb using mongoose
const connectMongoDB = () => {
mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
mongoose.connect(process.env.MONGODB_URI)
const db = mongoose.connection
db.on('error', console.error.bind(console, 'Connection error:'))
return db
Expand All @@ -58,13 +55,13 @@ const insertDataInMongo = (records) => {
const callGithubCodeBaseAPI = () => {
axios
.get(
`https://api.github.com/repos/TECHOUS/${process.env.CODE_SRC}/contents/CodeBase`
`https://api.github.com/repos/TECHOUS/${process.env.CODE_SRC}/contents/CodeBase`,
)
.then((res) => {
// get all the names from the files
const filePromises = res.data.map((codeObject) => {
return getUserNameFromCodeBaseFile(
`${process.env.CODE_SRC}/${codeObject.path}`
`${process.env.CODE_SRC}/${codeObject.path}`,
)
})

Expand All @@ -77,7 +74,7 @@ const callGithubCodeBaseAPI = () => {
fileObject.value.fileName,
fileObject.value.username,
]
})
}),
)

const dataToInsert = res.data.map((data) => {
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/Vercel Deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
node-version: '20.x'
- run: yarn install
- run: yarn run test
env:
Expand All @@ -25,8 +25,8 @@ jobs:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: amondnet/vercel-action@v20
- uses: actions/checkout@v4
- uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required
vercel-args: '--prod' #Optional
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/Vercel Dev Deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
node-version: '20.x'
- run: yarn install
- run: yarn run test
env:
Expand All @@ -25,8 +25,8 @@ jobs:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: amondnet/vercel-action@v20
- uses: actions/checkout@v4
- uses: amondnet/vercel-action@v25
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }} # Required
vercel-org-id: ${{ secrets.ORG_ID}} #Required
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codebase-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ jobs:
init-setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
node-version: '20.x'
- run: yarn install
- run: bash .github/job.sh
env:
Expand Down
6 changes: 4 additions & 2 deletions api/public/assets/main.bundle.js

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions api/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<meta name="description" content="Engine to handle the rating mechanisms for the clean code">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="assets/bootstrap.min.css?v=1697340676180" rel="stylesheet" media="screen">
<link href="assets/prism.css?v=1697340676180" rel="stylesheet" />
<link href="assets/prism-toolbar.css?v=1697340676180" rel="stylesheet" />
<link href="assets/prism-diff-highlight.css?v=1697340676180" rel="stylesheet" />
<link href="assets/main.css?v=1697340676180" rel="stylesheet" media="screen, print">
<link href="assets/favicon.ico?v=1697340676180" rel="icon" type="image/x-icon">
<link href="assets/apple-touch-icon.png?v=1697340676180" rel="apple-touch-icon" sizes="180x180">
<link href="assets/favicon-32x32.png?v=1697340676180" rel="icon" type="image/png" sizes="32x32">
<link href="assets/favicon-16x16.png?v=1697340676180" rel="icon" type="image/png" sizes="16x16">
<link href="assets/bootstrap.min.css?v=1727848448632" rel="stylesheet" media="screen">
<link href="assets/prism.css?v=1727848448632" rel="stylesheet" />
<link href="assets/prism-toolbar.css?v=1727848448632" rel="stylesheet" />
<link href="assets/prism-diff-highlight.css?v=1727848448632" rel="stylesheet" />
<link href="assets/main.css?v=1727848448632" rel="stylesheet" media="screen, print">
<link href="assets/favicon.ico?v=1727848448632" rel="icon" type="image/x-icon">
<link href="assets/apple-touch-icon.png?v=1727848448632" rel="apple-touch-icon" sizes="180x180">
<link href="assets/favicon-32x32.png?v=1727848448632" rel="icon" type="image/png" sizes="32x32">
<link href="assets/favicon-16x16.png?v=1727848448632" rel="icon" type="image/png" sizes="16x16">
</head>

<body class="container-fluid">
Expand Down Expand Up @@ -1042,6 +1042,6 @@ <h2>{{__ "Request Body"}}</h2>
</div>
</div>

<script src="assets/main.bundle.js?v=1697340676180"></script>
<script src="assets/main.bundle.js?v=1727848448632"></script>
</body>
</html>
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "coderatingengine",
"version": "1.0.0",
"version": "1.20.0",
"engines": {
"node": "18.x",
"node": "20.x",
"yarn": "1.x"
},
"description": "Engine to handle the rating mechanisms for the clean code",
Expand All @@ -17,22 +17,22 @@
"author": "Gaurav Walia",
"license": "ISC",
"dependencies": {
"axios": "^1.5.1",
"axios": "^1.7.7",
"cors": "^2.8.5",
"express": "^4.18.2",
"express-rate-limit": "^7.1.1",
"mongoose": "^7.6.2",
"uuid": "^9.0.1"
"express": "^4.21.0",
"express-rate-limit": "^7.4.0",
"mongoose": "^8.7.0",
"uuid": "^10.0.0"
},
"devDependencies": {
"apidoc": "^1.2.0",
"dotenv": "^16.3.1",
"husky": "^8.0.3",
"lint-staged": "^14.0.1",
"mocha": "^10.2.0",
"nodemon": "^3.0.1",
"mocha": "^10.7.3",
"nodemon": "^3.1.7",
"prettier": "^3.0.3",
"supertest": "^6.3.3"
"supertest": "^7.0.0"
},
"lint-staged": {
"*.js": "prettier --write"
Expand Down
7 changes: 6 additions & 1 deletion routes/api/v1/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,12 @@ router.put(
* @apiName searchUser
* @apiDescription search and return the code rating for the specific user
* @apiVersion 1.0.0
* @apiBody {String} codeRatingEngineToken Access token received from randomCodes request
* @apiHeader {String} authorization Access token received from randomCodes request
* @apiHeaderExample {json} Request Header example
* {
* "Authorization": "Bearer <ACCESS_TOKEN>"
* }
*
* @apiQuery {String} username Username to search
* @apiQuery {Boolean} sendContent Whether content is needed from the API or not
*
Expand Down
19 changes: 11 additions & 8 deletions src/auth.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
const {validateToken} = require('./engine')

async function authenticateAPI(req, res, next) {
const {codeRatingEngineToken} = req.body
const {authorization} = req.headers

if (codeRatingEngineToken === undefined) {
return res.status(401).json({
status: 401,
message: 'Invalid Token !! Please send the valid token',
})
} else {
if (authorization && authorization.startsWith('Bearer ')) {
const codeRatingEngineToken = authorization.replace('Bearer ', '')
const tokenFound = await validateToken(codeRatingEngineToken)
if (Array.isArray(tokenFound) && tokenFound.length > 0) {
next()
} else {
return res.status(401).json({
status: 401,
message: 'Invalid Token !! Please send the valid token',
message:
'Invalid Authorization Token !! Please send the valid token',
})
}
} else {
return res.status(401).json({
status: 401,
message:
'Invalid Authorization Token !! Please send the valid token',
})
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ const accessTokenModel = require('../models/accessToken')
const {default: axios} = require('axios')
const {v4: uuidv4} = require('uuid')

mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
mongoose.connect(process.env.MONGODB_URI)
const db = mongoose.connection
db.on('error', console.error.bind(console, 'Connection error:'))

Expand Down
Loading

0 comments on commit e3e94d2

Please sign in to comment.