backend/app/models/api/OfflineDataSync.model.js
garrettmills dffb3d9efa
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
Finish basic offline sync logic
2020-10-30 21:59:42 -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],
databases: [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,
databases: req.body?.dirtyRecords.databases,
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