Skip to content

Commit 1575377

Browse files
authored
Merge pull request #24 from Mala1180/feature/devices-frontend
feature/devices-frontend
2 parents 21cbe83 + 8e104dc commit 1575377

File tree

13 files changed

+227
-163
lines changed

13 files changed

+227
-163
lines changed

alarm/db/alarm-init.js

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ db.createCollection('anomaly')
44

55
db.anomaly.insert([
66
{
7-
_id: '65b514200718dbb3580fb9e6',
7+
_id: ObjectId('65b514200718dbb3580fb9e6'),
88
deviceId: {
99
type: 'SENSOR',
1010
code: 'sen-01'
@@ -17,7 +17,7 @@ db.anomaly.insert([
1717
__v: 0
1818
},
1919
{
20-
_id: '65b514240718dbb3580fb9e8',
20+
_id: ObjectId('65b514240718dbb3580fb9e8'),
2121
deviceId: {
2222
type: 'CAMERA',
2323
code: 'cam-03'
@@ -34,17 +34,17 @@ db.createCollection('notification')
3434

3535
db.notification.insert([
3636
{
37-
_id: '65b5113633b1c7e038248937',
38-
anomalyId: '65b514200718dbb3580fb9e6',
37+
_id: ObjectId('65b5113633b1c7e038248937'),
38+
anomalyId: ObjectId('65b514200718dbb3580fb9e6'),
3939
anomalyType: 'EXCEEDING',
4040
timestamp: {
4141
$date: '2024-01-27T14:20:38.950Z'
4242
},
4343
__v: 0
4444
},
4545
{
46-
_id: '65b513ef0718dbb3580fb9e3',
47-
anomalyId: '65b514240718dbb3580fb9e8',
46+
_id: ObjectId('65b513ef0718dbb3580fb9e3'),
47+
anomalyId: ObjectId('65b514240718dbb3580fb9e8'),
4848
anomalyType: 'INTRUSION',
4949
timestamp: {
5050
$date: '2024-01-27T14:32:15.925Z'
@@ -56,30 +56,24 @@ db.notification.insert([
5656
db.createCollection('securityRule')
5757
db.securityRule.insert([
5858
{
59-
_id: '65b527590fa38e9a5422537c',
59+
_id: ObjectId('65b527590fa38e9a5422537c'),
6060
deviceId: {
6161
type: 'SENSOR',
6262
code: 'sen-01'
6363
},
64-
creatorId: 'aaaaaaaaaaaaaaaaaaaaaaaa',
64+
creatorId: ObjectId('aaaaaaaaaaaaaaaaaaaaaaaa'),
6565
description: 'Exceeding rule description',
6666
minValue: 0,
6767
maxValue: 25,
6868
measure: 'TEMPERATURE',
6969
contacts: [
7070
{
7171
type: 'SMS',
72-
value: '3333333333',
73-
_id: {
74-
$oid: '65b527590fa38e9a5422537d'
75-
}
72+
value: '3333333333'
7673
},
7774
{
7875
type: 'EMAIL',
79-
80-
_id: {
81-
$oid: '65b527590fa38e9a5422537e'
82-
}
76+
8377
}
8478
],
8579
from: {
@@ -91,28 +85,22 @@ db.securityRule.insert([
9185
__v: 0
9286
},
9387
{
94-
_id: '65b52e53cffd8e469604ef10',
88+
_id: ObjectId('65b52e53cffd8e469604ef10'),
9589
deviceId: {
9690
type: 'CAMERA',
9791
code: 'cam-01'
9892
},
99-
creatorId: 'aaaaaaaaaaaaaaaaaaaaaaab',
93+
creatorId: ObjectId('aaaaaaaaaaaaaaaaaaaaaaab'),
10094
description: 'Intrusion rule description',
10195
objectClass: 'PERSON',
10296
contacts: [
10397
{
10498
type: 'SMS',
105-
value: '3333333333',
106-
_id: {
107-
$oid: '65b52e53cffd8e469604ef11'
108-
}
99+
value: '3333333333'
109100
},
110101
{
111102
type: 'EMAIL',
112-
113-
_id: {
114-
$oid: '65b52e53cffd8e469604ef12'
115-
}
103+
116104
}
117105
],
118106
from: {
@@ -129,43 +117,31 @@ db.createCollection('recognizingNode')
129117

130118
db.recognizingNode.insert([
131119
{
132-
_id: '65a020d5de7178fe501e7dda',
120+
_id: ObjectId('65a020d5de7178fe501e7dda'),
133121
ipAddress: '192.168.1.2',
134122
deviceIds: [
135123
{
136124
type: 'CAMERA',
137-
code: 'cam-01',
138-
_id: {
139-
$oid: '65a10044aa628f95323324a9'
140-
}
125+
code: 'cam-01'
141126
},
142127
{
143128
type: 'SENSOR',
144-
code: 'sen-01',
145-
_id: {
146-
$oid: '65a10044aa628f95323324aa'
147-
}
129+
code: 'sen-01'
148130
}
149131
],
150132
__v: 0
151133
},
152134
{
153-
_id: '65a020d5de7178fe501e7ddb',
135+
_id: ObjectId('65a020d5de7178fe501e7ddb'),
154136
ipAddress: '192.168.1.2',
155137
deviceIds: [
156138
{
157139
type: 'CAMERA',
158-
code: 'cam-02',
159-
_id: {
160-
$oid: '65a10044aa628f95323324b9'
161-
}
140+
code: 'cam-02'
162141
},
163142
{
164143
type: 'SENSOR',
165-
code: 'sen-02',
166-
_id: {
167-
$oid: '65a10044aa628f95323324ac'
168-
}
144+
code: 'sen-02'
169145
}
170146
],
171147
__v: 0

alarm/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const app: Express = express()
1616
app.use(express.json())
1717
app.use(cors())
1818

19-
const PORT: number = Number(process.env.PORT) || 4000
19+
const PORT: number = Number(process.env.ALARM_PORT) || 4002
2020

2121
app.use((req: Request, res: Response, next: NextFunction) => {
2222
const authHeader = req.headers.authorization

auth/db/auth-init.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ db.createCollection('user')
44
//TODO to test
55
db.user.insertMany([
66
{
7-
_id: 'aaaaaaaaaaaaaaaaaaaaaaaa',
7+
_id: ObjectId('aaaaaaaaaaaaaaaaaaaaaaaa'),
88
name: 'Mattia',
99
surname: 'Matteini',
1010
username: 'mattia',
@@ -18,7 +18,7 @@ db.user.insertMany([
1818
]
1919
},
2020
{
21-
_id: 'aaaaaaaaaaaaaaaaaaaaaaab',
21+
_id: ObjectId('aaaaaaaaaaaaaaaaaaaaaaab'),
2222
name: 'Mario',
2323
surname: 'Rossi',
2424
username: 'paga16',

domain/src/domain/device/repositories/DeviceRepository.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ export interface DeviceRepository {
2222

2323
updateSensor(sensor: Sensor): Promise<void>
2424

25-
deleteDevice(deviceId: DeviceId): Promise<void>
25+
deleteCamera(code: string): Promise<void>
26+
27+
deleteSensor(code: string): Promise<void>
2628
}

domain/src/storage/device/DeviceRepositoryImpl.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -142,30 +142,25 @@ export class DeviceRepositoryImpl implements DeviceRepository {
142142
.orFail()
143143
}
144144

145-
async deleteDevice(deviceId: DeviceId): Promise<void> {
146-
switch (deviceId.type) {
147-
case DeviceType.CAMERA:
148-
await this.cameraModel
149-
.deleteOne({
150-
_id: {
151-
type: DeviceTypeConverter.convertToString(deviceId.type),
152-
code: deviceId.code
153-
}
154-
})
155-
.orFail()
156-
break
157-
case DeviceType.SENSOR:
158-
await this.sensorModel
159-
.deleteOne({
160-
_id: {
161-
type: DeviceTypeConverter.convertToString(deviceId.type),
162-
code: deviceId.code
163-
}
164-
})
165-
.orFail()
166-
break
167-
default:
168-
throw new Error('Error while deleting device')
169-
}
145+
async deleteCamera(code: string): Promise<void> {
146+
await this.cameraModel
147+
.deleteOne({
148+
_id: {
149+
type: 'CAMERA',
150+
code: code
151+
}
152+
})
153+
.orFail()
154+
}
155+
156+
async deleteSensor(code: string): Promise<void> {
157+
await this.sensorModel
158+
.deleteOne({
159+
_id: {
160+
type: 'SENSOR',
161+
code: code
162+
}
163+
})
164+
.orFail()
170165
}
171166
}

frontend/src/components/devices/NewDevicePopup.vue

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
<script setup lang="ts">
22
import { Measure } from 'domain/dist/domain/device/core/impl/enum/Measure'
3-
import { ref } from 'vue'
4-
import { DeviceType } from '@domain/device/core'
3+
import { ref, toRaw } from 'vue'
4+
import { type Camera, DeviceType, type Sensor } from '@domain/device/core'
55
import type { DeviceFactory, DeviceIdFactory, ResolutionFactory } from '@domain/device/factories'
66
import {
77
DeviceFactoryImpl,
88
DeviceIdFactoryImpl,
99
ResolutionFactoryImpl
1010
} from '@domain/device/factories'
11+
import { AnomalyType } from 'domain/dist/domain/anomaly/core'
12+
import type { ExceedingRule, IntrusionRule } from 'domain/dist/domain/security-rule/core'
13+
import type { Contact } from 'domain/dist/domain/monitoring/core'
1114
1215
const emit = defineEmits<{
1316
(e: 'update-devices'): void
17+
(e: 'insert-camera', camera: Camera): void
18+
(e: 'insert-sensor', sensor: Sensor): void
1419
}>()
1520
1621
const deviceIdFactory: DeviceIdFactory = new DeviceIdFactoryImpl()
@@ -41,24 +46,21 @@ const options = ref([
4146
4247
const addNewDevice = () => {
4348
if (deviceType.value == DeviceType.SENSOR) {
44-
console.log(
45-
deviceFactory.createSensor(
46-
deviceIdFactory.createSensorId(code),
47-
ipAddress,
48-
intervalMillis,
49-
measures.value
50-
)
49+
const newSensor: Sensor = deviceFactory.createSensor(
50+
deviceIdFactory.createSensorId(code.value),
51+
ipAddress.value,
52+
intervalMillis.value,
53+
measures.value
5154
)
55+
emit('insert-sensor', newSensor)
5256
} else if (deviceType.value == DeviceType.CAMERA) {
53-
console.log(
54-
deviceFactory.createCamera(
55-
deviceIdFactory.createCameraId(code),
56-
ipAddress,
57-
resolutionFactory.createResolution(width, height)
58-
)
57+
const newCamera: Camera = deviceFactory.createCamera(
58+
deviceIdFactory.createCameraId(code.value),
59+
ipAddress.value,
60+
resolutionFactory.createResolution(width.value, height.value)
5961
)
62+
emit('insert-camera', newCamera)
6063
}
61-
emit('update-devices')
6264
}
6365
</script>
6466

frontend/src/env.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ interface ImportMetaEnv {
66
readonly VITE_MONITORING_PORT: string
77
readonly VITE_AUTH_HOST: string
88
readonly VITE_AUTH_PORT: string
9+
readonly VITE_ALARM_HOST: string
10+
readonly VITE_ALARM_PORT: string
911
}
1012

1113
interface ImportMeta {

frontend/src/utils/RequestHelper.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ type Headers = {
1414

1515
export const authHost: string = import.meta.env.VITE_AUTH_HOST || 'localhost'
1616
export const authPort: string = import.meta.env.VITE_AUTH_PORT || '4000'
17+
export const monitoringHost: string = import.meta.env.VITE_MONITORING_HOST || 'localhost'
18+
export const monitoringPort: string = import.meta.env.VITE_MONITORING_PORT || '4001'
19+
export const alarmHost: string = import.meta.env.VITE_ALARM_HOST || 'localhost'
20+
export const alarmPort: string = import.meta.env.VITE_ALARM_PORT || '4002'
1721

1822
export default class RequestHelper {
1923
static getHeaders(): Headers {
20-
return { headers: { Authorization: `Bearer ${userStore().accessToken}` } }
24+
return { headers: { Authorization: `Bearer apikey-dev` } } //${userStore().accessToken}
2125
}
2226

2327
static async get(url: string, params?: any): Promise<AxiosResponse> {

0 commit comments

Comments
 (0)