mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-17 03:05:13 +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 { TuyaContext } from '@tuya/tuya-connector-nodejs';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import {
|
import {
|
||||||
@ -83,7 +88,10 @@ export class DoorLockService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async getOfflineMultipleTimeTemporaryPasswords(doorLockUuid: string) {
|
async getOfflineMultipleTimeTemporaryPasswords(
|
||||||
|
doorLockUuid: string,
|
||||||
|
fromVisitor?: boolean,
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
|
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
|
||||||
|
|
||||||
@ -99,11 +107,25 @@ export class DoorLockService {
|
|||||||
deviceDetails.deviceTuyaUuid,
|
deviceDetails.deviceTuyaUuid,
|
||||||
'multiple',
|
'multiple',
|
||||||
);
|
);
|
||||||
|
if (!passwords.result.records.length && fromVisitor) {
|
||||||
if (passwords.result.records.length > 0) {
|
throw new BadRequestException();
|
||||||
return convertKeysToCamelCase(passwords.result.records);
|
}
|
||||||
|
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;
|
return passwords;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
@ -113,10 +135,12 @@ export class DoorLockService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async getOfflineOneTimeTemporaryPasswords(doorLockUuid: string) {
|
async getOfflineOneTimeTemporaryPasswords(
|
||||||
|
doorLockUuid: string,
|
||||||
|
fromVisitor?: boolean,
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
|
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
|
||||||
|
|
||||||
if (!deviceDetails || !deviceDetails.deviceTuyaUuid) {
|
if (!deviceDetails || !deviceDetails.deviceTuyaUuid) {
|
||||||
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
||||||
} else if (deviceDetails.productDevice.prodType !== ProductType.DL) {
|
} else if (deviceDetails.productDevice.prodType !== ProductType.DL) {
|
||||||
@ -129,9 +153,24 @@ export class DoorLockService {
|
|||||||
deviceDetails.deviceTuyaUuid,
|
deviceDetails.deviceTuyaUuid,
|
||||||
'once',
|
'once',
|
||||||
);
|
);
|
||||||
|
if (!passwords.result.records.length && fromVisitor) {
|
||||||
|
throw new BadRequestException();
|
||||||
|
}
|
||||||
if (passwords.result.records.length > 0) {
|
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;
|
return passwords;
|
||||||
@ -142,7 +181,10 @@ export class DoorLockService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async getOnlineTemporaryPasswords(doorLockUuid: string) {
|
async getOnlineTemporaryPasswords(
|
||||||
|
doorLockUuid: string,
|
||||||
|
fromVisitor?: boolean,
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
|
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
|
||||||
|
|
||||||
@ -157,8 +199,7 @@ export class DoorLockService {
|
|||||||
const passwords = await this.getOnlineTemporaryPasswordsTuya(
|
const passwords = await this.getOnlineTemporaryPasswordsTuya(
|
||||||
deviceDetails.deviceTuyaUuid,
|
deviceDetails.deviceTuyaUuid,
|
||||||
);
|
);
|
||||||
|
if (passwords.result?.length > 0) {
|
||||||
if (passwords.result.length > 0) {
|
|
||||||
const passwordFiltered = passwords.result
|
const passwordFiltered = passwords.result
|
||||||
.filter((item) => item.type === 0)
|
.filter((item) => item.type === 0)
|
||||||
.map((password: any) => {
|
.map((password: any) => {
|
||||||
@ -181,9 +222,24 @@ export class DoorLockService {
|
|||||||
return password;
|
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;
|
return passwords;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
@ -192,8 +248,10 @@ export class DoorLockService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async getOnlineTemporaryPasswordsOneTime(
|
||||||
async getOnlineTemporaryPasswordsOneTime(doorLockUuid: string) {
|
doorLockUuid: string,
|
||||||
|
fromVisitor?: boolean,
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
|
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
|
||||||
|
|
||||||
@ -208,8 +266,7 @@ export class DoorLockService {
|
|||||||
const passwords = await this.getOnlineTemporaryPasswordsTuya(
|
const passwords = await this.getOnlineTemporaryPasswordsTuya(
|
||||||
deviceDetails.deviceTuyaUuid,
|
deviceDetails.deviceTuyaUuid,
|
||||||
);
|
);
|
||||||
|
if (passwords.result?.length > 0) {
|
||||||
if (passwords.result.length > 0) {
|
|
||||||
const passwordFiltered = passwords.result
|
const passwordFiltered = passwords.result
|
||||||
.filter((item) => item.type === 1)
|
.filter((item) => item.type === 1)
|
||||||
.map((password: any) => {
|
.map((password: any) => {
|
||||||
@ -232,9 +289,24 @@ export class DoorLockService {
|
|||||||
return password;
|
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;
|
return passwords;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
|
@ -49,8 +49,8 @@ export class VisitorPasswordController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ApiBearerAuth()
|
// @ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
// @UseGuards(JwtAuthGuard)
|
||||||
@Post('temporary-password/online/one-time')
|
@Post('temporary-password/online/one-time')
|
||||||
async addOnlineTemporaryPassword(
|
async addOnlineTemporaryPassword(
|
||||||
@Body() addDoorLockOnlineOneTimeDto: AddDoorLockOnlineOneTimeDto,
|
@Body() addDoorLockOnlineOneTimeDto: AddDoorLockOnlineOneTimeDto,
|
||||||
|
@ -417,38 +417,21 @@ export class VisitorPasswordService {
|
|||||||
deviceIds.forEach((deviceId) => {
|
deviceIds.forEach((deviceId) => {
|
||||||
data.push(
|
data.push(
|
||||||
this.doorLockService
|
this.doorLockService
|
||||||
.getOfflineMultipleTimeTemporaryPasswords(deviceId.uuid)
|
.getOfflineMultipleTimeTemporaryPasswords(deviceId.uuid, true)
|
||||||
.catch(() => {}),
|
.catch(() => {}),
|
||||||
this.doorLockService
|
this.doorLockService
|
||||||
.getOnlineTemporaryPasswordsOneTime(deviceId.uuid)
|
.getOnlineTemporaryPasswordsOneTime(deviceId.uuid, true)
|
||||||
.catch(() => {}),
|
.catch(() => {}),
|
||||||
this.doorLockService
|
this.doorLockService
|
||||||
.getOnlineTemporaryPasswords(deviceId.uuid)
|
.getOnlineTemporaryPasswords(deviceId.uuid, true)
|
||||||
.catch(() => {}),
|
.catch(() => {}),
|
||||||
this.doorLockService
|
this.doorLockService
|
||||||
.getOfflineOneTimeTemporaryPasswords(deviceId.uuid)
|
.getOfflineOneTimeTemporaryPasswords(deviceId.uuid, true)
|
||||||
.catch(() => {}),
|
.catch(() => {}),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
return (await Promise.all(data)).flat().map((item) => {
|
return (await Promise.all(data)).flat().filter((datum) => {
|
||||||
return {
|
return datum != null;
|
||||||
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,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user