Skip to content

Commit 2d39cb0

Browse files
authored
refactor!: changed case conventions in database (#169)
1 parent 0baad95 commit 2d39cb0

File tree

6 files changed

+217
-237
lines changed

6 files changed

+217
-237
lines changed

bin/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ mongoose.connect(process.env.DB_URI as string, () => {
2525
email,
2626
verified: true,
2727
password,
28-
acceptedTermsAndConditions: true,
29-
receiveMarketingEmails: true,
28+
accepted_terms_and_conditions: true,
29+
receive_marketing_emails: true,
3030
})
3131
.then(() => {
3232
console.log("✔ Admin created successfully");

src/controllers/auth.controller.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export const signupHandler = async (req: Request<{}, {}, SignupSchema["body"]>,
5151
password,
5252
role: "user",
5353
verified: false,
54-
receiveMarketingEmails,
55-
acceptedTermsAndConditions,
54+
receive_marketing_emails: receiveMarketingEmails,
55+
accepted_terms_and_conditions: acceptedTermsAndConditions,
5656
});
5757

5858
const token = await signAccessTokenService(createdUser);
@@ -63,10 +63,10 @@ export const signupHandler = async (req: Request<{}, {}, SignupSchema["body"]>,
6363
`<h2>Welcome to Multi Email</h2>
6464
<h4>please visit this URL and enter your OTP</h4>
6565
<p>
66-
OTP: ${createdUser.verificationCode}
66+
OTP: ${createdUser.verification_code}
6767
</p>
6868
<p>
69-
<a href="${process.env.FRONTEND_URL}/verify?v=${createdUser.verificationCode}&t=${token}">Verify My Account</a>
69+
<a href="${process.env.FRONTEND_URL}/verify?v=${createdUser.verification_code}&t=${token}">Verify My Account</a>
7070
</p>
7171
`,
7272
);
@@ -336,7 +336,7 @@ export const forgotPasswordHandler = async (
336336

337337
// generate password reset code and send that to users email
338338
const passwordResetCode = generateRandomOTP();
339-
user.passwordResetCode = passwordResetCode;
339+
user.password_reset_code = passwordResetCode;
340340

341341
/**
342342
* @author is-it-ayush
@@ -394,13 +394,16 @@ export const resetPasswordHandler = async (
394394
});
395395
}
396396

397-
if (!user?.passwordResetCode || user?.passwordResetCode !== parseInt(passwordResetCode)) {
397+
if (
398+
!user?.password_reset_code ||
399+
user?.password_reset_code !== parseInt(passwordResetCode)
400+
) {
398401
return res.status(StatusCodes.FORBIDDEN).json({
399402
error: "Invalid password reset code",
400403
});
401404
}
402405

403-
user.passwordResetCode = null;
406+
user.password_reset_code = null;
404407

405408
// NOTE: password will be hashed in user model
406409
user.password = password;

src/controllers/marketingEmail.controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const createMarketingEmailHandler = async (
4040
* Send email to all the users those have selected the checkbox
4141
*/
4242
if (allUsers) {
43-
const users = await findUsersService({ receiveMarketingEmails: true });
43+
const users = await findUsersService({ receive_marketing_emails: true });
4444

4545
if (!users) {
4646
return res.status(StatusCodes.NOT_FOUND).json({
@@ -72,13 +72,13 @@ export const createMarketingEmailHandler = async (
7272
users.forEach(
7373
async (user) =>
7474
user &&
75-
user.receiveMarketingEmails &&
75+
user.receive_marketing_emails &&
7676
(await sendEmail(user.email, subject, html)),
7777
);
7878

7979
await createMarketingEmailService({
8080
subject,
81-
users: users.map((user) => user && user.receiveMarketingEmails && user._id),
81+
users: users.map((user) => user && user.receive_marketing_emails && user._id),
8282
});
8383

8484
return res.status(StatusCodes.OK).json({

src/models/user.model.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { genSalt, hash, compare } from "bcrypt";
22
import { pre, prop, index, getModelForClass, Severity } from "@typegoose/typegoose";
33
import { generateRandomOTP } from "../utils/otp.util";
44

5-
export const userModalPrivateFields = ["password", "__v", "verificationCode", "passwordResetCode"];
5+
export const userModalPrivateFields = [
6+
"password",
7+
"__v",
8+
"verification_code",
9+
"password_reset_code",
10+
"connected_services",
11+
];
612

713
export class ConnectedServices {
814
@prop()
@@ -48,16 +54,16 @@ export class User {
4854
public verified: boolean;
4955

5056
@prop({ required: true, default: () => generateRandomOTP() })
51-
public verificationCode: number;
57+
public verification_code: number;
5258

5359
@prop()
54-
public passwordResetCode: number | null;
60+
public password_reset_code: number | null;
5561

5662
@prop({ required: true })
57-
public acceptedTermsAndConditions: boolean;
63+
public accepted_terms_and_conditions: boolean;
5864

5965
@prop({ required: true, default: false })
60-
public receiveMarketingEmails: boolean;
66+
public receive_marketing_emails: boolean;
6167

6268
@prop()
6369
public connected_services: [ConnectedServices];

src/services/user.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ export function createUserService(
6262
Omit<
6363
User,
6464
| "uid"
65-
| "verificationCode"
66-
| "passwordResetCode"
65+
| "verification_code"
66+
| "password_reset_code"
6767
| "comparePassword"
6868
| "connected_services"
6969
>

0 commit comments

Comments
 (0)