backend/app/models/api/OfflineDataSync.model.js
garrettmills 55a22a4f4c
All checks were successful
continuous-integration/drone/push Build is passing
Start /api/v1/offline/sync endpoint
2020-10-28 22:55:04 -05:00

38 lines
1.2 KiB
JavaScript

const { Model } = require('flitter-orm')
const uuid = require('uuid/v4')
class OfflineDataSyncModel extends Model {
static get schema() {
return {
user_id: String,
sync_timestamp: { type: Date, default: () => new Date() },
UUID: { type: String, default: uuid },
codiums: [Object],
database: [Object],
databaseColumns: [Object],
databaseEntries: [Object],
fileGroups: [Object],
pages: [Object],
pageNodes: [Object],
}
}
static async from_request(req) {
const rec = new this({
user_id: req.user.id,
codiums: req.body?.dirtyRecords.codiums,
database: req.body?.dirtyRecords.database,
databaseColumns: req.body?.dirtyRecords.databaseColumns,
databaseEntries: req.body?.dirtyRecords.databaseEntries,
fileGroups: req.body?.dirtyRecords.fileGroups,
pages: req.body?.dirtyRecords.pages,
pageNodes: req.body?.dirtyRecords.pageNodes,
})
await rec.save()
return rec
}
}
module.exports = exports = OfflineDataSyncModel