Skip to content

Commit f2d2af7

Browse files
committed
Improve typescript & javascript backends
1 parent f7d982c commit f2d2af7

File tree

68 files changed

+2398
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2398
-115
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=mock # pg | mysql | mock | mongo
12+
DB_CLIENT=mysql # pg | mysql | mock | mongo
1313

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

backend-javascript/eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default defineConfig([
66
{
77
ignores: [
88
'dist/**',
9+
'sql/**',
910
'eslint.config.js',
1011
'webpack.config.js',
1112
],
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
const DatabaseService = require('../../src/features/setup/database-service');
4+
5+
async function main() {
6+
const databaseName = 'backend_angular';
7+
8+
try {
9+
console.log(`Starting database creation for: ${databaseName}`);
10+
const databaseService = new DatabaseService();
11+
await databaseService.createDatabase(databaseName);
12+
console.log(`Database ${databaseName} created successfully`);
13+
} catch (error) {
14+
console.error(`Error creating database: ${error.message}`);
15+
throw error;
16+
}
17+
}
18+
19+
main().catch((error) => {
20+
console.error('Unhandled error:', error.message);
21+
throw error;
22+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
const DomainService = require('../../src/features/setup/domain-service');
4+
5+
async function main() {
6+
try {
7+
console.log('Starting domains creation');
8+
const domainService = new DomainService();
9+
const domainsCreated = await domainService.createDomains();
10+
11+
if (domainsCreated && domainsCreated.length > 0) {
12+
console.log('Domains created successfully:', domainsCreated.map(domain => domain.name).join(', '));
13+
} else {
14+
console.log('No domains were created');
15+
}
16+
} catch (error) {
17+
console.error(`Error creating domains: ${error.message}`);
18+
throw error;
19+
}
20+
}
21+
22+
main().catch((error) => {
23+
console.error('Unhandled error:', error.message);
24+
throw error;
25+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
db.createCollection("continent");
2+
3+
db.createCollection("country");
4+
5+
db.createCollection("city");
6+
7+
db.createCollection("person");
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
db.continent.insertMany([
3+
{
4+
"code": "NA",
5+
"name": "North America-mongodb",
6+
"wikipediaLink": "North_America",
7+
"area": 24709000,
8+
"population": 587615000,
9+
"countriesNumber": 23
10+
},
11+
{
12+
"code": "EU",
13+
"name": "Europe-mongodb",
14+
"wikipediaLink": "Europe",
15+
"area": 10180000,
16+
"population": 742648000,
17+
"countriesNumber": 45
18+
}
19+
]);
20+
21+
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"paginationTotals": {
3+
"count": 7,
4+
"area": 150278011,
5+
"population": 6344901941,
6+
"countriesNumber": 682,
7+
"density": "42.22109"
8+
},
9+
"allTotals": {
10+
"count": 7,
11+
"area": 150278011,
12+
"population": 6344901941,
13+
"countriesNumber": 682,
14+
"density": "42.22109"
15+
},
16+
"continents": [
17+
{
18+
"id": 1016,
19+
"code": "AF44",
20+
"name": "Africa-pgbxcvbxc",
21+
"wikipediaLink": "Africa1111",
22+
"area": 30370011,
23+
"population": 451,
24+
"countriesNumber": 541,
25+
"density": 0.00001
26+
},
27+
{
28+
"id": 1017,
29+
"code": "AN",
30+
"name": "Antarctica-pg",
31+
"wikipediaLink": "Antarctica",
32+
"area": 14000000,
33+
"population": 4490,
34+
"countriesNumber": 0,
35+
"density": 0.00032
36+
},
37+
{
38+
"id": 1018,
39+
"code": "AS",
40+
"name": "Asia-pgdfghdfgh",
41+
"wikipediaLink": "Asia",
42+
"area": 44579000,
43+
"population": 4545133000,
44+
"countriesNumber": 47,
45+
"density": 101.95682
46+
},
47+
{
48+
"id": 1019,
49+
"code": "OC",
50+
"name": "Australia-pg",
51+
"wikipediaLink": "Australia_(continent)",
52+
"area": 8600000,
53+
"population": 41261000,
54+
"countriesNumber": 14,
55+
"density": 4.79779
56+
},
57+
{
58+
"id": 1020,
59+
"code": "EU",
60+
"name": "Europe-pg",
61+
"wikipediaLink": "Europe",
62+
"area": 10180000,
63+
"population": 742648000,
64+
"countriesNumber": 45,
65+
"density": 72.95167
66+
},
67+
{
68+
"id": 1021,
69+
"code": "NA",
70+
"name": "North America-pg",
71+
"wikipediaLink": "North_America",
72+
"area": 24709000,
73+
"population": 587615000,
74+
"countriesNumber": 23,
75+
"density": 23.78142
76+
},
77+
{
78+
"id": 1022,
79+
"code": "SA",
80+
"name": "South America-pg",
81+
"wikipediaLink": "South_America",
82+
"area": 17840000,
83+
"population": 428240000,
84+
"countriesNumber": 12,
85+
"density": 24.00448
86+
}
87+
]
88+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
WITH filtered_data AS (
2+
SELECT
3+
id,
4+
code,
5+
name,
6+
wikipedia_link AS wikipedia_link,
7+
CAST(area AS SIGNED) AS area,
8+
CAST(population AS DECIMAL(15, 2)) AS population,
9+
CAST(countries_number AS SIGNED) AS countries_number,
10+
ROUND(
11+
CAST(population AS DECIMAL(15, 2)) / NULLIF(CAST(area AS DECIMAL(15, 2)), 0),
12+
5
13+
) AS density
14+
FROM
15+
continent
16+
WHERE
17+
LOWER(name) LIKE '%a%'
18+
ORDER BY
19+
name ASC
20+
),
21+
pagination AS (
22+
SELECT
23+
id,
24+
code,
25+
name,
26+
wikipedia_link AS wikipediaLink,
27+
CAST(area AS SIGNED) AS area,
28+
CAST(population AS DECIMAL(15, 2)) AS population,
29+
CAST(countries_number AS SIGNED) AS countriesNumber,
30+
ROUND(
31+
CAST(population AS DECIMAL(15, 2)) / NULLIF(CAST(area AS DECIMAL(15, 2)), 0),
32+
5
33+
) AS density
34+
FROM
35+
filtered_data
36+
LIMIT
37+
5 OFFSET 0
38+
),
39+
totals AS (
40+
SELECT
41+
CAST(SUM(area) AS SIGNED) AS total_area_all,
42+
CAST(SUM(population) AS DECIMAL(15, 2)) AS total_population_all,
43+
CAST(SUM(countries_number) AS SIGNED) AS total_countries_number_all,
44+
COUNT(id) AS count_all,
45+
ROUND(
46+
CAST(SUM(population) AS DECIMAL(15, 2)) / NULLIF(CAST(SUM(area) AS DECIMAL(15, 2)), 0),
47+
5
48+
) AS average_density_all
49+
FROM
50+
filtered_data
51+
),
52+
totals_pagination AS (
53+
SELECT
54+
CAST(SUM(area) AS SIGNED) AS total_area,
55+
CAST(SUM(population) AS DECIMAL(15, 2)) AS total_population,
56+
CAST(SUM(countriesNumber) AS SIGNED) AS total_countries_number,
57+
COUNT(id) AS count,
58+
ROUND(
59+
CAST(SUM(population) AS DECIMAL(15, 2)) / NULLIF(CAST(SUM(area) AS DECIMAL(15, 2)), 0),
60+
5
61+
) AS average_density
62+
FROM
63+
pagination
64+
)
65+
SELECT
66+
(
67+
SELECT
68+
count_all
69+
FROM
70+
totals
71+
) AS count,
72+
(
73+
SELECT
74+
total_area_all
75+
FROM
76+
totals
77+
) AS area,
78+
(
79+
SELECT
80+
total_population_all
81+
FROM
82+
totals
83+
) AS population,
84+
(
85+
SELECT
86+
total_countries_number_all
87+
FROM
88+
totals
89+
) AS countriesNumber,
90+
(
91+
SELECT
92+
count
93+
FROM
94+
totals_pagination
95+
) AS countPagination,
96+
(
97+
SELECT
98+
total_area
99+
FROM
100+
totals_pagination
101+
) AS areaPagination,
102+
(
103+
SELECT
104+
total_population
105+
FROM
106+
totals_pagination
107+
) AS populationPagination,
108+
(
109+
SELECT
110+
total_countries_number
111+
FROM
112+
totals_pagination
113+
) AS countriesNumberPagination,
114+
(
115+
SELECT
116+
average_density_all
117+
FROM
118+
totals
119+
) AS density,
120+
(
121+
SELECT
122+
average_density
123+
FROM
124+
totals_pagination
125+
) AS densityPagination,
126+
JSON_ARRAYAGG(
127+
JSON_OBJECT(
128+
'id',
129+
pagination.id,
130+
'code',
131+
pagination.code,
132+
'name',
133+
pagination.name,
134+
'wikipediaLink',
135+
pagination.wikipediaLink,
136+
'area',
137+
pagination.area,
138+
'population',
139+
pagination.population,
140+
'countriesNumber',
141+
pagination.countriesNumber,
142+
'density',
143+
pagination.density
144+
)
145+
) AS continents
146+
FROM
147+
pagination;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DROP DATABASE IF EXISTS backend_javascript;
2+
3+
CREATE DATABASE backend_javascript;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
CREATE TABLE continent (
2+
id MEDIUMINT NOT NULL AUTO_INCREMENT,
3+
code CHAR(10) NOT NULL,
4+
name CHAR(100) NOT NULL,
5+
wikipedia_link CHAR(100) DEFAULT "",
6+
area INT DEFAULT 0,
7+
population BIGINT DEFAULT 0,
8+
countries_number INT DEFAULT 0,
9+
PRIMARY KEY (id)
10+
);
11+
12+
ALTER TABLE
13+
continent AUTO_INCREMENT = 1000;
14+
15+
CREATE TABLE country (
16+
id MEDIUMINT NOT NULL AUTO_INCREMENT,
17+
name CHAR(50) NOT NULL,
18+
wikipedia_link CHAR(50) DEFAULT "",
19+
continent_id INT,
20+
iso_numeric CHAR(50),
21+
iso_alpha2 CHAR(50),
22+
iso_alpha3 CHAR(50),
23+
flag CHAR(50),
24+
PRIMARY KEY (id)
25+
);
26+
27+
ALTER TABLE
28+
country AUTO_INCREMENT = 1000;
29+
30+
CREATE TABLE city (
31+
id MEDIUMINT NOT NULL AUTO_INCREMENT,
32+
name CHAR(50) NOT NULL,
33+
wikipedia_link CHAR(50) DEFAULT "",
34+
country_id INTEGER,
35+
capital BOOLEAN DEFAULT false,
36+
PRIMARY KEY (id)
37+
);
38+
39+
ALTER TABLE
40+
city AUTO_INCREMENT = 1000;
41+
42+
CREATE TABLE person (
43+
id MEDIUMINT NOT NULL AUTO_INCREMENT,
44+
name CHAR(100) NOT NULL,
45+
wikipedia_link CHAR(100) NOT NULL,
46+
birth_date DATE,
47+
birth_city_id INT,
48+
death_date DATE,
49+
death_city_id INT,
50+
gender_id INT,
51+
image CHAR(50),
52+
PRIMARY KEY (id)
53+
);
54+
55+
ALTER TABLE
56+
person AUTO_INCREMENT = 1000;

0 commit comments

Comments
 (0)