|
1 |
| -import { Injectable } from '@nestjs/common'; |
| 1 | +import { WeatherService } from '@app/weather/provider/weather.service'; |
| 2 | +import { BadRequestException, Injectable } from '@nestjs/common'; |
2 | 3 |
|
| 4 | +import { PrismaService } from '@src/prisma/prisma.service'; |
3 | 5 | import axios from 'axios';
|
4 | 6 | import * as crypto from 'crypto';
|
| 7 | +import { SMSApplyDto } from '../sms-apply.dto'; |
5 | 8 |
|
6 | 9 | @Injectable()
|
7 | 10 | export class SmsService {
|
8 | 11 | private ACCESS_KEY_ID = process.env.SENS_ACCESS_KEY;
|
9 | 12 | private SECRET_KEY = process.env.SENS_SECRET_KEY;
|
10 | 13 | private SERVICE_ID = process.env.SENS_SERVICE_ID;
|
| 14 | + |
| 15 | + constructor( |
| 16 | + private readonly weatherService: WeatherService, |
| 17 | + private readonly prisma: PrismaService, |
| 18 | + ) {} |
11 | 19 | // private headers = {
|
12 | 20 | // 'Content-Type': 'application/json;charset=UTF-8',
|
13 | 21 | // 'x-ncp-apigw-timestamp': Date.now().toString(),
|
@@ -74,4 +82,32 @@ export class SmsService {
|
74 | 82 | //this.logger.error(`Error occurred: ${error.message}`, error.stack);
|
75 | 83 | }
|
76 | 84 | }
|
| 85 | + |
| 86 | + async applyNotice(smsApplyDto: SMSApplyDto) { |
| 87 | + const { phone_number, longitude, latitude } = smsApplyDto; |
| 88 | + const { city } = await this.weatherService.getCity(latitude, longitude); |
| 89 | + if (city === 'non-city') |
| 90 | + throw new BadRequestException('존재하지 않는 지역입니다.'); |
| 91 | + |
| 92 | + return await this.prisma.user.upsert({ |
| 93 | + where: { |
| 94 | + phone_number, |
| 95 | + }, |
| 96 | + update: { |
| 97 | + city, |
| 98 | + }, |
| 99 | + create: { |
| 100 | + phone_number, |
| 101 | + city, |
| 102 | + }, |
| 103 | + }); |
| 104 | + } |
| 105 | + |
| 106 | + async getUserListByCity(city: string) { |
| 107 | + return await this.prisma.user.findMany({ |
| 108 | + where: { |
| 109 | + city, |
| 110 | + }, |
| 111 | + }); |
| 112 | + } |
77 | 113 | }
|
0 commit comments