Skip to content

Commit ba5f7a8

Browse files
committed
configure eslint, prettier with pre-commit
1 parent eedb179 commit ba5f7a8

File tree

19 files changed

+1752
-487
lines changed

19 files changed

+1752
-487
lines changed

.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
build
3+
*.d.ts
4+
*playground*
5+
**/Modal/*

.eslintrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
7+
"overrides": [],
8+
"parser": "@typescript-eslint/parser",
9+
"parserOptions": {
10+
"ecmaVersion": "latest",
11+
"sourceType": "module"
12+
},
13+
"plugins": ["@typescript-eslint"],
14+
"rules": {
15+
"@typescript-eslint/no-explicit-any": "warn",
16+
"@typescript-eslint/no-unused-vars": "warn"
17+
}
18+
}

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4+
npx lint-staged

.prettierignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

22
README.md
33
package*.json
4-
tsconfig.json
4+
tsconfig.json
5+
.*ignore
6+
.husky
7+
node_modules
8+
build

@types/index.d.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,9 @@ declare global {
2929
}
3030

3131
export type MiddleWare = (
32-
req: Request<
33-
ParamsDictionary,
34-
any,
35-
any,
36-
QueryString.ParsedQs,
37-
Record<string, any>
38-
>,
32+
req: Request<ParamsDictionary, any, any, QueryString.ParsedQs, Record<string, any>>,
3933
res: Response<any>,
40-
next: NextFunction
34+
next: NextFunction,
4135
) => void;
4236

4337
export type RequestHandler = (req: Request, res: Response) => void;

API/Authenticated/endpoint_handler.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import { RequestHandler } from "../../@types";
1515

1616
const userProfileData: RequestHandler = async (req, res) => {
1717
try {
18-
if (!req.userId)
19-
return res.status(401).send(ErrorResponse({ message: "Unauthorized" }));
18+
if (!req.userId) return res.status(401).send(ErrorResponse({ message: "Unauthorized" }));
2019
const profileData = await getProfileById(req.userId, true);
2120
res.send(SuccessResponse({ data: profileData }));
2221
} catch (e) {
@@ -33,13 +32,11 @@ const userNameChecker: RequestHandler = (req, res) => {
3332
res.send(
3433
SuccessResponse({
3534
data: { available: availability },
36-
})
35+
}),
3736
);
3837
});
3938
} else {
40-
res
41-
.status(400)
42-
.send(ErrorResponse({ message: "Invalid username check request" }));
39+
res.status(400).send(ErrorResponse({ message: "Invalid username check request" }));
4340
}
4441
} catch (e) {
4542
console.log("FailedUsernameCheck:", e);
@@ -106,7 +103,7 @@ const userSearchHandler: RequestHandler = async (req, res) => {
106103
res.send(
107104
SuccessResponse({
108105
data: { users, hasData: users.length > 0, groups: [] },
109-
})
106+
}),
110107
);
111108
} catch (e) {
112109
console.log(e);
@@ -115,8 +112,7 @@ const userSearchHandler: RequestHandler = async (req, res) => {
115112
};
116113

117114
const imageHandler: RequestHandler = async (req, res) => {
118-
if (!req.userId)
119-
return res.status(401).send(ErrorResponse({ message: "Unauthorized" }));
115+
if (!req.userId) return res.status(401).send(ErrorResponse({ message: "Unauthorized" }));
120116
const imageBlob = req.body;
121117
if (!imageBlob) {
122118
res.status(400).send(ErrorResponse({ message: "Image not provided!" }));
@@ -132,8 +128,7 @@ const registerUser: RequestHandler = async (req, res) => {
132128
try {
133129
console.log(Object.keys(req.body).length);
134130
if (Object.keys(req.body).length === 6) {
135-
const { about, usernameSelected, firstName, lastName, email, password } =
136-
req.body;
131+
const { about, usernameSelected, firstName, lastName, email, password } = req.body;
137132
const usernameAvailable = await isUsernameAvailable(usernameSelected);
138133
if (usernameAvailable && email === req.emailAddress) {
139134
const user = await createNewAccount({
@@ -156,13 +151,4 @@ const registerUser: RequestHandler = async (req, res) => {
156151
}
157152
};
158153

159-
export {
160-
userProfileData,
161-
userNameChecker,
162-
imageHandler,
163-
registerUser,
164-
userSearchHandler,
165-
blockedUsersRequestHandler,
166-
blockHandler,
167-
unblockHandler,
168-
};
154+
export { userProfileData, userNameChecker, imageHandler, registerUser, userSearchHandler, blockedUsersRequestHandler, blockHandler, unblockHandler };

API/endpoint_handler.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,19 @@ import { RequestHandler } from "../@types";
1010
const loginAuthentication: RequestHandler = async (req, res) => {
1111
const { username, password } = req.body;
1212
if (username && password) {
13-
const { userExists, credentialsMatch, userId } = await verifyUser(
14-
username,
15-
password
16-
);
17-
if (!userExists)
18-
res.send(ErrorResponse({ message: "User does not exists!" }));
19-
else if (!credentialsMatch)
20-
res.send(
21-
ErrorResponse({ message: "Username or Password is not correct!" })
22-
);
13+
const { userExists, credentialsMatch, userId } = await verifyUser(username, password);
14+
if (!userExists) res.send(ErrorResponse({ message: "User does not exists!" }));
15+
else if (!credentialsMatch) res.send(ErrorResponse({ message: "Username or Password is not correct!" }));
2316
else {
24-
let token = await generateLoginToken(userId.toString());
17+
const token = await generateLoginToken(userId.toString());
2518
if (token) {
2619
res.send(SuccessResponse({ data: token }));
2720
} else {
2821
res.send(ErrorResponse({ message: "Cannot login!" }));
2922
}
3023
}
3124
} else {
32-
res
33-
.status(400)
34-
.json(ErrorResponse({ message: "Invalid credentials input" }));
25+
res.status(400).json(ErrorResponse({ message: "Invalid credentials input" }));
3526
}
3627
};
3728

@@ -46,9 +37,7 @@ const emailValidation: RequestHandler = async (req, res) => {
4637
res.send(ErrorResponse({ message: "Invalid Email" }));
4738
return;
4839
}
49-
const emailAlreadyRegistered = await isEmailAlreadyRegistered(
50-
emailAddress
51-
);
40+
const emailAlreadyRegistered = await isEmailAlreadyRegistered(emailAddress);
5241
if (!emailAlreadyRegistered) {
5342
const OTPCreated = await provideOTPAuth(emailAddress, resend, req.ip);
5443
if (OTPCreated.created || OTPCreated.exists) {
@@ -65,16 +54,14 @@ const emailValidation: RequestHandler = async (req, res) => {
6554
res.send(
6655
SuccessResponse({
6756
data: generateNewToken({ emailAddress }, "signup"),
68-
})
57+
}),
6958
);
7059
} else {
7160
res.send(ErrorResponse({ message: "Unverified" }));
7261
}
7362
}
7463
} catch (e) {
75-
res
76-
.status(500)
77-
.send(ErrorResponse({ message: "Something went wrong to us!" }));
64+
res.status(500).send(ErrorResponse({ message: "Something went wrong to us!" }));
7865
console.error("FailedEmailAuthentication:", e);
7966
}
8067
};
@@ -97,7 +84,7 @@ const oAuthHandler: RequestHandler = async (req, res) => {
9784
SuccessResponse({
9885
data: await generateLoginToken(registeredUser.toString()),
9986
message: "login",
100-
})
87+
}),
10188
);
10289
} else {
10390
res.send(
@@ -107,12 +94,10 @@ const oAuthHandler: RequestHandler = async (req, res) => {
10794
firstName: payload.given_name,
10895
lastName: payload.family_name,
10996
email: payload.email,
110-
token: payload.email_verified
111-
? generateNewToken({ emailAddress: payload.email }, "signup")
112-
: null,
97+
token: payload.email_verified ? generateNewToken({ emailAddress: payload.email }, "signup") : null,
11398
},
11499
message: "signup",
115-
})
100+
}),
116101
);
117102
}
118103
} catch (e) {

API/middleware.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ const tokenAuthority: MiddleWare = async (req, res, next) => {
1313
}
1414
} catch (e) {
1515
res.send(500);
16-
} finally {
17-
return;
1816
}
17+
return;
1918
}
2019

2120
validateToken(authToken, "login")
@@ -24,7 +23,7 @@ const tokenAuthority: MiddleWare = async (req, res, next) => {
2423
next();
2524
})
2625
.catch((r) => {
27-
res.sendStatus(401);
26+
res.status(401).send(r);
2827
});
2928
} else {
3029
res.sendStatus(401);

CloudFlare_Helper/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const uploadProfileImage = async (user_Id: string, blob: Blob) => {
2323
Key,
2424
Body: blob,
2525
ContentType: "image/png",
26-
})
26+
}),
2727
);
2828
return Key;
2929
};
@@ -43,7 +43,7 @@ const getPostSignedURL = async (path: string, key: string, size: number) => {
4343
}),
4444
{
4545
expiresIn: 600,
46-
}
46+
},
4747
);
4848
};
4949

MongoDB_Helper/Modal/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ts-nocheck
1+
// @ts-nocheck
22
import { Schema, model } from "mongoose";
33

44
const Profile = model(
@@ -18,7 +18,7 @@ const Profile = model(
1818
profile_type: String,
1919
username: String,
2020
status: "ONLINE" | "OFFLINE",
21-
})
21+
}),
2222
);
2323

2424
const Chat = model(
@@ -30,7 +30,7 @@ const Chat = model(
3030
created_by: String,
3131
messages: Array,
3232
participants: Array,
33-
})
33+
}),
3434
);
3535

3636
export { Profile, Chat };

0 commit comments

Comments
 (0)