Skip to content

Commit adc48c6

Browse files
committed
test
1 parent 4460ff0 commit adc48c6

31 files changed

Lines changed: 581 additions & 162 deletions

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
build

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This repository contains both the frontend and backend code in a single reposito
88
## Structure
99

1010
mysocialcode/
11+
1112
- frontend/ – Frontend application (Expo / React Native)
1213
- backend/ – Backend API (Node.js / Express)
1314

backend/eslint.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import js from "@eslint/js";
2+
import tseslint from "typescript-eslint";
3+
4+
export default [
5+
{
6+
ignores: ["dist/**", "build/**", "node_modules/**"],
7+
rules: {
8+
"@typescript-eslint/no-unused-vars": [
9+
"error",
10+
{ argsIgnorePattern: "^_" }
11+
],
12+
},
13+
},
14+
js.configs.recommended,
15+
...tseslint.configs.recommended,
16+
];

backend/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"scripts": {
55
"dev": "ts-node-dev --respawn --transpile-only src/server.ts",
66
"build": "tsc",
7-
"start": "node dist/server.js"
7+
"start": "node dist/server.js",
8+
"lint": "eslint"
89
},
910
"dependencies": {
1011
"dotenv": "^17.2.3",
@@ -16,10 +17,15 @@
1617
"typeorm": "^0.3.28"
1718
},
1819
"devDependencies": {
20+
"@eslint/js": "^9.39.2",
1921
"@types/express": "^5.0.6",
2022
"@types/node": "^25.0.3",
2123
"@types/pg": "^8.16.0",
24+
"@typescript-eslint/eslint-plugin": "^8.51.0",
25+
"@typescript-eslint/parser": "^8.51.0",
26+
"eslint": "^9.39.2",
2227
"ts-node-dev": "^2.0.0",
23-
"typescript": "~5.9.3"
28+
"typescript": "~5.9.3",
29+
"typescript-eslint": "^8.51.0"
2430
}
2531
}

backend/src/app.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
import express from 'express'
2-
import PinoHttp, { pinoHttp } from 'pino-http'
3-
import { logger } from './utils/logger'
4-
import { notFound } from './middleware/notFound'
5-
import { errorHandler } from './middleware/errorHandler'
6-
import Healthrouter from './routes/health'
7-
import pino from 'pino'
8-
const app = express()
9-
app.use(express.json())
1+
import express from 'express';
2+
import { pinoHttp } from 'pino-http';
3+
import { logger } from './utils/logger';
4+
import { notFound } from './middleware/notFound';
5+
import { errorHandler } from './middleware/errorHandler';
6+
import Healthrouter from './routes/health';
7+
const app = express();
8+
app.use(express.json());
109
app.use(
11-
pinoHttp({
12-
logger,
13-
autoLogging:{
14-
ignore:(req)=>req.url==='health'
15-
}
16-
})
17-
)
18-
app.use('/health',Healthrouter)
19-
app.use(notFound)
20-
app.use(errorHandler)
21-
export default app;
10+
pinoHttp({ logger, autoLogging: { ignore: (req) => req.url === 'health' } }),
11+
);
12+
app.use('/health', Healthrouter);
13+
app.use(notFound);
14+
app.use(errorHandler);
15+
export default app;

backend/src/data-source.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import "dotenv/config";
2-
import { DataSource } from "typeorm";
3-
import { User } from "./entities/User";
1+
import 'dotenv/config';
2+
import { DataSource } from 'typeorm';
3+
import { User } from './entities/User';
44
if (!process.env.DATABASE_URL) {
5-
throw new Error("DATABASE_URL is not defined");
5+
throw new Error('DATABASE_URL is not defined');
66
}
77
export const appDataSouce = new DataSource({
8-
type:"postgres",
9-
url:process.env.DATABASE_URL,
10-
ssl:{
11-
rejectUnauthorized:false,
12-
},
13-
entities:[User],
14-
synchronize:true,
15-
})
8+
type: 'postgres',
9+
url: process.env.DATABASE_URL,
10+
ssl: {
11+
rejectUnauthorized: false,
12+
},
13+
entities: [User],
14+
synchronize: true,
15+
});

backend/src/entities/User.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {Entity, PrimaryGeneratedColumn,Column} from 'typeorm'
1+
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
22
@Entity()
3-
export class User{
4-
@PrimaryGeneratedColumn()
5-
id!:number;
6-
@Column()
7-
phone!:string;
8-
}
3+
export class User {
4+
@PrimaryGeneratedColumn()
5+
id!: number;
6+
@Column()
7+
phone!: string;
8+
}
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
import { Request, Response, NextFunction } from "express";
1+
import { Request, Response, NextFunction } from 'express';
22

3-
export const errorHandler = (err: any,req: Request,res: Response,next: NextFunction
3+
export const errorHandler = (
4+
err: unknown,
5+
req: Request,
6+
res: Response,
7+
_next: NextFunction,
48
) => {
59
console.error(err);
610

7-
const statusCode = err.statusCode || 500;
11+
let message = 'Internal Server Error';
812

9-
res.status(statusCode).json({
10-
message: err.message || "Internal Server Error",
11-
});
13+
if (err instanceof Error) {
14+
message = err.message;
15+
}
16+
17+
res.status(500).json({ message });
1218
};

backend/src/middleware/notFound.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { Request, Response, NextFunction } from "express";
1+
import { Request, Response, NextFunction } from 'express';
22

3-
export const notFound = (req: Request,res: Response,next:NextFunction
4-
) => {
3+
export const notFound = (req: Request, res: Response, _next: NextFunction) => {
54
res.status(404).json({
6-
message: "Route not found",
5+
message: 'Route not found',
76
});
87
};

0 commit comments

Comments
 (0)