mirror of
https://github.com/vernu/textbee.git
synced 2026-05-18 13:24:50 -04:00
refactor(api): clean up code
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
constructor() {}
|
||||
}
|
||||
export class AppService {}
|
||||
|
||||
@@ -16,14 +16,6 @@ export class AuthService {
|
||||
@InjectModel(ApiKey.name) private apiKeyModel: Model<ApiKeyDocument>,
|
||||
) {}
|
||||
|
||||
async validateUser(_id: string): Promise<User | null> {
|
||||
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,
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -61,30 +61,17 @@ export class GatewayService {
|
||||
async sendSMS(deviceId: string, smsData: SendSMSInputDTO): Promise<any> {
|
||||
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),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user