Skip to content

Commit

Permalink
feat(users): 유저 생성 후 created 문장 출력 시, db에 저장된 email 값을 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
nyj001012 committed Jan 27, 2024
1 parent 2de0795 commit 802227d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions backend/src/v1/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export const create = async (req: Request, res: Response, next: NextFunction) =>
if (!pwSchema.validate(String(password))) {
return next(new ErrorResponse(errorCode.INVALIDATE_PASSWORD, status.BAD_REQUEST));
}
await usersService.createUser(String(email), await bcrypt.hash(String(password), 10));
return res.status(status.OK).send(`${email} created!`);
const result = await usersService.createUser(String(email), await bcrypt.hash(String(password), 10));
return res.status(status.OK).send(`${result.email} created!`);
} catch (error: any) {
const errorNumber = parseInt(error.message, 10);
if (errorNumber >= 200 && errorNumber < 300) {
Expand Down
4 changes: 3 additions & 1 deletion backend/src/v1/users/users.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
UserReservation,
User,
} from '~/entity/entities';
import { InsertResult } from "kysely";
import * as models from '../DTO/users.model';

export default class UsersRepository extends Repository<User> {
Expand Down Expand Up @@ -111,11 +112,12 @@ export default class UsersRepository extends Repository<User> {
async insertUser(email: string, password: string) {
const penaltyEndDate = new Date(0);
penaltyEndDate.setDate(penaltyEndDate.getDate() - 1);
await this.insert({
const result = await this.save({
email,
password,
penaltyEndDate: formatDate(penaltyEndDate),
});
return result;
}

async updateUser(id: number, values: {}): Promise<models.User> {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/v1/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ export default class UsersService {
if (emailCount > 0) {
throw new Error(errorCode.EMAIL_OVERLAP);
}
await this.usersRepository.insertUser(email, password);
return null;
const result = await this.usersRepository.insertUser(email, password);
return result;
}

async updateUserEmail(id: number, email: string) {
Expand Down

0 comments on commit 802227d

Please sign in to comment.