|
@ -1,13 +1,14 @@ |
|
|
import { BadRequestException, Injectable } from '@nestjs/common' |
|
|
import { BadRequestException, Injectable } from '@nestjs/common' |
|
|
import { InjectRepository } from '@nestjs/typeorm' |
|
|
import { InjectRepository } from '@nestjs/typeorm' |
|
|
import { Repository } from 'typeorm' |
|
|
import { Repository } from 'typeorm' |
|
|
|
|
|
import { Cron } from '@nestjs/schedule' |
|
|
|
|
|
import * as bcrypt from 'bcrypt' |
|
|
|
|
|
|
|
|
import { type CreateChannelDto } from './dto/create-channel.dto' |
|
|
import { type CreateChannelDto } from './dto/create-channel.dto' |
|
|
import { UsersService } from 'src/users/users.service' |
|
|
import { UsersService } from 'src/users/users.service' |
|
|
|
|
|
|
|
|
import type User from 'src/users/entity/user.entity' |
|
|
import type User from 'src/users/entity/user.entity' |
|
|
import Channel from './entity/channel.entity' |
|
|
import Channel from './entity/channel.entity' |
|
|
import { Cron } from '@nestjs/schedule' |
|
|
|
|
|
|
|
|
|
|
|
@Injectable() |
|
|
@Injectable() |
|
|
export class ChatService { |
|
|
export class ChatService { |
|
@ -58,7 +59,7 @@ export class ChatService { |
|
|
newChannel.admins = [user] |
|
|
newChannel.admins = [user] |
|
|
newChannel.name = channel.name |
|
|
newChannel.name = channel.name |
|
|
newChannel.isPrivate = channel.isPrivate |
|
|
newChannel.isPrivate = channel.isPrivate |
|
|
newChannel.password = channel.password |
|
|
newChannel.password = await this.hash(channel.password) |
|
|
console.log("New channel: ", JSON.stringify(newChannel)) |
|
|
console.log("New channel: ", JSON.stringify(newChannel)) |
|
|
} |
|
|
} |
|
|
return await this.ChannelRepository.save(newChannel) |
|
|
return await this.ChannelRepository.save(newChannel) |
|
@ -75,15 +76,13 @@ export class ChatService { |
|
|
return newDM |
|
|
return newDM |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async updatePassword (id: number, password: string): Promise<void> { |
|
|
async hash(password: string): Promise<string> { |
|
|
const channel: Channel | null = await this.ChannelRepository.findOneBy({ |
|
|
if (!password) return '' |
|
|
id |
|
|
password = await bcrypt.hash( |
|
|
}) |
|
|
password, |
|
|
if (channel === null) { |
|
|
Number(process.env.HASH_SALT) |
|
|
throw new BadRequestException(`Channel #${id} not found`) |
|
|
) |
|
|
} |
|
|
return password |
|
|
channel.password = password |
|
|
|
|
|
await this.update(channel) |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async getChannelsForUser (ftId: number): Promise<Channel[]> { |
|
|
async getChannelsForUser (ftId: number): Promise<Channel[]> { |
|
|