Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
node_modules/
dist/
.env
build/
.env*
.env.*.local
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
.vscode/
.idea/
*.swp
*.swo
*~
coverage/
.nyc_output/
*.tmp
*.temp
project_code.txt
7 changes: 7 additions & 0 deletions ormconfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { DataSource } from 'typeorm';
import config from './src/config/config';

export default new DataSource({
...config.typeorm,
migrations: ['src/migrations/*.ts'],
});
99 changes: 94 additions & 5 deletions package-lock.json
100644 → 100755

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions package.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,30 @@
"scripts": {
"dev": "ts-node-dev --respawn src/server.ts",
"build": "tsc",
"start": "node dist/server.js"
"start": "node dist/server.js",
"typeorm": "typeorm-ts-node-commonjs -d ormconfig.ts",
"migration:generate": "npm run typeorm migration:generate",
"migration:run": "npm run typeorm migration:run",
"migration:revert": "npm run typeorm migration:revert"
},
"dependencies": {
"@map-colonies/error-types": "^1.3.1",
"config": "^3.3.12",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"pg": "^8.16.3",
"reflect-metadata": "^0.2.2",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1",
"typeorm": "^0.3.20"
"typeorm": "^0.3.20",
"zod": "^3.25.76"
},
"devDependencies": {
"@types/config": "^3.3.5",
"@types/express": "^4.17.21",
"@types/node": "^20.11.30",
"@types/node": "^20.19.22",
"@types/swagger-jsdoc": "^6.0.4",
"@types/swagger-ui-express": "^4.1.6",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"typescript": "^5.4.5"
Expand Down
11 changes: 5 additions & 6 deletions src/app.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import express from 'express';
import usersRouter from './routes/users';
import { errorHandler } from './middleware/errorHandler';

import userRoutes from './routes/userRoutes';
import { getErrorHandlerMiddleware } from '@map-colonies/error-express-handler';

const app = express();

app.use(express.json());
app.use(express.json());

app.use('/users', usersRouter);
app.use('/users', userRoutes);

app.use(errorHandler);
app.use(getErrorHandlerMiddleware());

export default app;
46 changes: 46 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import dotenv from 'dotenv';
import { DataSourceOptions } from 'typeorm';
import { User } from '../entity/User';

dotenv.config();

interface Config {
port: number;
nodeEnv: string;
database: {
host: string;
port: number;
name: string;
user: string;
password: string;
};
typeorm: DataSourceOptions;
}

const config: Config = {
port: parseInt(process.env.PORT || '3000', 10),
nodeEnv: process.env.NODE_ENV || 'development',
database: {
host: process.env.DB_HOST || 'localhost',
port: parseInt(process.env.DB_PORT || '5432', 10),
name: process.env.DB_NAME || 'myapp',
user: process.env.DB_USER || 'postgres',
password: process.env.DB_PASSWORD || '',
},
typeorm: {
type: 'postgres',
host: process.env.DB_HOST || 'localhost',
port: parseInt(process.env.DB_PORT || '5432', 10),
username: process.env.DB_USER || 'postgres',
password: process.env.DB_PASSWORD || '',
database: process.env.DB_NAME || 'myapp',
synchronize: false,
logging: process.env.NODE_ENV === 'development',
entities: [User],
migrations: ['src/migrations/*.ts'],
migrationsTableName: 'migrations',
migrationsRun: false,
},
};

export default config;
Copy link

Choose a reason for hiding this comment

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

add eslint - will prevent EOFs errors if you run it before pushing to branch.
it repeats everywhere so i stop commenting for it

6 changes: 6 additions & 0 deletions src/config/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DataSource } from 'typeorm';
import config from './config';

export const AppDataSource = new DataSource(config.typeorm);

export default AppDataSource;
14 changes: 14 additions & 0 deletions src/constants/HttpStatusCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export {
OK,
CREATED,
NO_CONTENT,
BAD_REQUEST,
UNAUTHORIZED,
FORBIDDEN,
NOT_FOUND,
CONFLICT,
INTERNAL_SERVER_ERROR,
SERVICE_UNAVAILABLE,
type StatusCodes as HttpStatusCode
} from 'http-status-codes';

Loading