-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yash Kasera
committed
Jul 31, 2022
1 parent
d8183d0
commit 29c4d0f
Showing
16 changed files
with
1,702 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "backend", | ||
"version": "1.0.0", | ||
"main": "src/index.js", | ||
"repository": "https://github.com/yashkasera/Urban-Thrift.git", | ||
"author": "yashkasera", | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "node src/index.js", | ||
"dev": "nodemon src/index.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"dependencies": { | ||
"dotenv": "^16.0.1", | ||
"express": "^4.18.1" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^2.0.19" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require('dotenv').config(); | ||
const express = require('express'); | ||
const {NotFoundError} = require("./util/error"); | ||
const router = require("./routes"); | ||
const errorController = require("./controller/errorController"); | ||
const app = express(); | ||
app.use(express.json()); | ||
|
||
app.use('/api/v1', router); | ||
|
||
app.all('*', (req, res) => { | ||
errorController(new NotFoundError(), req, res); | ||
}); | ||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const errorController = (err, req, res) => | ||
res.status(err.code || 400).send({ | ||
message: err.message || 'Something went wrong', | ||
name: err.name || 'Bad Request', | ||
code: err.code || 400, | ||
}); | ||
|
||
|
||
module.exports = errorController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const port = process.env.PORT || 3000; | ||
const app = require('./app'); | ||
|
||
app.listen(port, () => { | ||
console.log(`Listening on port ${port}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class User { | ||
constructor(name, alias, email, password, isVerified, phoneNumber, balance, token, createdAt) { | ||
this.name = name; | ||
this.alias = alias; | ||
this.email = email; | ||
this.password = password; | ||
this.isVerified = isVerified; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class NotFoundError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = 'NotFoundError'; | ||
this.code = 404; | ||
this.message = 'The resource you are looking for is not found.'; | ||
} | ||
} | ||
|
||
class BadRequestError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = 'BadRequestError'; | ||
this.code = 400; | ||
this.message = 'The request is invalid.'; | ||
} | ||
} | ||
|
||
class AuthenticationError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = 'AuthenticationError'; | ||
this.code = 401; | ||
this.message = message || 'You are not authorized to perform this action.'; | ||
} | ||
} | ||
|
||
class ForbiddenError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = 'ForbiddenError'; | ||
this.code = 403; | ||
this.message = 'You are not authorized to perform this action.'; | ||
} | ||
} | ||
|
||
|
||
|
||
module.exports = { | ||
NotFoundError, | ||
BadRequestError, | ||
AuthenticationError, | ||
ForbiddenError, | ||
} |
Oops, something went wrong.