add expired status for vistor pass

This commit is contained in:
faris Aljohari
2024-08-21 22:36:46 +03:00
parent c92f02dc99
commit adb9019749
3 changed files with 61 additions and 19 deletions

View File

@ -113,7 +113,7 @@ export class DoorLockController {
@Param('doorLockUuid') doorLockUuid: string,
) {
try {
return await this.doorLockService.getOnlineTemporaryPasswords(
return await this.doorLockService.getOnlineTemporaryPasswordsMultiple(
doorLockUuid,
);
} catch (error) {

View File

@ -92,6 +92,7 @@ export class DoorLockService {
async getOfflineMultipleTimeTemporaryPasswords(
doorLockUuid: string,
fromVisitor?: boolean,
isExpired?: boolean,
) {
try {
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
@ -107,6 +108,7 @@ export class DoorLockService {
const passwords = await this.getTemporaryOfflinePasswordsTuya(
deviceDetails.deviceTuyaUuid,
'multiple',
isExpired,
);
if (!passwords.result.records.length && fromVisitor) {
throw new BadRequestException();
@ -114,15 +116,20 @@ export class DoorLockService {
if (passwords.result.records.length > 0) {
return fromVisitor
? convertKeysToCamelCase(passwords.result.records).map((password) => {
const timestampInSeconds = Math.floor(Date.now() / 1000);
return {
passwordId: `${password.pwdId}`,
invalidTime: `${password.gmtExpired}`,
effectiveTime: `${password.gmtStart}`,
passwordCreated: `${password.gmtCreate}`,
createdTime: password.pwdName,
passwordStatus: `${password.status}`,
passwordType: 'OFFLINE_MULTIPLE',
deviceUuid: doorLockUuid,
passwordStatus: isExpired
? 'EXPIRED'
: timestampInSeconds > password.effectiveTime
? 'EFFECTIVE'
: 'TO_BE_EFFECTIVE',
};
})
: convertKeysToCamelCase(passwords.result.records);
@ -139,6 +146,7 @@ export class DoorLockService {
async getOfflineOneTimeTemporaryPasswords(
doorLockUuid: string,
fromVisitor?: boolean,
isExpired?: boolean,
) {
try {
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
@ -153,6 +161,7 @@ export class DoorLockService {
const passwords = await this.getTemporaryOfflinePasswordsTuya(
deviceDetails.deviceTuyaUuid,
'once',
isExpired,
);
if (!passwords.result.records.length && fromVisitor) {
throw new BadRequestException();
@ -160,15 +169,20 @@ export class DoorLockService {
if (passwords.result.records.length > 0) {
return fromVisitor
? convertKeysToCamelCase(passwords.result.records).map((password) => {
const timestampInSeconds = Math.floor(Date.now() / 1000);
return {
passwordId: `${password.pwdId}`,
invalidTime: `${password.gmtExpired}`,
effectiveTime: `${password.gmtStart}`,
createdTime: `${password.gmtCreate}`,
passwordName: password.pwdName,
passwordStatus: `${password.status}`,
passwordType: 'OFFLINE_ONETIME',
deviceUuid: doorLockUuid,
passwordStatus: isExpired
? 'EXPIRED'
: timestampInSeconds > password.gmtStart
? 'EFFECTIVE'
: 'TO_BE_EFFECTIVE',
};
})
: convertKeysToCamelCase(passwords.result.records);
@ -182,9 +196,10 @@ export class DoorLockService {
);
}
}
async getOnlineTemporaryPasswords(
async getOnlineTemporaryPasswordsMultiple(
doorLockUuid: string,
fromVisitor?: boolean,
isExpired?: boolean,
) {
try {
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
@ -197,8 +212,9 @@ export class DoorLockService {
HttpStatus.BAD_REQUEST,
);
}
const passwords = await this.getOnlineTemporaryPasswordsTuya(
const passwords = await this.getOnlineTemporaryPasswordsMultipleTuya(
deviceDetails.deviceTuyaUuid,
isExpired,
);
if (passwords.result?.length > 0) {
const passwordFiltered = passwords.result
@ -225,16 +241,21 @@ export class DoorLockService {
return fromVisitor
? convertKeysToCamelCase(passwordFiltered).map((password) => {
const timestampInSeconds = Math.floor(Date.now() / 1000);
return {
passwodId: `${password.id}`,
passwordId: `${password.id}`,
invalidTime: `${password.invalidTime}`,
effectiveTime: `${password.effectiveTime}`,
createdTime: '',
scheduleList: password?.scheduleList,
passwodName: password.name,
passwordStatus: '',
passwordName: password.name,
passwordType: 'ONLINE_MULTIPLE',
deviceUuid: doorLockUuid,
passwordStatus: isExpired
? 'EXPIRED'
: timestampInSeconds > password.effectiveTime
? 'EFFECTIVE'
: 'TO_BE_EFFECTIVE',
};
})
: convertKeysToCamelCase(passwordFiltered);
@ -253,6 +274,7 @@ export class DoorLockService {
async getOnlineTemporaryPasswordsOneTime(
doorLockUuid: string,
fromVisitor?: boolean,
isExpired?: boolean,
) {
try {
const deviceDetails = await this.getDeviceByDeviceUuid(doorLockUuid);
@ -265,8 +287,9 @@ export class DoorLockService {
HttpStatus.BAD_REQUEST,
);
}
const passwords = await this.getOnlineTemporaryPasswordsTuya(
const passwords = await this.getOnlineTemporaryPasswordsMultipleTuya(
deviceDetails.deviceTuyaUuid,
isExpired,
);
if (passwords.result?.length > 0) {
const passwordFiltered = passwords.result
@ -293,15 +316,20 @@ export class DoorLockService {
return fromVisitor
? convertKeysToCamelCase(passwordFiltered).map((password) => {
const timestampInSeconds = Math.floor(Date.now() / 1000);
return {
passwodId: `${password.id}`,
passwordId: `${password.id}`,
invalidTime: `${password.invalidTime}`,
effectiveTime: `${password.effectiveTime}`,
createdTime: '',
passwodName: password.name,
passwordStatus: '',
passwordName: password.name,
passwordType: 'ONLINE_ONETIME',
deviceUuid: doorLockUuid,
passwordStatus: isExpired
? 'EXPIRED'
: timestampInSeconds > password.effectiveTime
? 'EFFECTIVE'
: 'TO_BE_EFFECTIVE',
};
})
: convertKeysToCamelCase(passwordFiltered);
@ -318,11 +346,12 @@ export class DoorLockService {
}
}
async getOnlineTemporaryPasswordsTuya(
async getOnlineTemporaryPasswordsMultipleTuya(
doorLockUuid: string,
isExpired?: boolean,
): Promise<getPasswordInterface> {
try {
const path = `/v1.0/devices/${doorLockUuid}/door-lock/temp-passwords?valid=true`;
const path = `/v1.0/devices/${doorLockUuid}/door-lock/temp-passwords?valid=${!isExpired}`;
const response = await this.tuya.request({
method: 'GET',
@ -340,9 +369,10 @@ export class DoorLockService {
async getTemporaryOfflinePasswordsTuya(
doorLockUuid: string,
type: string,
isExpired?: boolean,
): Promise<getPasswordOfflineInterface> {
try {
const path = `/v1.0/devices/${doorLockUuid}/door-lock/offline-temp-password?pwd_type_codes=${type}&target_status=EFFECTIVE&page_no=1&page_size=100`;
const path = `/v1.0/devices/${doorLockUuid}/door-lock/offline-temp-password?pwd_type_codes=${type}&target_status=${isExpired ? 'INEFFECTIVE' : 'EFFECTIVE'}&page_no=1&page_size=100`;
const response = await this.tuya.request({
method: 'GET',

View File

@ -420,16 +420,28 @@ export class VisitorPasswordService {
deviceIds.forEach((deviceId) => {
data.push(
this.doorLockService
.getOnlineTemporaryPasswordsOneTime(deviceId.uuid, true)
.getOnlineTemporaryPasswordsOneTime(deviceId.uuid, true, false)
.catch(() => {}),
this.doorLockService
.getOnlineTemporaryPasswords(deviceId.uuid, true)
.getOnlineTemporaryPasswordsOneTime(deviceId.uuid, true, true)
.catch(() => {}),
this.doorLockService
.getOfflineOneTimeTemporaryPasswords(deviceId.uuid, true)
.getOnlineTemporaryPasswordsMultiple(deviceId.uuid, true, false)
.catch(() => {}),
this.doorLockService
.getOfflineMultipleTimeTemporaryPasswords(deviceId.uuid, true)
.getOnlineTemporaryPasswordsMultiple(deviceId.uuid, true, true)
.catch(() => {}),
this.doorLockService
.getOfflineOneTimeTemporaryPasswords(deviceId.uuid, true, true)
.catch(() => {}),
this.doorLockService
.getOfflineOneTimeTemporaryPasswords(deviceId.uuid, true, false)
.catch(() => {}),
this.doorLockService
.getOfflineMultipleTimeTemporaryPasswords(deviceId.uuid, true, true)
.catch(() => {}),
this.doorLockService
.getOfflineMultipleTimeTemporaryPasswords(deviceId.uuid, true, false)
.catch(() => {}),
);
});