Skip to content

Commit 2e8ff89

Browse files
committed
Improve linter on typescript-backend
1 parent cd3c12c commit 2e8ff89

21 files changed

+364
-411
lines changed

backend-javascript/.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PORT=3000
99
CORS_ORIGIN=http://localhost:3000
1010

1111
# === BASE DE DONNEES ===
12-
DB_CLIENT=mysql # pg | mysql | mock
12+
DB_CLIENT=mock # pg | mysql | mock
1313

1414
# === AUTHENTIFICATION MOCK ===
1515
FAKE_USER_NAME=editor_user

backend-typescript/.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PORT=3001
99
CORS_ORIGIN=http://localhost:3001
1010

1111
# === BASE DE DONNEES ===
12-
DB_CLIENT=mysql # pg | mysql | mock
12+
DB_CLIENT=mock # pg | mysql | mock
1313

1414
# === AUTHENTIFICATION MOCK ===
1515
FAKE_USER_NAME=editor_user

backend-typescript/src/core/database/clients/mysql/native.client.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,3 @@ const pool: Pool = mysql.createPool({
1515
});
1616

1717
export default pool;
18-
19-
20-
// import mysql from 'mysql2/promise';
21-
// import dotenv from 'dotenv';
22-
23-
// dotenv.config();
24-
25-
// const pool = mysql.createPool({
26-
// host: process.env.DB_MYSQL_HOST,
27-
// port: Number(process.env.DB_MYSQL_PORT),
28-
// database: process.env.DB_MYSQL_DATABASE,
29-
// user: process.env.DB_MYSQL_USER,
30-
// password: process.env.DB_MYSQL_PASSWORD,
31-
// waitForConnections: true,
32-
// connectionLimit: 10,
33-
// queueLimit: 0,
34-
// });
35-
36-
// export default pool;

backend-typescript/src/core/database/clients/postgres/native.client.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,3 @@ const pool: Pool = new Pool({
1212
});
1313

1414
export default pool;
15-
16-
17-
// import pkg from 'pg';
18-
// import dotenv from 'dotenv';
19-
20-
// dotenv.config();
21-
22-
// const { Pool } = pkg;
23-
24-
// const pool = new Pool({
25-
// host: process.env.DB_PG_HOST,
26-
// port: Number(process.env.DB_PG_PORT),
27-
// database: process.env.DB_PG_DATABASE,
28-
// user: process.env.DB_PG_USER,
29-
// password: process.env.DB_PG_PASSWORD,
30-
// });
31-
32-
// export default pool;
Lines changed: 89 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Request, Response, NextFunction } from 'express';
22
import { HTTP_STATUS } from '../../shared/constants/http/http-status';
3-
// import { ITEM_CONSTANTS } from '../constants/city.constant';
4-
// import { validateItem } from '../schemas/city.schema';
3+
import { ITEM_CONSTANTS } from './city.constant';
4+
import { validateItem } from './city.schema';
55
import Service from './city.service';
6-
// import { City } from '../models/city.model';
6+
import { City } from './city.model';
77

