Skip to content

Commit 9d4a04e

Browse files
committed
formated all files to eslint standards
1 parent 3a933b0 commit 9d4a04e

25 files changed

+130
-125
lines changed

.eslintrc.cjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ module.exports = {
1717
quotes: ["error", "double"],
1818
"import/prefer-default-export": "off"
1919
},
20-
// TODO: setup import export path resolver
2120
"settings": {
2221
"import/resolver": {
2322
"alias": {

bin/www.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*/
66

77
import http from "http";
8-
import debug from "debug";//("api:server");
9-
import app, {logger} from "#app";
10-
import dotenv from "dotenv"
8+
import debug from "debug";// ("api:server");
9+
import dotenv from "dotenv";
10+
import app from "#app";
11+
import { logger } from "#util";
12+
1113
dotenv.config();
1214

1315
/**

constant.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const logLevel = {
2-
local: "silly",
3-
dev: "debug",
4-
prod: "info"
5-
}
2+
local: "silly",
3+
dev: "debug",
4+
prod: "info",
5+
};

controller/auth.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const otpStore = {};
55

66
async function login(req, res) {
77
const { id, password } = req.body;
8-
try{
8+
try {
99
const userValidated = await authenticateUser(id, password);
1010
const userDetails = {
1111
uid: userValidated.uid,
@@ -16,15 +16,13 @@ async function login(req, res) {
1616
const token = util.genrateToken(userDetails);
1717
userDetails.token = token;
1818
res.json({ res: "welcome", user: userDetails });
19-
}
20-
catch(error){
21-
if(error.name === "UserDoesNotExist"){
19+
} catch (error) {
20+
if (error.name === "UserDoesNotExist") {
2221
res.status(403);
23-
res.json({err: "Incorrect ID password"})
24-
}
25-
else{
22+
res.json({ err: "Incorrect ID password" });
23+
} else {
2624
res.status(500);
27-
res.json({err: "Something is wrong on our side. Try again"});
25+
res.json({ err: "Something is wrong on our side. Try again" });
2826
}
2927
}
3028
}
@@ -48,22 +46,19 @@ async function sendOTP(req, res) {
4846
async function resetPassword(req, res) {
4947
const { uid, otp, password } = req.body;
5048
if (otpStore[uid] === otp) {
51-
try{
49+
try {
5250
await updatePassword(uid, password);
5351
res.json({ res: "successfully updated password" });
54-
}
55-
catch(error){
52+
} catch (error) {
5653
res.status(500);
57-
if(error.name === "UpdateError")
58-
res.json({ err: "Something went wrong while updating password" });
59-
else
60-
res.json({err: "something went wrong"});
54+
if (error.name === "UpdateError") res.json({ err: "Something went wrong while updating password" });
55+
else res.json({ err: "something went wrong" });
6156
}
6257
} else {
6358
res.json({ err: "incorrect otp" });
6459
}
6560
}
6661

6762
export default {
68-
validateUser, sendOTP, resetPassword, login
63+
validateUser, sendOTP, resetPassword, login,
6964
};

controller/user.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
import user from "#models/user";
21
import { allUsers, createUser } from "#services/user";
32

43
async function addUser(req, res) {
54
const {
65
name, password, emailId, uid, userType,
76
} = req.body;
8-
try{
9-
let newUser = await createUser(name, password, emailId, uid, userType);
7+
try {
8+
const newUser = await createUser(name, password, emailId, uid, userType);
109
res.json({ res: `added user ${newUser.id}` });
11-
}
12-
catch(error){
10+
} catch (error) {
1311
res.json({ err: "Error while inserting in DB" });
14-
}
12+
}
1513
}
1614

17-
async function getAllUser(req, res){
15+
async function getAllUser(req, res) {
1816
const allUser = await allUsers();
19-
res.json({res: allUser});
20-
}
17+
res.json({ res: allUser });
18+
}
2119

2220
export default { addUser, getAllUser };

error/DataEntryError.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export class DataEntryError extends Error {
2+
constructor(modelName) {
3+
super(`Error while creating new entry in ${modelName}`);
4+
this.name = "DataEntryError";
5+
}
6+
}

error/DataNotFoundError.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export class DataNotFoundError extends Error {
2+
constructor(message) {
3+
super(message);
4+
this.name = "DataNotFound";
5+
}
6+
}

error/UpdateError.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export class UpdateError extends Error {
2+
constructor(modelName) {
3+
super(`unable to update ${modelName}`);
4+
this.name = "UpdateError";
5+
}
6+
}

error/UserDoesNotExist.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export class UserDoesNotExistError extends Error {
2+
constructor() {
3+
super("User Does not exist");
4+
this.name = "UserDoesNotExist";
5+
}
6+
}

error/database.js

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
1-
export class DataNotFound extends Error{
2-
constructor(message){
3-
super(message);
4-
this.name = "DataNotFound";
5-
}
6-
}
1+
import { DataEntryError } from "#error/DataEntryError";
2+
import { DataNotFoundError } from "#error/DataNotFoundError";
3+
import { UpdateError } from "#error/UpdateError";
4+
import { UserDoesNotExistError } from "#error/UserDoesNotExist";
75

8-
export class UserDoesNotExist extends Error{
9-
constructor(){
10-
super("User Does not exist");
11-
this.name = "UserDoesNotExist";
12-
}
13-
}
14-
15-
export class UpdateError extends Error{
16-
constructor(modelName){
17-
super(`unable to update ${modelName}`);
18-
this.name = "UpdateError";
19-
}
20-
}
21-
22-
export class DataEntryError extends Error{
23-
constructor(modelName){
24-
super(`Error while creating new entry in ${modelName}`);
25-
this.name = "DataEntryError";
26-
}
27-
}
6+
export default {
7+
DataEntryError, DataNotFoundError, UpdateError, UserDoesNotExistError,
8+
};

0 commit comments

Comments
 (0)