mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-14 18:05:48 +00:00
added devices and passwords of devices
This commit is contained in:
@ -192,6 +192,58 @@ export class DoorLockService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getOnlineTemporaryPasswordsOneTime(doorLockUuid: string) {
|
||||||
|
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) {
|
||||||
|
throw new HttpException(
|
||||||
|
'This is not a door lock device',
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const passwords = await this.getOnlineTemporaryPasswordsTuya(
|
||||||
|
deviceDetails.deviceTuyaUuid,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (passwords.result.length > 0) {
|
||||||
|
const passwordFiltered = passwords.result
|
||||||
|
.filter((item) => item.type === 1)
|
||||||
|
.map((password: any) => {
|
||||||
|
if (password.schedule_list?.length > 0) {
|
||||||
|
password.schedule_list = password.schedule_list.map(
|
||||||
|
(schedule) => {
|
||||||
|
schedule.working_day = this.getDaysFromWorkingDayValue(
|
||||||
|
schedule.working_day,
|
||||||
|
);
|
||||||
|
schedule.effective_time = this.minutesToTime(
|
||||||
|
schedule.effective_time,
|
||||||
|
);
|
||||||
|
schedule.invalid_time = this.minutesToTime(
|
||||||
|
schedule.invalid_time,
|
||||||
|
);
|
||||||
|
return schedule;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return password;
|
||||||
|
});
|
||||||
|
|
||||||
|
return convertKeysToCamelCase(passwordFiltered);
|
||||||
|
}
|
||||||
|
|
||||||
|
return passwords;
|
||||||
|
} catch (error) {
|
||||||
|
throw new HttpException(
|
||||||
|
error.message || 'Error getting online temporary passwords',
|
||||||
|
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async getOnlineTemporaryPasswordsTuya(
|
async getOnlineTemporaryPasswordsTuya(
|
||||||
doorLockUuid: string,
|
doorLockUuid: string,
|
||||||
): Promise<getPasswordInterface> {
|
): Promise<getPasswordInterface> {
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
HttpException,
|
HttpException,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
|
Get,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||||
import {
|
import {
|
||||||
@ -122,4 +123,26 @@ export class VisitorPasswordController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Get('')
|
||||||
|
async GetVisitorPassword() {
|
||||||
|
try {
|
||||||
|
return await this.visitorPasswordService.getPasswords();
|
||||||
|
} catch (error) {
|
||||||
|
throw new HttpException(
|
||||||
|
error.message || 'Internal server error',
|
||||||
|
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Get('/devices')
|
||||||
|
async GetVisitorDevices() {
|
||||||
|
try {
|
||||||
|
return await this.visitorPasswordService.getAllPassDevices();
|
||||||
|
} catch (error) {
|
||||||
|
throw new HttpException(
|
||||||
|
error.message || 'Internal server error',
|
||||||
|
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import {
|
|||||||
} from '../dtos';
|
} from '../dtos';
|
||||||
import { EmailService } from '@app/common/util/email.service';
|
import { EmailService } from '@app/common/util/email.service';
|
||||||
import { PasswordEncryptionService } from 'src/door-lock/services/encryption.services';
|
import { PasswordEncryptionService } from 'src/door-lock/services/encryption.services';
|
||||||
|
import { DoorLockService } from 'src/door-lock/services';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VisitorPasswordService {
|
export class VisitorPasswordService {
|
||||||
@ -24,6 +25,7 @@ export class VisitorPasswordService {
|
|||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
private readonly deviceRepository: DeviceRepository,
|
private readonly deviceRepository: DeviceRepository,
|
||||||
private readonly emailService: EmailService,
|
private readonly emailService: EmailService,
|
||||||
|
private readonly doorLockService: DoorLockService,
|
||||||
private readonly passwordEncryptionService: PasswordEncryptionService,
|
private readonly passwordEncryptionService: PasswordEncryptionService,
|
||||||
) {
|
) {
|
||||||
const accessKey = this.configService.get<string>('auth-config.ACCESS_KEY');
|
const accessKey = this.configService.get<string>('auth-config.ACCESS_KEY');
|
||||||
@ -403,6 +405,63 @@ export class VisitorPasswordService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async getPasswords() {
|
||||||
|
const deviceIds = await this.deviceRepository.find({
|
||||||
|
where: {
|
||||||
|
productDevice: {
|
||||||
|
prodType: ProductType.DL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const data = [];
|
||||||
|
deviceIds.forEach((deviceId) => {
|
||||||
|
data.push(
|
||||||
|
this.doorLockService
|
||||||
|
.getOfflineMultipleTimeTemporaryPasswords(deviceId.uuid)
|
||||||
|
.catch(() => {}),
|
||||||
|
this.doorLockService
|
||||||
|
.getOnlineTemporaryPasswordsOneTime(deviceId.uuid)
|
||||||
|
.catch(() => {}),
|
||||||
|
this.doorLockService
|
||||||
|
.getOnlineTemporaryPasswords(deviceId.uuid)
|
||||||
|
.catch(() => {}),
|
||||||
|
this.doorLockService
|
||||||
|
.getOfflineOneTimeTemporaryPasswords(deviceId.uuid)
|
||||||
|
.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,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAllPassDevices() {
|
||||||
|
return await this.deviceRepository.find({
|
||||||
|
where: {
|
||||||
|
productDevice: {
|
||||||
|
prodType: ProductType.DL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async addOnlineTemporaryPasswordOneTime(
|
async addOnlineTemporaryPasswordOneTime(
|
||||||
addDoorLockOnlineOneTimeDto: AddDoorLockOnlineOneTimeDto,
|
addDoorLockOnlineOneTimeDto: AddDoorLockOnlineOneTimeDto,
|
||||||
) {
|
) {
|
||||||
|
@ -6,8 +6,9 @@ import { DeviceRepositoryModule } from '@app/common/modules/device';
|
|||||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||||
import { EmailService } from '@app/common/util/email.service';
|
import { EmailService } from '@app/common/util/email.service';
|
||||||
import { PasswordEncryptionService } from 'src/door-lock/services/encryption.services';
|
import { PasswordEncryptionService } from 'src/door-lock/services/encryption.services';
|
||||||
|
import { DoorLockModule } from 'src/door-lock/door.lock.module';
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ConfigModule, DeviceRepositoryModule],
|
imports: [ConfigModule, DeviceRepositoryModule, DoorLockModule],
|
||||||
controllers: [VisitorPasswordController],
|
controllers: [VisitorPasswordController],
|
||||||
providers: [
|
providers: [
|
||||||
VisitorPasswordService,
|
VisitorPasswordService,
|
||||||
|
Reference in New Issue
Block a user