Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix-#3: refactored-backend-with-typescript #408

Conversation

vamsidhar-914
Copy link
Contributor

Summary

refactored backend with typescript

Description

migrated all js files to ts files with all the types.

Issue(s) Addressed

Closes #3

Prerequisites

Copy link

vercel bot commented Jun 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wanderlust ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 8, 2024 2:14pm
wanderlust-backend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 8, 2024 2:14pm

Copy link

github-actions bot commented Jun 7, 2024

Hey @vamsidhar-914! Thanks for sticking to the guidelines! High five! 🙌🏻

@vamsidhar-914
Copy link
Contributor Author

@krishnaacharyaa
check it out....tell me if any mistakes to be taken care of..

for tests I might need some help.I didnt touched tests for refactoring

Copy link
Owner

@krishnaacharyaa krishnaacharyaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @vamsidhar-914 appreciate the efforts, kindly don't make any changes to the codebase, just the refactoring part to the ts and don't remove the codes or comment if you get errors, kindly address all the reviews :)

fullName: string;
email: string;
password: string;
avatar?: string;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give here password string | undefined, so that it will let you define undefined

import mongoose from 'mongoose';

export interface IUser extends Document {
_id: string;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use types instead of interface and remove the I prefix in the naming


user.refreshToken = refreshToken;

await user.save();
user.password = undefined;
// user.password = undefined;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the password field nullable in the type, so that you don't have to comment it for the ts error

@@ -95,7 +104,6 @@ export const signInWithEmailOrUsername = asyncHandler(async (req, res) => {

user.refreshToken = refreshToken;
await user.save();
user.password = undefined;

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, get it back

@@ -164,12 +178,6 @@ export const isLoggedIn = asyncHandler(async (req, res) => {
console.log(error);
}
}
const user = await User.findById(_id);
if (!user) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have we tottally removed this? please don't remove some functionality just because it is giving error XD

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not remove d but declared on above

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name of the file post-type

import { IUser } from './user-Type';

export interface IPost extends Document {
_id?: string;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it type and why does it extend Document? who is document and rename we don't need I prefix

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name

import { Request } from 'express';

interface RequestUserType {
_id: string;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convert to type

}

export interface RequestWithUserRole extends Request {
user?: RequestUserType;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need this? Can't we directly use the above ? make it both to type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in middleware req.user , user is not found in Request type...extended the Request Type added user filed

@vamsidhar-914
Copy link
Contributor Author

hi @krishnaacharyaa

1.) when i use default Request type for req. it throws me error req.user is not found.so i declared index.d.ts file extended Request type with user field. but again it throws me the same error

Screenshot (218)

so i created a new type for Request and replaced it with that type , and it works fine
Screenshot (219)

2.) when i use the type 'module' in package.json it throws this error,
Screenshot (215)

these are the errors

@krishnaacharyaa
Copy link
Owner

@vamsidhar-914 please google these, it will be available.

  1. might be because Request is a wrong import
  2. because you have to change the tsconfig.json even, we can't change it from module to commonjs, no going back.

And the request type as discussed would not be actually required, try to come up with alternative

@krishnaacharyaa
Copy link
Owner

@vamsidhar-914 Hi, Are we good or blocked?
Let's have a call and get this in, It is a important feature we need this in, early it is, better it is :)

@vamsidhar-914
Copy link
Contributor Author

@krishnaacharyaa sorry! been busy lately.....everything is done except for the type module issue...searched google but couldn't find it.

@krishnaacharyaa
Copy link
Owner

No worries can we arrange a call we'll debug

@vamsidhar-914
Copy link
Contributor Author

can we connect tomorrow morning?

@krishnaacharyaa
Copy link
Owner

Nights or sat Sun
I have office other times

@vamsidhar-914
Copy link
Contributor Author

sure....lets connect on sunday

@krishnaacharyaa
Copy link
Owner

@vamsidhar-914 the earlier we get this, better it is :)
Now we have conflicts, it will increase as the time progresses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactoring backend using typescript
2 participants