Skip to content

Commit

Permalink
wip: notification test
Browse files Browse the repository at this point in the history
  • Loading branch information
paga16-hash committed Jan 31, 2024
1 parent b26f647 commit 5f328bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,20 @@ import type { AnomalyFactory } from "domain/dist/domain/anomaly/factories";
import { AnomalyFactoryImpl } from "domain/dist/domain/anomaly/factories";
import type { DeviceIdFactory } from "domain/dist/domain/device/factories";
import { DeviceIdFactoryImpl } from "domain/dist/domain/device/factories";
import type { Notification } from "domain/dist/domain/alarm-system/core";

const notificationFactory: NotificationFactory = new NotificationFactoryImpl()
const anomalyFactory: AnomalyFactory = new AnomalyFactoryImpl()
const deviceIdFactory: DeviceIdFactory = new DeviceIdFactoryImpl()

export async function composeNotification(notification: any) {
await RequestHelper.get(`http://${alarmHost}:${alarmPort}/anomalies/` + notification.anomalyId)
.then((anomaly: any) => {
switch (DeviceTypeConverter.convertToDeviceType(anomaly.data.deviceId.type)) {
case DeviceType.CAMERA:
return notificationFactory.createIntrusionNotification(notification._id, composeIntrusion(anomaly.data))
case DeviceType.SENSOR:
return notificationFactory.createExceedingNotification(notification._id, composeExceeding(anomaly.data))
}
})
.catch(error => {
console.log(error)
})
export const composeNotification = async (notification: any): Promise<Notification> => {
const resAnomaly = await RequestHelper.get(`http://${alarmHost}:${alarmPort}/anomalies/` + notification.anomalyId)
switch (DeviceTypeConverter.convertToDeviceType(resAnomaly.data.deviceId.type)) {
case DeviceType.CAMERA:
return notificationFactory.createIntrusionNotification(notification._id, composeIntrusion(resAnomaly.data))
case DeviceType.SENSOR:
return notificationFactory.createExceedingNotification(notification._id, composeExceeding(resAnomaly.data))
}
}

function composeIntrusion(intrusion: any): Intrusion {
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/views/NotificationView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import RequestHelper, { alarmHost, alarmPort } from '@/utils/RequestHelper'
import NotificationBadge from '@/components/notification/NotificationBadge.vue'
import { composeNotification } from '@/scripts/presentation/notification/ComposeNotification'
let notifications: ref<Notification[]> = ref<Notification[]>([])
let notifications: ref<Notification[]> = ref([])
async function getNotifications() {
await RequestHelper.get(`http://${alarmHost}:${alarmPort}/notifications`)
.then((res: any) => {
notifications.value = []
//notifications.value = []
for (let i = 0; i < res.data.length; i++) {
console.log("AAAA")
console.log(composeNotification(res.data[i]))
notifications.value.push(composeNotification(res.data[i]))
}
})
Expand Down

0 comments on commit 5f328bf

Please sign in to comment.