Skip to content

Commit

Permalink
Merge pull request #49 from kolya-mazurok2/release/0.1.6
Browse files Browse the repository at this point in the history
Release/0.1.6
  • Loading branch information
kolya-mazurok2 committed Aug 13, 2022
2 parents 65d15a1 + abf1726 commit 121ffcd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/config/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'reflect-metadata';
import { DataSource } from 'typeorm';
import { City } from '../entities/city';
import { Forecast } from '../entities/forecast';
import { User } from '../entities/user';

interface PostgresConfig {
host: string;
Expand Down Expand Up @@ -32,7 +33,7 @@ export const dataSource = new DataSource({
type: 'postgres',
synchronize: true,
logging: false,
entities: [City, Forecast],
entities: [City, Forecast, User],
subscribers: [],
...postgresConfig,
});
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express, { Application } from 'express';
import express, { Application, NextFunction, Request, Response } from 'express';
import morgan from 'morgan';
import { dataSource } from './config/database';
import router from './routes';
Expand All @@ -15,7 +15,9 @@ app.use(morgan('tiny'));

app.use(router);

app.use(apiErrorMiddleware);
app.use((err: Error, req: Request, res: Response, _: NextFunction) =>
apiErrorMiddleware(err, req, res)
);

(async () => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/api-error.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const apiErrorMiddleware = (err: Error, req: Request, res: Response) => {
if (err instanceof ApiError) {
return res.status(err.status).send({ message: err.message });
}
console.log(res);

return res.status(500).send({ message: errorMessages[500] });
};

Expand Down
11 changes: 10 additions & 1 deletion src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import { Router } from 'express';
import { Request, Response, Router } from 'express';
import { errorMessages } from '../errors/constants';
import cityRouter from './city.router';
import forecastRouter from './forecast.router';
import userRouter from './user.router';

const router = Router();

router.get('/ping', (_: Request, res: Response) =>
res.send({
message: 'pong',
})
);
router.use('', userRouter);
router.use('/cities', cityRouter);
router.use('/forecasts', forecastRouter);
router.get('*', (_: Request, res: Response) =>
res.status(404).send({ message: errorMessages[404] })
);

export default router;
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Secret } from 'jsonwebtoken';

require('dotenv').config();

export const JWT_SECRET_KEY: Secret = process.env.JWT_SECRET_KEY || '';

0 comments on commit 121ffcd

Please sign in to comment.