Skip to content

feat: Migrate Session.controller.js to typescript #3958

Open
Piyushrathoree wants to merge 4 commits intoprocessing:developfrom
Piyushrathoree:ts/migrate-session-controller
Open

feat: Migrate Session.controller.js to typescript #3958
Piyushrathoree wants to merge 4 commits intoprocessing:developfrom
Piyushrathoree:ts/migrate-session-controller

Conversation

@Piyushrathoree
Copy link

Fixes #3957

Changes:

  • Migrated server/controllers/session.controller.js to exactly matching TS file.
  • Created CreateSessionRequestBody, CreateSessionResponseBody, GetSessionResponseBody, and DestroySessionResponseBody types in server/types/session.ts.
  • Installed @types/express-session as a devDependency to allow the global Express Request object to understand req.session.destroy().

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • has no typecheck errors (npm run typecheck)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123
  • meets the standards outlined in the accessibility guidelines

Copy link
Contributor

Choose a reason for hiding this comment

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

This file does not need to be committed. Please exclude it from the commit.

next(innerErr);
return;
}
res.json(userResponse(req.user!));
Copy link
Contributor

Choose a reason for hiding this comment

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

A safer approach for this is res.json(userResponse(user));

Copy link
Author

Choose a reason for hiding this comment

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

sure

{},
CreateSessionResponseBody,
CreateSessionRequestBody
> = (req: Request, res: Response, next: NextFunction) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since RequestHandler<> is already used for typing, explicit Request, Response, and NextFunction annotations can be removed for cleaner code.

Copy link
Author

Choose a reason for hiding this comment

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

okay make sense

@Piyushrathoree Piyushrathoree force-pushed the ts/migrate-session-controller branch from d76fec9 to 1c59e8d Compare March 4, 2026 13:56
- Add RequestHandler generics and JSDoc to session controller
- Add server/types/session.ts with request/response types
- Update server/types barrel to export session types
@Piyushrathoree Piyushrathoree force-pushed the ts/migrate-session-controller branch from 1c59e8d to 230bc07 Compare March 4, 2026 14:05
@Piyushrathoree
Copy link
Author

@yugalkaushik made changes

@@ -0,0 +1,15 @@
import { PublicUser, GenericResponseBody } from '.';
Copy link
Collaborator

Choose a reason for hiding this comment

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

this creates a circular dependency, please update to import from the correct source files

| PublicUser
| { message: string };

export type DestroySessionResponseBody = { success: boolean };
Copy link
Collaborator

Choose a reason for hiding this comment

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

there's already GenericResponseBody, I would either Pick from that, or just omit this change and use GenericResponseBody instead

next(innerErr);
return;
}
res.json(userResponse(user));
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you change this back to userResponse(req.user)? There are no tests for the controller yet, so it would be safer not to change this

@clairep94 clairep94 self-assigned this Mar 7, 2026
Copy link
Collaborator

@clairep94 clairep94 left a comment

Choose a reason for hiding this comment

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

sorry misclicked when I hit approve, if you could amend per the feedback that would be great!

@clairep94 clairep94 added the Contributor Follow-up Required Request for changes, or other follow up required. Please see PR comments thread. label Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Contributor Follow-up Required Request for changes, or other follow up required. Please see PR comments thread.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript Migration: session.controller.js

3 participants