Skip to content

Commit

Permalink
Feature: user account endpoint (#2)
Browse files Browse the repository at this point in the history
* User account endpoint

* Update deploy script
  • Loading branch information
moiskillnadne authored Sep 29, 2024
1 parent c28a0c7 commit e56784d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ jobs:
corepack enable
yarn install --frozen-lockfile
yarn build
yarn db:migrate
pm2 restart /root/apps/challenge-logger/ecosystem.config.js
12 changes: 10 additions & 2 deletions src/api/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ const route = express.Router();

route.use(authMiddleware);

route.get('/test', (req: Request, res: Response) => {
route.get('/', (req: Request, res: Response) => {
const user = (req as AuthorizedRequest).user;

res.status(200).send({ message: `Hello, ${user.email}` });
return res.status(200).json({
type: 'USER_FETCHED',
statusCode: 200,
message: 'User fetched successfully',
isSuccess: true,
details: {
user,
},
});
});

export default route;
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ app.get('/healthcheck', (req: Request, res: Response) => {
return res.status(200).send('OK');
});

app.all('*', (req: Request, res: Response) => {
return res.status(404).json({
error: true,
message: 'Endpoint not found.',
});
});

app.listen(PORT, async () => {
console.info(`Server is running on port ${PORT}`);

Expand Down

0 comments on commit e56784d

Please sign in to comment.