mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
added password return data
This commit is contained in:
@ -1,4 +1,9 @@
|
||||
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
|
||||
import {
|
||||
Injectable,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
BadRequestException,
|
||||
} from '@nestjs/common';
|
||||
import { TuyaContext } from '@tuya/tuya-connector-nodejs';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import {
|
||||
@ -83,7 +88,10 @@ export class DoorLockService {
|
||||
);
|
||||
}
|
||||
}
|
||||
async getOfflineMultipleTimeTemporaryPasswords(doorLockUuid: string) {
|
||||
async getOfflineMultipleTimeTemporaryPasswords(
|
||||
doorLockUuid: string,
|
||||
fromVisitor?: boolean,
|
||||
) {
|
||||
try {
|
||||
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
|
||||
|
||||
@ -99,11 +107,25 @@ export class DoorLockService {
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
'multiple',
|
||||
);
|
||||
|
||||
if (passwords.result.records.length > 0) {
|
||||
return convertKeysToCamelCase(passwords.result.records);
|
||||
if (!passwords.result.records.length && fromVisitor) {
|
||||
throw new BadRequestException();
|
||||
}
|
||||
if (passwords.result.records.length > 0) {
|
||||
return fromVisitor
|
||||
? convertKeysToCamelCase(passwords.result.records).map((password) => {
|
||||
return {
|
||||
passwodId: `${password.pwdId}`,
|
||||
passwodExpired: `${password.gmtExpired}`,
|
||||
passwordStart: `${password.gmtStart}`,
|
||||
passwordCreated: `${password.gmtCreate}`,
|
||||
passwodName: password.pwdName,
|
||||
passwordStatus: password.status,
|
||||
passwordType: 'OFFLINE_MULTIPLE',
|
||||
deviceUuid: doorLockUuid,
|
||||
};
|
||||
})
|
||||
: convertKeysToCamelCase(passwords.result.records);
|
||||
}
|
||||
|
||||
return passwords;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
@ -113,10 +135,12 @@ export class DoorLockService {
|
||||
);
|
||||
}
|
||||
}
|
||||
async getOfflineOneTimeTemporaryPasswords(doorLockUuid: string) {
|
||||
async getOfflineOneTimeTemporaryPasswords(
|
||||
doorLockUuid: string,
|
||||
fromVisitor?: boolean,
|
||||
) {
|
||||
try {
|
||||
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
|
||||
|
||||
if (!deviceDetails || !deviceDetails.deviceTuyaUuid) {
|
||||
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
||||
} else if (deviceDetails.productDevice.prodType !== ProductType.DL) {
|
||||
@ -129,9 +153,24 @@ export class DoorLockService {
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
'once',
|
||||
);
|
||||
|
||||
if (!passwords.result.records.length && fromVisitor) {
|
||||
throw new BadRequestException();
|
||||
}
|
||||
if (passwords.result.records.length > 0) {
|
||||
return convertKeysToCamelCase(passwords.result.records);
|
||||
return fromVisitor
|
||||
? convertKeysToCamelCase(passwords.result.records).map((password) => {
|
||||
return {
|
||||
passwodId: `${password.pwdId}`,
|
||||
passwodExpired: `${password.gmtExpired}`,
|
||||
passwordStart: `${password.gmtStart}`,
|
||||
passwordCreated: `${password.gmtCreate}`,
|
||||
passwodName: password.pwdName,
|
||||
passwordStatus: password.status,
|
||||
passwordType: 'OFFLINE_ONETIME',
|
||||
deviceUuid: doorLockUuid,
|
||||
};
|
||||
})
|
||||
: convertKeysToCamelCase(passwords.result.records);
|
||||
}
|
||||
|
||||
return passwords;
|
||||
@ -142,7 +181,10 @@ export class DoorLockService {
|
||||
);
|
||||
}
|
||||
}
|
||||
async getOnlineTemporaryPasswords(doorLockUuid: string) {
|
||||
async getOnlineTemporaryPasswords(
|
||||
doorLockUuid: string,
|
||||
fromVisitor?: boolean,
|
||||
) {
|
||||
try {
|
||||
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
|
||||
|
||||
@ -157,8 +199,7 @@ export class DoorLockService {
|
||||
const passwords = await this.getOnlineTemporaryPasswordsTuya(
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
);
|
||||
|
||||
if (passwords.result.length > 0) {
|
||||
if (passwords.result?.length > 0) {
|
||||
const passwordFiltered = passwords.result
|
||||
.filter((item) => item.type === 0)
|
||||
.map((password: any) => {
|
||||
@ -181,9 +222,24 @@ export class DoorLockService {
|
||||
return password;
|
||||
});
|
||||
|
||||
return convertKeysToCamelCase(passwordFiltered);
|
||||
return fromVisitor
|
||||
? convertKeysToCamelCase(passwordFiltered).map((password) => {
|
||||
return {
|
||||
passwodId: `${password.id}`,
|
||||
passwodExpired: `${password.invalidTime}`,
|
||||
passwordStart: `${password.effectiveTime}`,
|
||||
passwordCreated: '',
|
||||
passwodName: password.name,
|
||||
passwordStatus: '',
|
||||
passwordType: 'ONLINE_MULTIPLE',
|
||||
deviceUuid: doorLockUuid,
|
||||
};
|
||||
})
|
||||
: convertKeysToCamelCase(passwordFiltered);
|
||||
}
|
||||
if (fromVisitor) {
|
||||
throw new BadRequestException();
|
||||
}
|
||||
|
||||
return passwords;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
@ -192,8 +248,10 @@ export class DoorLockService {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async getOnlineTemporaryPasswordsOneTime(doorLockUuid: string) {
|
||||
async getOnlineTemporaryPasswordsOneTime(
|
||||
doorLockUuid: string,
|
||||
fromVisitor?: boolean,
|
||||
) {
|
||||
try {
|
||||
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
|
||||
|
||||
@ -208,8 +266,7 @@ export class DoorLockService {
|
||||
const passwords = await this.getOnlineTemporaryPasswordsTuya(
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
);
|
||||
|
||||
if (passwords.result.length > 0) {
|
||||
if (passwords.result?.length > 0) {
|
||||
const passwordFiltered = passwords.result
|
||||
.filter((item) => item.type === 1)
|
||||
.map((password: any) => {
|
||||
@ -232,9 +289,24 @@ export class DoorLockService {
|
||||
return password;
|
||||
});
|
||||
|
||||
return convertKeysToCamelCase(passwordFiltered);
|
||||
return fromVisitor
|
||||
? convertKeysToCamelCase(passwordFiltered).map((password) => {
|
||||
return {
|
||||
passwodId: `${password.id}`,
|
||||
passwodExpired: `${password.invalidTime}`,
|
||||
passwordStart: `${password.effectiveTime}`,
|
||||
passwordCreated: '',
|
||||
passwodName: password.name,
|
||||
passwordStatus: '',
|
||||
passwordType: 'ONLINE_ONETIME',
|
||||
deviceUuid: doorLockUuid,
|
||||
};
|
||||
})
|
||||
: convertKeysToCamelCase(passwordFiltered);
|
||||
}
|
||||
if (fromVisitor) {
|
||||
throw new BadRequestException();
|
||||
}
|
||||
|
||||
return passwords;
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
|
@ -49,8 +49,8 @@ export class VisitorPasswordController {
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
// @ApiBearerAuth()
|
||||
// @UseGuards(JwtAuthGuard)
|
||||
@Post('temporary-password/online/one-time')
|
||||
async addOnlineTemporaryPassword(
|
||||
@Body() addDoorLockOnlineOneTimeDto: AddDoorLockOnlineOneTimeDto,
|
||||
|
@ -417,38 +417,21 @@ export class VisitorPasswordService {
|
||||
deviceIds.forEach((deviceId) => {
|
||||
data.push(
|
||||
this.doorLockService
|
||||
.getOfflineMultipleTimeTemporaryPasswords(deviceId.uuid)
|
||||
.getOfflineMultipleTimeTemporaryPasswords(deviceId.uuid, true)
|
||||
.catch(() => {}),
|
||||
this.doorLockService
|
||||
.getOnlineTemporaryPasswordsOneTime(deviceId.uuid)
|
||||
.getOnlineTemporaryPasswordsOneTime(deviceId.uuid, true)
|
||||
.catch(() => {}),
|
||||
this.doorLockService
|
||||
.getOnlineTemporaryPasswords(deviceId.uuid)
|
||||
.getOnlineTemporaryPasswords(deviceId.uuid, true)
|
||||
.catch(() => {}),
|
||||
this.doorLockService
|
||||
.getOfflineOneTimeTemporaryPasswords(deviceId.uuid)
|
||||
.getOfflineOneTimeTemporaryPasswords(deviceId.uuid, true)
|
||||
.catch(() => {}),
|
||||
);
|
||||
});
|
||||
return (await Promise.all(data)).flat().map((item) => {
|
||||
return {
|
||||
id: item.pwdId || item.id || null,
|
||||
name: item.pwdName || item.name || '',
|
||||
type: item.pwdTypeCode || item.type || '',
|
||||
startTime: item.gmtStart || item.effectiveTime || null,
|
||||
endTime: item.gmtExpired || item.invalidTime || null,
|
||||
status: item.status || item.success || null,
|
||||
additionalInfo: {
|
||||
optUid: item.optUid || null,
|
||||
hasClearPwd: item.hasClearPwd || false,
|
||||
phase: item.phase || null,
|
||||
phone: item.phone || '',
|
||||
timeZone: item.timeZone || '',
|
||||
result: item.result || null,
|
||||
tid: item.tid || null,
|
||||
t: item.t || null,
|
||||
},
|
||||
};
|
||||
return (await Promise.all(data)).flat().filter((datum) => {
|
||||
return datum != null;
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user