88
export default class Controller {
99
private service: Service;
@@ -12,10 +12,10 @@ export default class Controller {
1212
this.service = service;
1313

1414
this.getItems = this.getItems.bind(this);
15-
// this.getItemById = this.getItemById.bind(this);
16-
// this.createItem = this.createItem.bind(this);
17-
// this.updateItem = this.updateItem.bind(this);
18-
// this.deleteItem = this.deleteItem.bind(this);
15+
this.getItemById = this.getItemById.bind(this);
16+
this.createItem = this.createItem.bind(this);
17+
this.updateItem = this.updateItem.bind(this);
18+
this.deleteItem = this.deleteItem.bind(this);
1919
}
2020

2121
async getItems(req: Request, res: Response, next: NextFunction): Promise<void> {
@@ -29,75 +29,86 @@ export default class Controller {
2929
}
3030
}
3131

32-
// async getItemById(req: Request, res: Response, next: NextFunction): Promise<void> {
33-
// try {
34-
// const id = parseInt(req.params.id, 10);
35-
// const result = await this.service.getItemById(id);
36-
// res.locals = { data: result, statusCode: HTTP_STATUS.OK };
37-
// return next();
38-
// } catch (error: any) {
39-
// if (error.message === ITEM_CONSTANTS.NOT_FOUND) {
40-
// return next({
41-
// statusCode: HTTP_STATUS.NOT_FOUND,
42-
// message: error.message,
43-
// context: `${req.method} ${req.originalUrl}`,
44-
// details: {
45-
// path: req.originalUrl,
46-
// errorCode: HTTP_STATUS.NOT_FOUND,
47-
// timestamp: new Date().toISOString(),
48-
// },
49-
// });
50-
// }
51-
// return next(error);
52-
// }
53-
// }
54-
55-
// async createItem(req: Request, res: Response, next: NextFunction): Promise<void> {
56-
// try {
57-
// validateItem(req.body);
58-
// const result = await this.service.createItem(req.body as City);
59-
// res.locals = { data: result, statusCode: HTTP_STATUS.CREATED };
60-
// return next();
61-
// } catch (error: any) {
62-
// if (error.message === ITEM_CONSTANTS.ALREADY_EXISTS) {
63-
// return next({ statusCode: HTTP_STATUS.CONFLICT, message: error.message });
64-
// }
65-
// if (error.name === 'ValidationError') {
66-
// return next({ statusCode: HTTP_STATUS.BAD_REQUEST, message: error.message });
67-
// }
68-
// return next(error);
69-
// }
70-
// }
71-
72-
// async updateItem(req: Request, res: Response, next: NextFunction): Promise<void> {
73-
// try {
74-
// validateItem(req.body);
75-
// const id = parseInt(req.params.id, 10);
76-
// const result = await this.service.updateItem(id, req.body as Partial<City>);
77-
// res.locals = { data: result, statusCode: HTTP_STATUS.OK };
78-
// return next();
79-
// } catch (error: any) {
80-
// if (error.message === ITEM_CONSTANTS.NOT_FOUND) {
81-
// return next({ statusCode: HTTP_STATUS.NOT_FOUND, message: error.message });
82-
// }
83-
// if (error.name === 'ValidationError') {
84-
// return next({ statusCode: HTTP_STATUS.BAD_REQUEST, message: error.message });
85-
// }
86-
// return next(error);
87-
// }
88-
// }
89-
90-
// async deleteItem(req: Request, res: Response, next: NextFunction): Promise<void> {
91-
// try {
92-
// const id = parseInt(req.params.id, 10);
93-
// const result = await this.service.deleteItem(id);
94-
// res.locals = { data: result, statusCode: HTTP_STATUS.OK };
95-
// return next();
96-
// } catch (error: any) {
97-
// if (error.message === ITEM_CONSTANTS.NOT_FOUND) {
98-
// return next({ statusCode: HTTP_STATUS.NOT_FOUND, message: error.message });
99-
// }
100-
// return next(error);
101-
// }
102-
// }
32+
async getItemById(req: Request, res: Response, next: NextFunction): Promise<void> {
33+
try {
34+
const id = parseInt(req.params.id, 10);
35+
const result = await this.service.getItemById(id);
36+
res.locals = { data: result, statusCode: HTTP_STATUS.OK };
37+
38+
return next();
39+
} catch (error: any) {
40+
if (error.message === ITEM_CONSTANTS.NOT_FOUND) {
41+
42+
return next({
43+
statusCode: HTTP_STATUS.NOT_FOUND,
44+
message: error.message,
45+
context: `${req.method} ${req.originalUrl}`,
46+
details: {
47+
path: req.originalUrl,
48+
errorCode: HTTP_STATUS.NOT_FOUND,
49+
timestamp: new Date().toISOString(),
50+
},
51+
});
52+
}
53+
54+
return next(error);
55+
}
56+
}
57+
58+
async createItem(req: Request, res: Response, next: NextFunction): Promise<void> {
59+
try {
60+
validateItem(req.body);
61+
const result = await this.service.createItem(req.body as City);
62+
res.locals = { data: result, statusCode: HTTP_STATUS.CREATED };
63+
64+
return next();
65+
} catch (error: any) {
66+
if (error.message === ITEM_CONSTANTS.ALREADY_EXISTS) {
67+
68+
return next({ statusCode: HTTP_STATUS.CONFLICT, message: error.message });
69+
}
70+
if (error.name === 'ValidationError') {
71+
72+
return next({ statusCode: HTTP_STATUS.BAD_REQUEST, message: error.message });
73+
}
74+
75+
return next(error);
76+
}
77+
}
78+
79+
async updateItem(req: Request, res: Response, next: NextFunction): Promise<void> {
80+
try {
81+
validateItem(req.body);
82+
const id = parseInt(req.params.id, 10);
83+
const result = await this.service.updateItem(id, req.body);
84+
res.locals = { data: result, statusCode: HTTP_STATUS.OK };
85+
86+
return next();
87+
} catch (error: any) {
88+
if (error.message === ITEM_CONSTANTS.NOT_FOUND) {
89+
return next({ statusCode: HTTP_STATUS.NOT_FOUND, message: error.message });
90+
}
91+
if (error.name === 'ValidationError') {
92+
return next({ statusCode: HTTP_STATUS.BAD_REQUEST, message: error.message });
93+
}
94+
95+
return next(error);
96+
}
97+
}
98+
99+
async deleteItem(req: Request, res: Response, next: NextFunction): Promise<void> {
100+
try {
101+
const id = parseInt(req.params.id, 10);
102+
const result = await this.service.deleteItem(id);
103+
res.locals = { data: result, statusCode: HTTP_STATUS.OK };
104+
105+
return next();
106+
} catch (error: any) {
107+
if (error.message === ITEM_CONSTANTS.NOT_FOUND) {
108+
return next({ statusCode: HTTP_STATUS.NOT_FOUND, message: error.message });
109+
}
110+
111+
return next(error);
112+
}
113+
}
103114
}

backend-typescript/src/modules/city/city.mock-data.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { City } from '../../modules/city/city.model';
2+
3+
export interface PaginationMetadata {
4+
pagination: {
5+
currentPage: number;
6+
perPage: number;
7+
totalItems: number;
8+
totalPages: number;
9+
};
10+
}
11+
12+
export interface PaginatedCityResult {
13+
metadata: PaginationMetadata;
14+
data: City[];
15+
}
16+
17+
export interface CityRepositoryInterface {
18+
getItems(query?: any): Promise<PaginatedCityResult>;
19+
getItemById(id: number): Promise<City | null>;
20+
createItem(data: City): Promise<City>;
21+
updateItem(id: number, data: City): Promise<City>;
22+
deleteItem(id: number): Promise<void>;
23+
existsByName(name: string): Promise<boolean>;
24+
}

0 commit comments

Comments
 (0)