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

30
backend/endpoints/beat.ts Normal file
View File

@@ -0,0 +1,30 @@
import { Response } from "express";
import { logger } from "../app";
import { LivebeatRequest } from "../lib/request";
import { Beat } from "../models/beat/beat.model.";
import { Phone } from "../models/phone/phone.model";
export interface IFilter {
phone: string,
time: {
from: number,
to: number
},
max: number
}
export async function GetBeat(req: LivebeatRequest, res: Response) {
const filter: IFilter = req.body.filter as IFilter;
// If no filters are specified, we return the last 500 points. We take the first phone as default.
if (filter === undefined) {
const phone = await Phone.findOne({ user: req.user?._id });
logger.debug(`No filters were provided! Take ${phone?.displayName} as default.`);
if (phone !== undefined && phone !== null) {
logger.debug("Query for latest beats ...");
const beats = await Beat.find({ phone: phone._id }).limit(800).sort({ _id: -1 });
res.status(200).send(beats);
}
}
}