Livebeat is now able to send, store and show beats
This commit is contained in:
30
backend/endpoints/beat.ts
Normal file
30
backend/endpoints/beat.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user