import { Injectable } from '@nestjs/common';
import {InjectRepository} from "@nestjs/typeorm";
import {Repository} from "typeorm";
import {UserEntity} from "./entities/user.entity";
import {ApiError} from "./exceptions/api-error";
import {v4} from 'uuid';
import * as bcrypt from 'bcrypt';
import {CreateUserDto} from "./dto/create-user.dto";
import {TokenGuard} from "./token.guard";
import {UserMailService} from "./userMail.service";
@Injectable()
export class UserService {
constructor(@InjectRepository(UserEntity) private readonly userRepository: Repository<UserEntity>) {}
public async register(email: any, password: any) {
const candidate = await this.userRepository.findOne({where: {email: email}})
if (candidate) {
throw ApiError.BadRequest(`Пользователь с почтовым адресом ${email} уже существует`)
}
const hashPassword = await bcrypt.hash(password, 3);
const activationLink = v4(); // v34fa-asfasf-142saf-sa-asf
const user = await this.userRepository.create({email, password: hashPassword, activationLink})
await UserMailService.sendActivationMail(email, `${process.env.API_URL}/api/activate/${activationLink}`);
const userDto = new CreateUserDto(user); // id, email, isActivated
const tokens = TokenGuard.generateTokens({...userDto});
await TokenGuard.saveToken(userDto.id, tokens.refreshToken);
return {...tokens, user: userDto}
}
}
TS2339: Property 'sendActivationMail' does not exist on type 'typeof UserMailService'.
await UserMailService.sendActivationMail(email, `${process.env.API_URL}/api/activate/${activationLink}`);
TS2339: Property 'sendActivationMail' does not exist on type 'typeof UserMailService'
rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcan
login | rolreplication | rolconnlimit | rolpassword | rolvaliduntil | rolbypassrls | rolc
onfig | oid
---------------------------+----------+------------+---------------+-------------+-------
------+----------------+--------------+-------------+---------------+--------------+-----
------+-------
pg_database_owner | f | t | f | f | f
| f | -1 | ******** | | f |
| 6171
pg_read_all_data | f | t | f | f | f
| f | -1 | ******** | | f |
| 6181
pg_write_all_data | f | t | f | f | f
| f | -1 | ******** | | f |
| 6182
pg_monitor | f | t | f | f | f
| f | -1 | ******** | | f |
| 3373
pg_read_all_settings | f | t | f | f | f
| f | -1 | ******** | | f |
| 3374
pg_read_all_stats | f | t | f | f | f
| f | -1 | ******** | | f |
--Далее--
Файлы, относящиеся к этой СУБД, будут принадлежать пользователю "postgres".
От его имени также будет запускаться процесс сервера.
Кластер баз данных будет инициализирован с локалью "ru_RU.UTF-8".
Кодировка БД по умолчанию, выбранная в соответствии с настройками: "UTF8".
Выбрана конфигурация текстового поиска по умолчанию "russian".
Контроль целостности страниц данных отключён.
исправление прав для существующего каталога /var/lib/pgsql/data... ок
создание подкаталогов... ок
выбирается реализация динамической разделяемой памяти... posix
выбирается значение max_connections по умолчанию... 100
выбирается значение shared_buffers по умолчанию... 128MB
выбирается часовой пояс по умолчанию... America/New_York
создание конфигурационных файлов... ок
выполняется подготовительный скрипт... ок
выполняется заключительная инициализация... ок
сохранение данных на диске... ок
Готово. Теперь вы можете запустить сервер баз данных:
/usr/bin/pg_ctl -D /var/lib/pgsql/data -l файл_журнала start
[Stell@fedora ~]$ sudo postgresql-setup --initdb
* Initializing database in '/var/lib/pgsql/data'
ERROR: Data directory /var/lib/pgsql/data is not empty!
ERROR: Initializing database failed, possibly see /var/lib/pgsql/initdb_postgresql.log
[Stell@fedora ~]$ systemctl restart postgresql
Job for postgresql.service failed because the control process exited with error code.
See "systemctl status postgresql.service" and "journalctl -xeu postgresql.service" for details.
[Stell@fedora ~]$
ERROR: The /var/lib/pgsql directory has wrong permissions.
Please make sure the directory is writable by Stell.
при 1 команде LinkScroll activeClass="active" spy={true}
smooth={true}
offset={-100}
duration={500}
style={{color: "black", textDecoration: "none"}}
to={page.tags}>
<ListItemText onClick={() => navigate('/#' + page.tags)} id={"#" + page.tags} sx={{fontFamily: "Mulish"}}>
{page.title}
</ListItemText>
</LinkScroll>