diff --git a/api/src/app.service.ts b/api/src/app.service.ts index 4e8f0ee..5965cb5 100644 --- a/api/src/app.service.ts +++ b/api/src/app.service.ts @@ -1,6 +1,4 @@ import { Injectable } from '@nestjs/common' @Injectable() -export class AppService { - constructor() {} -} +export class AppService {} diff --git a/api/src/auth/auth.service.ts b/api/src/auth/auth.service.ts index 8bf4dc2..f9bd127 100644 --- a/api/src/auth/auth.service.ts +++ b/api/src/auth/auth.service.ts @@ -16,14 +16,6 @@ export class AuthService { @InjectModel(ApiKey.name) private apiKeyModel: Model, ) {} - async validateUser(_id: string): Promise { - const user = await this.usersService.findOne({ _id }) - if (user) { - return user - } - return null - } - async login(userData: any) { const user = await this.usersService.findOne({ email: userData.email }) if (!user) { @@ -101,7 +93,7 @@ export class AuthService { const hashedApiKey = await bcrypt.hash(apiKey, 10) const newApiKey = new this.apiKeyModel({ - apiKey: apiKey.substr(0, 17) + '******************', + apiKey: apiKey.substr(0, 17) + '*'.repeat(18), hashedApiKey, user: currentUser._id, }) diff --git a/api/src/auth/guards/auth.guard.ts b/api/src/auth/guards/auth.guard.ts index bc8f5ed..5c929fe 100644 --- a/api/src/auth/guards/auth.guard.ts +++ b/api/src/auth/guards/auth.guard.ts @@ -45,7 +45,7 @@ export class AuthGuard implements CanActivate { } if (userId) { - const user = await this.authService.validateUser(userId) + const user = await this.usersService.findOne({ _id: userId }) if (user) { request.user = user return true diff --git a/api/src/gateway/gateway.service.ts b/api/src/gateway/gateway.service.ts index be053f9..bcbe1c0 100644 --- a/api/src/gateway/gateway.service.ts +++ b/api/src/gateway/gateway.service.ts @@ -61,30 +61,17 @@ export class GatewayService { async sendSMS(deviceId: string, smsData: SendSMSInputDTO): Promise { const device = await this.deviceModel.findById(deviceId) - if (!device) { - throw new HttpException( - { - error: 'Device not found', - }, - HttpStatus.NOT_FOUND, - ) - } - - if (!device.enabled) { + if (!device?.enabled) { throw new HttpException( { success: false, - error: 'Device is disabled', + error: 'Device does not exist or is not enabled', }, HttpStatus.BAD_REQUEST, ) } const payload: any = { - // notification: { - // title: 'SMS', - // body: 'message', - // }, data: { smsData: JSON.stringify(smsData), },