Skip to content

Commit 7bd340f

Browse files
authored
Merge pull request #39 from VMihalov/master
Fix some requested issues and improve the generation process
2 parents 849b15a + 2350316 commit 7bd340f

File tree

34 files changed

+229
-128
lines changed

34 files changed

+229
-128
lines changed

generators/app/questions/db.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-
module.exports = [
2-
{
3-
type: 'list',
4-
name: 'db',
5-
message: 'Choose db for your api.(Sql - Typeorm, Mongo - Mongoose)',
6-
choices: ['Mongodb', 'Mysql', 'Postgresql'],
7-
},
8-
]
1+
module.exports = {
2+
jwt: [
3+
{
4+
type: 'list',
5+
name: 'db',
6+
message: 'Choose db for your api.(Sql - Typeorm, Mongo - Mongoose)',
7+
choices: ['Mongodb', 'Mysql', 'Postgresql'],
8+
},
9+
],
10+
oauth2: [
11+
{
12+
type: 'list',
13+
name: 'db',
14+
message: 'Choose db for your api.(Sql - Typeorm, Mongo - Mongoose)',
15+
choices: ['Mongodb', 'Mysql'],
16+
},
17+
],
18+
passportLocal: [
19+
{
20+
type: 'list',
21+
name: 'db',
22+
message: 'Choose db for your api.(Sql - Typeorm, Mongo - Mongoose)',
23+
choices: ['Mongodb', 'Mysql'],
24+
},
25+
],
26+
}

generators/app/questions/dependenciesVersions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ module.exports = [
44
name: 'needStableDependencies',
55
message: 'Do you want install stable packages`s versions (if `no` will be istalled latest versions)',
66
default: 'Yes',
7-
choices: ['Yes', 'No'],
7+
choices: ['Yes'],
88
},
99
];

generators/app/steps/prompting.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module.exports = {
5050
},
5151

5252
askAboutDatabase() {
53-
askQuestions.call(this, 'Database', questions.db, this.async());
53+
askQuestions.call(this, 'Database', questions.db[this.answers.authType], this.async());
5454
},
5555

5656
askAboutMailer() {

generators/auth/dependencies/dependencies.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
"redis": "3.1.2"
2626
},
2727
"mongodb": {
28-
"passport-google-oauth20": "2.0.9",
28+
"passport-google-oauth20": "2.0.0",
2929
"express-session": "1.17.2",
3030
"cookie-parser": "1.4.5",
3131
"connect-mongodb-session": "3.0.0",
3232
"mongodb": "4.1.0"
3333
},
3434
"mysql": {
35-
"passport-google-oauth20": "2.0.9",
35+
"passport-google-oauth20": "2.0.0",
3636
"express-session": "1.17.2",
3737
"express-mysql-session": "2.1.6"
3838
}

generators/auth/templates/mongodb/oauth2/_.env

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ OAUTH2_GOOGLE_CALLBACK_URL=<%= config.oauth2CallbackUrl %>
77

88
PASSPORT_SESSION_SECRET=<%= config.passportSessionSecret %>
99

10-
REDIS_PORT=6379
10+
MONGODB_URL=mongodb://mongodb:27017/app
1111

12-
<% if(config.wantedDocker === 'Yes') { %>
13-
REDIS_URL=redis://redis:6379
12+
<% if(config.sessionsStorage === 'redis') { %>
1413
REDIS_HOST=redis
15-
16-
MONGODB_URL=mongodb://mongodb:27017/app
14+
REDIS_PORT=6379
1715
<% } %>
1816

19-
<% if(config.wantedDocker === 'No') { %>
20-
REDIS_URL=redis://localhost:6379
21-
REDIS_HOST=127.0.0.1
22-
23-
MONGODB_URL=mongodb://localhost:27017/app
17+
<% if(config.sessionsStorage === 'mysql') { %>
18+
MYSQL_ROOT_USER=root
19+
MYSQL_PASSWORD=1234
20+
MYSQL_HOST=mysql
21+
MYSQL_PORT=3306
22+
MYSQL_DB=app
2423
<% } %>

generators/auth/templates/mongodb/passportLocal/_.env

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ SERVER_HOST=<%= config.serverHost %>:<%= config.serverPort %>
33

44
PASSPORT_SESSION_SECRET=<%= config.passportSessionSecret %>
55

6-
<% if(config.wantedDocker === 'Yes') { %>
7-
MONGODB_URL='mongodb://mongodb:27017/app'
6+
MONGODB_URL=mongodb://127.0.0.1:27017/app
87

9-
REDIS_URL=redis://redis:6379
8+
<% if(config.sessionsStorage === 'redis') { %>
109
REDIS_HOST=redis
10+
REDIS_PORT=6379
1111
<% } %>
1212

13-
<% if(config.wantedDocker === 'No') { %>
14-
MONGODB_URL=mongodb://localhost:27017/app
15-
16-
REDIS_URL=redis://localhost:6379
17-
REDIS_HOST=localhost
13+
<% if(config.sessionsStorage === 'mysql') { %>
14+
MYSQL_ROOT_USER=root
15+
MYSQL_PASSWORD=1234
16+
MYSQL_HOST=mysql
17+
MYSQL_PORT=3306
18+
MYSQL_DB=app
1819
<% } %>
1920

generators/auth/templates/mongodb/passportLocal/src/_mysql-main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ async function bootstrap() {
4848
store: new MySQLStore({
4949
host: configService.get<string>('MYSQL_HOST'),
5050
port: configService.get<number>('MYSQL_PORT'),
51-
user: configService.get<string>('MYSQL_USER'),
52-
password: configService.get<string>('MYSQL_PASS'),
53-
database: configService.get<string>('MYSQL_SESSIONS_DB'),
51+
user: configService.get<string>('MYSQL_ROOT_USER'),
52+
password: configService.get<string>('MYSQL_PASSWORD'),
53+
database: configService.get<string>('MYSQL_DB'),
5454
}),
5555
}),
5656
);

generators/auth/templates/mysql/jwt/src/modules/v1/users/users.repository.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ export default class UsersRepository {
1919
});
2020
}
2121

