File tree Expand file tree Collapse file tree 4 files changed +681
-7
lines changed
Expand file tree Collapse file tree 4 files changed +681
-7
lines changed Original file line number Diff line number Diff line change 11const asyncHandler = require ( '@evnotify/utils' ) . asyncHandler ;
2- const SettingsModel = require ( '../models/Settings' ) ;
2+ const HistoryModel = require ( '../models/History' ) ;
3+ const SyncModel = require ( '../models/Sync' ) ;
34const errors = require ( '../errors.json' ) ;
45
5- const deleteSettings = asyncHandler ( async ( req , res , next ) => {
6- await SettingsModel . deleteOne ( {
7- akey : req . params . akey
8- } ) ;
6+ const submitData = asyncHandler ( async ( req , res , next ) => {
7+ // TODO outsource this in @evnotify /utils?!
8+ if ( req . params . akey !== req . headers . AKey ) return next ( errors . AKEY_MISMATCH ) ;
9+
10+ const syncObj = req . body ;
911
10- res . status ( 204 ) . end ( ) ;
12+ syncObj . akey = req . params . akey ;
13+ // create a history record
14+ await HistoryModel . create ( syncObj ) ;
15+ // sync to log?! trigger
16+ // update last sync
17+ res . json ( await SyncModel . updateOne ( {
18+ akey : req . params . akey
19+ } , req . body ) ) ;
1120} ) ;
1221
1322module . exports = {
Original file line number Diff line number Diff line change 1+ const mongoose = require ( 'mongoose' ) ;
2+ const connection = require ( '@evnotify/utils' ) . db . getDB ( ) ;
3+
4+ const TelemetrySchema = require ( './Telemetry' ) ;
5+ const LocationSchema = require ( './Location' ) ;
6+
7+ const options = {
8+ id : false ,
9+ collection : 'sync' ,
10+ timestamps : true ,
11+ toObject : {
12+ getters : true
13+ } ,
14+ versionKey : false
15+ } ;
16+
17+ const HistorySchema = new mongoose . Schema ( {
18+ akey : {
19+ type : String ,
20+ required : true
21+ } ,
22+ telemetry : TelemetrySchema ,
23+ location : LocationSchema
24+ } , options ) ;
25+
26+ module . exports = connection . model ( 'History' , HistorySchema ) ;
You can’t perform that action at this time.
0 commit comments