@@ -14,71 +14,71 @@ import { buildRegisteringUser } from './utils/build-registering-user.util.js';
1414
1515@Injectable ( )
1616export class UserHelperService implements OnModuleInit {
17- constructor (
18- @InjectRepository ( UserEntity )
19- private readonly userRepository : Repository < UserEntity > ,
20- @InjectRepository ( CompanyInfoEntity )
21- private readonly companyInfoRepository : Repository < CompanyInfoEntity > ,
22- ) { }
17+ constructor (
18+ @InjectRepository ( UserEntity )
19+ private readonly userRepository : Repository < UserEntity > ,
20+ @InjectRepository ( CompanyInfoEntity )
21+ private readonly companyInfoRepository : Repository < CompanyInfoEntity > ,
22+ ) { }
2323
24- public buildFoundUserInGroupDs ( user : UserEntity ) : FoundUserInGroupDs {
25- return {
26- id : user . id ,
27- email : user . email ,
28- createdAt : user . createdAt ,
29- isActive : user . isActive ,
30- name : user . name ,
31- suspended : user . suspended ,
32- externalRegistrationProvider : user . externalRegistrationProvider ,
33- } ;
34- }
24+ public buildFoundUserInGroupDs ( user : UserEntity ) : FoundUserInGroupDs {
25+ return {
26+ id : user . id ,
27+ email : user . email ,
28+ createdAt : user . createdAt ,
29+ isActive : user . isActive ,
30+ name : user . name ,
31+ suspended : user . suspended ,
32+ externalRegistrationProvider : user . externalRegistrationProvider ,
33+ } ;
34+ }
3535
36- public async buildFoundUserDs ( user : UserEntity ) : Promise < FoundUserDto > {
37- const intercomHash = getUserIntercomHash ( user . id ) ;
38- return {
39- id : user . id ,
40- createdAt : user . createdAt ,
41- suspended : user . suspended ,
42- isActive : user . isActive ,
43- email : user . email ,
44- intercom_hash : intercomHash ,
45- name : user . name ,
46- role : user . role ,
47- is_2fa_enabled : user . otpSecretKey !== null && user . isOTPEnabled ,
48- company : user . company ? { id : user . company . id } : null ,
49- externalRegistrationProvider : user . externalRegistrationProvider ,
50- show_test_connections : user . showTestConnections ,
51- } ;
52- }
36+ public async buildFoundUserDs ( user : UserEntity ) : Promise < FoundUserDto > {
37+ const intercomHash = getUserIntercomHash ( user . id ) ;
38+ return {
39+ id : user . id ,
40+ createdAt : user . createdAt ,
41+ suspended : user . suspended ,
42+ isActive : user . isActive ,
43+ email : user . email ,
44+ intercom_hash : intercomHash ,
45+ name : user . name ,
46+ role : user . role ,
47+ is_2fa_enabled : user . otpSecretKey !== null && user . isOTPEnabled ,
48+ company : user . company ? { id : user . company . id } : null ,
49+ externalRegistrationProvider : user . externalRegistrationProvider ,
50+ show_test_connections : user . showTestConnections ,
51+ } ;
52+ }
5353
54- public async onModuleInit ( ) : Promise < void > {
55- if ( isSaaS ( ) ) {
56- return ;
57- }
58- const email = ( process . env . ADMIN_EMAIL || 'admin@email.local' ) . toLowerCase ( ) ;
59- const password =
60- process . env . ADMIN_PASSWORD ||
61- ( process . env . NODE_ENV === 'test' ? 'test12345' : Encryptor . generateRandomString ( 10 ) ) ;
54+ public async onModuleInit ( ) : Promise < void > {
55+ if ( isSaaS ( ) || process . env . NODE_ENV !== 'test' ) {
56+ return ;
57+ }
58+ const email = ( process . env . ADMIN_EMAIL || 'admin@email.local' ) . toLowerCase ( ) ;
59+ const password =
60+ process . env . ADMIN_PASSWORD ||
61+ ( process . env . NODE_ENV === 'test' ? 'test12345' : Encryptor . generateRandomString ( 10 ) ) ;
6262
63- const foundTestUser = await this . userRepository . findOneBy ( { email : email } ) ;
64- if ( foundTestUser ) {
65- return ;
66- }
63+ const foundTestUser = await this . userRepository . findOneBy ( { email : email } ) ;
64+ if ( foundTestUser ) {
65+ return ;
66+ }
6767
68- const registerUserData : RegisterUserDs = {
69- email : email ,
70- password : password ,
71- isActive : true ,
72- gclidValue : null ,
73- name : 'Admin' ,
74- role : UserRoleEnum . ADMIN ,
75- } ;
76- const savedUser = await this . userRepository . save ( buildRegisteringUser ( registerUserData ) ) ;
77- const newCompanyInfo = new CompanyInfoEntity ( ) ;
78- newCompanyInfo . id = Encryptor . generateUUID ( ) ;
79- const savedCompanyInfo = await this . companyInfoRepository . save ( newCompanyInfo ) ;
80- savedUser . company = savedCompanyInfo ;
81- await this . userRepository . save ( savedUser ) ;
82- console . info ( `Admin user created with email: "${ email } " and password: "${ password } "` ) ;
83- }
68+ const registerUserData : RegisterUserDs = {
69+ email : email ,
70+ password : password ,
71+ isActive : true ,
72+ gclidValue : null ,
73+ name : 'Admin' ,
74+ role : UserRoleEnum . ADMIN ,
75+ } ;
76+ const savedUser = await this . userRepository . save ( buildRegisteringUser ( registerUserData ) ) ;
77+ const newCompanyInfo = new CompanyInfoEntity ( ) ;
78+ newCompanyInfo . id = Encryptor . generateUUID ( ) ;
79+ const savedCompanyInfo = await this . companyInfoRepository . save ( newCompanyInfo ) ;
80+ savedUser . company = savedCompanyInfo ;
81+ await this . userRepository . save ( savedUser ) ;
82+ console . info ( `Admin user created with email: "${ email } " and password: "${ password } "` ) ;
83+ }
8484}
0 commit comments