22-
public async getByEmail(email: string): Promise<UserEntity | undefined> {
22+
public async getByEmail(email: string): Promise<UserEntity | void> {
2323
return this.usersModel.findOne({
2424
where: [{
2525
email,
2626
}],
2727
});
2828
}
2929

30-
public async getUnverifiedUserByEmail(email: string): Promise<UserEntity | undefined> {
30+
public async getUnverifiedUserByEmail(email: string): Promise<UserEntity | void> {
3131
return this.usersModel.findOne({
3232
where: [{
3333
email,
@@ -36,7 +36,7 @@ export default class UsersRepository {
3636
});
3737
}
3838

39-
public async getVerifiedUserByEmail(email: string): Promise<UserEntity | undefined> {
39+
public async getVerifiedUserByEmail(email: string): Promise<UserEntity | void> {
4040
return this.usersModel.findOne({
4141
where: [{
4242
email,
@@ -45,17 +45,17 @@ export default class UsersRepository {
4545
});
4646
}
4747

48-
public async getById(id: number): Promise<UserEntity | undefined> {
48+
public async getById(id: number): Promise<UserEntity | void> {
4949
return this.usersModel.findOne(id);
5050
}
5151

52-
public async getVerifiedUserById(id: number): Promise<UserEntity | undefined> {
52+
public async getVerifiedUserById(id: number): Promise<UserEntity | void> {
5353
return this.usersModel.findOne(id, {
5454
where: [{ verified: true }],
5555
});
5656
}
5757

58-
public async getUnverifiedUserById(id: number): Promise<UserEntity | undefined> {
58+
public async getUnverifiedUserById(id: number): Promise<UserEntity | void> {
5959
return this.usersModel.findOne(id, {
6060
where: [{ verified: false }],
6161
});

generators/auth/templates/mysql/jwt/src/modules/v1/users/users.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ export default class UsersService {
2929
return this.usersRepository.getVerifiedUserByEmail(email);
3030
}
3131

32-
public async getVerifiedUserById(id: number): Promise<UserEntity | undefined> {
32+
public async getVerifiedUserById(id: number): Promise<UserEntity | void> {
3333
return this.usersRepository.getVerifiedUserById(id);
3434
}
3535

36-
public async getUnverifiedUserById(id: number): Promise<UserEntity | undefined> {
36+
public async getUnverifiedUserById(id: number): Promise<UserEntity | void> {
3737
return this.usersRepository.getUnverifiedUserById(id);
3838
}
3939

40-
public async getById(id: number): Promise<UserEntity | undefined> {
40+
public async getById(id: number): Promise<UserEntity | void> {
4141
return this.usersRepository.getById(id);
4242
}
4343

generators/auth/templates/mysql/oauth2/_.env

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ MYSQL_HOST=mysql
1212
MYSQL_PORT=3306
1313
MYSQL_DB=app
1414

15-
<% if(config.wantedDocker === 'Yes') { %>
16-
MONGODB_URL=mongodb://mongodb:27017/app
17-
18-
MYSQL_URL=mysql://mysql:3306/app
15+
<% if(config.sessionsStorage === 'redis') { %>
16+
REDIS_HOST=redis
17+
REDIS_PORT=6379
1918
<% } %>
2019

21-
<% if(config.wantedDocker === 'No') { %>
22-
MONGODB_URL=mongodb://localhost:27017/app
23-
24-
MYSQL_URL=mysql://mysql:3306/app
20+
<% if(config.sessionsStorage === 'mongodb') { %>
21+
MONGODB_URL=mongodb://mongodb:27017/app
2522
<% } %>

0 commit comments

Comments
 (0)