Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash Kasera committed Jul 31, 2022
1 parent d8183d0 commit 29c4d0f
Show file tree
Hide file tree
Showing 16 changed files with 1,702 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .idea/.gitignore

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

12 changes: 12 additions & 0 deletions .idea/Urban-Thrift.iml

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

8 changes: 8 additions & 0 deletions .idea/modules.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

20 changes: 20 additions & 0 deletions backend/package.json
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"
}
}
15 changes: 15 additions & 0 deletions backend/src/app.js
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;
9 changes: 9 additions & 0 deletions backend/src/controller/errorController.js
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;
6 changes: 6 additions & 0 deletions backend/src/index.js
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}`);
});
9 changes: 9 additions & 0 deletions backend/src/model/User.js
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;
}
}
4 changes: 4 additions & 0 deletions backend/src/routes/index.js
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;
44 changes: 44 additions & 0 deletions backend/src/util/error.js
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,
}
Loading

0 comments on commit 29c4d0f

Please sign in to comment.