|
1 | | -import { Injectable, OnModuleInit } from '@nestjs/common'; |
2 | | -import { isSaaS } from '../../helpers/app/is-saas.js'; |
| 1 | +import { Injectable } from '@nestjs/common'; |
3 | 2 | import { FoundUserInGroupDs } from './application/data-structures/found-user-in-group.ds.js'; |
4 | 3 | import { FoundUserDto } from './dto/found-user.dto.js'; |
5 | 4 | import { UserEntity } from './user.entity.js'; |
6 | 5 | import { getUserIntercomHash } from './utils/get-user-intercom-hash.js'; |
7 | | -import { Encryptor } from '../../helpers/encryption/encryptor.js'; |
8 | | -import { CompanyInfoEntity } from '../company-info/company-info.entity.js'; |
9 | | -import { RegisterUserDs } from './application/data-structures/register-user-ds.js'; |
10 | | -import { UserRoleEnum } from './enums/user-role.enum.js'; |
11 | | -import { InjectRepository } from '@nestjs/typeorm'; |
12 | | -import { Repository } from 'typeorm'; |
13 | | -import { buildRegisteringUser } from './utils/build-registering-user.util.js'; |
14 | 6 |
|
15 | 7 | @Injectable() |
16 | | -export 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 | | - ) {} |
23 | | - |
| 8 | +export class UserHelperService { |
24 | 9 | public buildFoundUserInGroupDs(user: UserEntity): FoundUserInGroupDs { |
25 | 10 | return { |
26 | 11 | id: user.id, |
@@ -50,35 +35,4 @@ export class UserHelperService implements OnModuleInit { |
50 | 35 | show_test_connections: user.showTestConnections, |
51 | 36 | }; |
52 | 37 | } |
53 | | - |
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)); |
62 | | - |
63 | | - const foundTestUser = await this.userRepository.findOneBy({ email: email }); |
64 | | - if (foundTestUser) { |
65 | | - return; |
66 | | - } |
67 | | - |
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 | | - } |
84 | 38 | } |
0 commit comments