From 5c039a5d2bea4eeb4666c2fa1207a6e6320255c4 Mon Sep 17 00:00:00 2001 From: Alberto Paganelli Date: Mon, 29 Jan 2024 17:48:30 +0100 Subject: [PATCH 1/6] wip: port numbers in helper and in alarm service --- alarm/src/index.ts | 2 +- frontend/src/env.d.ts | 2 ++ frontend/src/utils/RequestHelper.ts | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/alarm/src/index.ts b/alarm/src/index.ts index 8798231de..9220acc85 100644 --- a/alarm/src/index.ts +++ b/alarm/src/index.ts @@ -16,7 +16,7 @@ export const app: Express = express() app.use(express.json()) app.use(cors()) -const PORT: number = Number(process.env.PORT) || 4000 +const PORT: number = Number(process.env.ALARM_PORT) || 4002 app.use((req: Request, res: Response, next: NextFunction) => { const authHeader = req.headers.authorization diff --git a/frontend/src/env.d.ts b/frontend/src/env.d.ts index 7619ad8e5..61b7e8dfe 100644 --- a/frontend/src/env.d.ts +++ b/frontend/src/env.d.ts @@ -6,6 +6,8 @@ interface ImportMetaEnv { readonly VITE_MONITORING_PORT: string readonly VITE_AUTH_HOST: string readonly VITE_AUTH_PORT: string + readonly VITE_ALARM_HOST: string + readonly VITE_ALARM_PORT: string } interface ImportMeta { diff --git a/frontend/src/utils/RequestHelper.ts b/frontend/src/utils/RequestHelper.ts index ec8a208aa..1b9cd46f8 100644 --- a/frontend/src/utils/RequestHelper.ts +++ b/frontend/src/utils/RequestHelper.ts @@ -14,10 +14,15 @@ type Headers = { export const authHost: string = import.meta.env.VITE_AUTH_HOST || 'localhost' export const authPort: string = import.meta.env.VITE_AUTH_PORT || '4000' +export const monitoringHost: string = import.meta.env.VITE_MONITORING_HOST || 'localhost' +export const monitoringPort: string = import.meta.env.VITE_MONITORING_PORT || '4001' +export const alarmHost: string = import.meta.env.VITE_ALARM_HOST || 'localhost' +export const alarmPort: string = import.meta.env.VITE_ALARM_PORT || '4002' + export default class RequestHelper { static getHeaders(): Headers { - return { headers: { Authorization: `Bearer ${userStore().accessToken}` } } + return { headers: { Authorization: `Bearer apikey-dev` } } //${userStore().accessToken} } static async get(url: string, params?: any): Promise { From 78de8dc0540e426d9dc5525d6f4624950d519d2c Mon Sep 17 00:00:00 2001 From: Alberto Paganelli Date: Mon, 29 Jan 2024 18:34:09 +0100 Subject: [PATCH 2/6] wip: deletion and get devices --- .../device/repositories/DeviceRepository.ts | 4 +- .../storage/device/DeviceRepositoryImpl.ts | 45 +++--- frontend/src/views/DevicesView.vue | 134 ++++++++++++------ frontend/src/views/SecurityRuleView.vue | 2 - monitoring/src/consumer.ts | 16 +-- monitoring/src/controller/device.ts | 10 +- monitoring/src/routes/device.ts | 19 ++- 7 files changed, 139 insertions(+), 91 deletions(-) diff --git a/domain/src/domain/device/repositories/DeviceRepository.ts b/domain/src/domain/device/repositories/DeviceRepository.ts index 7f23d38ef..21be7830d 100644 --- a/domain/src/domain/device/repositories/DeviceRepository.ts +++ b/domain/src/domain/device/repositories/DeviceRepository.ts @@ -22,5 +22,7 @@ export interface DeviceRepository { updateSensor(sensor: Sensor): Promise - deleteDevice(deviceId: DeviceId): Promise + deleteCamera(code: string): Promise + + deleteSensor(code: string): Promise } diff --git a/domain/src/storage/device/DeviceRepositoryImpl.ts b/domain/src/storage/device/DeviceRepositoryImpl.ts index 2916f44e4..fdbb1cc66 100644 --- a/domain/src/storage/device/DeviceRepositoryImpl.ts +++ b/domain/src/storage/device/DeviceRepositoryImpl.ts @@ -142,30 +142,25 @@ export class DeviceRepositoryImpl implements DeviceRepository { .orFail() } - async deleteDevice(deviceId: DeviceId): Promise { - switch (deviceId.type) { - case DeviceType.CAMERA: - await this.cameraModel - .deleteOne({ - _id: { - type: DeviceTypeConverter.convertToString(deviceId.type), - code: deviceId.code - } - }) - .orFail() - break - case DeviceType.SENSOR: - await this.sensorModel - .deleteOne({ - _id: { - type: DeviceTypeConverter.convertToString(deviceId.type), - code: deviceId.code - } - }) - .orFail() - break - default: - throw new Error('Error while deleting device') - } + async deleteCamera(code: string): Promise { + await this.cameraModel + .deleteOne({ + _id: { + type: "CAMERA", + code: code + } + }) + .orFail() + } + + async deleteSensor(code: string): Promise { + await this.sensorModel + .deleteOne({ + _id: { + type: "SENSOR", + code: code + } + }) + .orFail() } } diff --git a/frontend/src/views/DevicesView.vue b/frontend/src/views/DevicesView.vue index f959b3761..75bb97951 100644 --- a/frontend/src/views/DevicesView.vue +++ b/frontend/src/views/DevicesView.vue @@ -1,6 +1,6 @@ @@ -104,7 +145,8 @@ const popupVisible = ref(false) /> - + +