Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/apis/reservations/reservation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ReservationsService {

await this.dogsService.findOneById({ id: dogId });

return await this.reservationsRepository.save({
const result = await this.reservationsRepository.save({
...createReservationInput,
shop: {
id: shopId,
Expand All @@ -68,6 +68,11 @@ export class ReservationsService {
id: dogId,
},
});

return this.reservationsRepository.findOne({
where: { id: result.id },
relations: ['dog', 'shop', 'user'],
});
}

// 예약 가능 여부 확인하기
Expand Down
Empty file.
20 changes: 10 additions & 10 deletions src/apis/shops/shops.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import { ShopsService } from './shops.service';
Shop, //
]),
ElasticsearchModule.register({
// node: 'http://elasticsearch:9200', // 로컬
node: 'http://elasticsearch:9200', // 로컬

// 배포
node: 'https://search-groomeong-elasticsearch-7mvk7xnf5m2a6tcx6p5ro5qste.ap-southeast-2.es.amazonaws.com:443',
auth: {
username: process.env.OPENSEARCH_ID,
password: process.env.OPENSEARCH_PWD,
},
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
// node: 'https://search-groomeong-elasticsearch-7mvk7xnf5m2a6tcx6p5ro5qste.ap-southeast-2.es.amazonaws.com:443',
// auth: {
// username: process.env.OPENSEARCH_ID,
// password: process.env.OPENSEARCH_PWD,
// },
// headers: {
// Accept: 'application/json',
// 'Content-Type': 'application/json',
// },
}),
],
providers: [
Expand Down
Empty file.
34 changes: 23 additions & 11 deletions src/apis/users/__test__/users.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('UsersService', () => {
let usersService: UsersService;
let mailerService: MailerService;
let cacheManager: Cache;
let mockUsersRepository: Repository<User>;

beforeEach(async () => {
const usersModule = await Test.createTestingModule({
Expand Down Expand Up @@ -88,6 +89,10 @@ describe('UsersService', () => {

mailerService = usersModule.get<MailerService>(MailerService);
usersService = usersModule.get<UsersService>(UsersService);

mockUsersRepository = usersModule.get<Repository<User>>(
getRepositoryToken(User),
);
});

describe('create', () => {
Expand Down Expand Up @@ -129,21 +134,11 @@ describe('UsersService', () => {
});

describe('mailerService', () => {
// it('send mail', async () => {
// const shoot = await mailerService.sendMail({
// to: '273hur4747@gmail.com',
// from: 'Test email',
// subject: '테스트코드 너무 어렵다..',
// text: 'Welcome to Hell',
// });
// expect(shoot).();
// });

it('sendTokenEmail', async () => {
const myData = {
name: '철수',
email: 'bbb@bbb.com',
password: '1234',
hasedPassword: '1234',
phone: '01012341234',
};

Expand Down Expand Up @@ -195,4 +190,21 @@ describe('UsersService', () => {
}
});
});

describe('update', () => {
it('업데이트가 잘 되었는지 확인', async () => {
const myData = {
id: '1',
email: 'a@a.com',
password: '1111',
name: '짱구2',
phone: '01022221237',
};

const user = await usersService.findOne({ userId: myData.id });
const result = await mockUsersRepository.save({ ...myData });

expect(myData).toEqual(result);
});
});
});
5 changes: 5 additions & 0 deletions src/apis/users/interface/users.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ export interface IUsersServiceCheckToken {
export interface IUsersServiceDuplicationEmail {
email: string;
}

export interface IUsersServiceUpdatePwd {
userId: string;
updateUserInput: UpdateUserInput;
}
8 changes: 5 additions & 3 deletions src/apis/users/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
IUsersServiceSendEmail,
IUsersServiceSendTokenEmail,
IUsersServiceUpdate,
IUsersServiceUpdatePwd,
} from './interface/users.interface';
import { MailerService } from '@nestjs-modules/mailer';
import { sendTokenTemplate, welcomeTemplate } from 'src/commons/utils/utils';
Expand Down Expand Up @@ -178,16 +179,17 @@ export class UsersService {
updateUserInput,
}: IUsersServiceUpdate): Promise<User> {
const user = await this.findOne({ userId });

const hasedPassword = await bcrypt.hash(updateUserInput.password, 10);

const result = await this.userRepository.save({
...user,
...updateUserInput,
password: hasedPassword,
});
return result;
}

// 이메일 인증 후 비밀번호 수정
// updatePwdSendToken({ email, password }) {}

// 유저 삭제하기(삭제는 나중에)
async delete({
userId, //
Expand Down
5 changes: 4 additions & 1 deletion src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { Controller, Get, HttpException, UseFilters } from '@nestjs/common';
import { HttpExceptionFilter } from './commons/filter/http-exception.filter';

@Controller()
// @UseFilters()
export class AppController {
@Get('/')
getHello() {
// throw new HttpException('Bad Request', 400);
return '안녕하세요!';
}
}
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import { HttpExceptionFilter } from './commons/filter/http-exception.filter';
}),
CacheModule.register<RedisClientOptions>({
store: redisStore,
url: `redis://${process.env.REDIS_URL}:6379`,
url: `redis://${process.env.REDIS_HOST}:6379`,
isGlobal: true,
}),
],
Expand Down
21 changes: 11 additions & 10 deletions src/commons/filter/http-exception.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import {
ExceptionFilter,
HttpException,
} from '@nestjs/common';
import { Response } from 'express';
import { HttpArgumentsHost } from '@nestjs/common/interfaces';
import { Request, Response } from 'express';

@Catch(HttpException)
export class HttpExceptionFilter implements ExceptionFilter<HttpException> {
catch(exception: HttpException, host: ArgumentsHost) {
const ctx = host.switchToHttp();
const response = ctx.getResponse<Response>();
const request = ctx.getRequest();
const httpCtx = ctx as HttpArgumentsHost;
const response = httpCtx.getResponse();
const request = httpCtx.getRequest();
const status = exception.getStatus();
// const message = exception.message;
const message = exception.message || 'Unexpected error occurred';
const timestamp = new Date().toLocaleString('en-US', {
timeZone: 'Asia/Seoul',
Expand All @@ -25,11 +26,11 @@ export class HttpExceptionFilter implements ExceptionFilter<HttpException> {
console.log('예외코드:', status);
console.log('============');

response.status(status).json({
status,
timestamp,
message,
path: request.url,
});
// response.status(status).json({
// status,
// timestamp,
// message,
// path: request.url,
// });
}
}