Devices can now subscribe to specific topics.

- Device can now become (in)active
- Error alert makes sound
- Alerts now execute function on click
This commit is contained in:
2020-11-14 21:15:05 +01:00
parent ab1b90d020
commit 8b54431449
20 changed files with 171 additions and 42 deletions

View File

@@ -1,9 +1,11 @@
import { Response } from "express";
import { logger } from "../app";
import { logger, rabbitmq } from "../app";
import { LivebeatRequest } from "../lib/request";
import { Beat } from "../models/beat/beat.model.";
import { Phone } from "../models/phone/phone.model";
export async function GetPhone(req: LivebeatRequest, res: Response) {
const phoneId: String = req.params['id'];
@@ -16,7 +18,7 @@ export async function GetPhone(req: LivebeatRequest, res: Response) {
// Check database for phone
const phone = await Phone.findOne({ androidId: phoneId, user: req.user?._id });
if (phone === undefined) {
if (phone === null) {
res.status(404).send();
return;
}
@@ -53,7 +55,7 @@ export async function PostPhone(req: LivebeatRequest, res: Response) {
}
// Create phone
await Phone.create({
const newPhone = await Phone.create({
androidId,
displayName,
modelName,
@@ -63,7 +65,8 @@ export async function PostPhone(req: LivebeatRequest, res: Response) {
active: false
});
logger.info(`New device (${displayName}) registered for ${req.user?.name}.`)
logger.info(`New device (${displayName}) registered for ${req.user?.name}.`);
rabbitmq.publish(req.user?.id, newPhone.toJSON(), 'phone_register')
res.status(200).send();
}