Livebeat is now able to send, store and show beats

This commit is contained in:
2020-10-23 00:39:36 +02:00
parent f722ee9595
commit 13f8437f29
52 changed files with 1948 additions and 442 deletions

View File

@@ -0,0 +1,63 @@
import { Response } from "express";
import { logger } from "../app";
import { LivebeatRequest } from "../lib/request";
import { Phone } from "../models/phone/phone.model";
export async function GetPhone(req: LivebeatRequest, res: Response) {
const phoneId: String = req.params['id'];
if (phoneId === undefined) {
res.status(400).send();
return;
}
// Check database for phone
const phone = await Phone.findOne({ androidId: phoneId, user: req.user?._id });
if (phone === undefined) {
res.status(404).send();
return;
}
res.status(200).send(phone);
}
export async function PostPhone(req: LivebeatRequest, res: Response) {
const androidId: String = req.body.androidId;
const modelName: String = req.body.modelName;
const displayName: String = req.body.displayName;
const operatingSystem: String = req.body.operatingSystem;
const architecture: String = req.body.architecture;
if (androidId === undefined ||
modelName === undefined ||
displayName === undefined ||
operatingSystem === undefined ||
architecture === undefined) {
logger.debug("Request to /phone failed because of missing parameters.");
res.status(400).send();
return;
}
// Check if phone already exists
const phone = await Phone.findOne({ androidId, user: req.user?._id });
if (phone !== null) {
logger.debug("Request to /phone failed because phone already exists.");
res.status(409).send();
return;
}
// Create phone
await Phone.create({
androidId,
displayName,
modelName,
operatingSystem,
architecture,
user: req.user?._id
});
logger.info(`New device (${displayName}) registered for ${req.user?.name}.`)
res.status(200).send();
}