Skip to content

Commit

Permalink
fix(channel): password 변경시 hashing이 제대로 되지 않는 문제 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
cjho0316 committed Dec 22, 2023
1 parent 23e3e5e commit 3623c22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/channels/channels.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { InjectRedis } from '@liaoliaots/nestjs-redis';
import {
BadRequestException,
Injectable,
Logger,
} from '@nestjs/common';
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
import * as bycrypt from 'bcrypt';
import { Redis } from 'ioredis';
import { MUTE_TIME } from 'src/common/constants';
Expand Down Expand Up @@ -31,6 +27,7 @@ import { DmChannelListResponseDto } from './dto/dmchannel-list-response.dto';
import { DmChannelListReturnDto } from './dto/dmchannel-list-return.dto';
import { UpdateChannelPwdParamDto } from './dto/update-channel-pwd-param.dto';
import moment from 'moment';
import { channel } from 'diagnostics_channel';

@Injectable()
export class ChannelsService {
Expand Down Expand Up @@ -781,10 +778,17 @@ export class ChannelsService {
channelId: number,
newPassword: string,
) {
const pwdResult = await this.channelsRepository.update(channelId, {
password: newPassword,
const channel = await this.channelsRepository.findOne({
where: { id: channelId },
});
if (pwdResult.affected !== 1)
if (!channel) {
throw new BadRequestException(
`channel ${channelId} does not exist`,
);
}
channel.password = newPassword;
const updateChannel = await this.channelsRepository.save(channel);
if (!updateChannel)
throw DBUpdateFailureException('update channel password failed');
}

Expand Down
3 changes: 2 additions & 1 deletion src/channels/entities/channel.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
CHANNEL_PASSWORD_REGEXP,
} from 'src/common/constants';
import { ChannelType } from 'src/common/enum';
import { BeforeInsert, Column, Entity } from 'typeorm';
import { BeforeInsert, BeforeUpdate, Column, Entity } from 'typeorm';

@Entity()
export class Channel extends BaseEntity {
Expand Down Expand Up @@ -45,6 +45,7 @@ export class Channel extends BaseEntity {
ownerId?: number | null;

@BeforeInsert()
@BeforeUpdate()
async hashPassword() {
if (this.password) {
try {
Expand Down

0 comments on commit 3623c22

Please sign in to comment.