backend/app/models/api/OfflineDataSync.model.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-10-29 03:55:04 +00:00
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],
2020-10-31 02:59:42 +00:00
databases: [Object],
2020-10-29 03:55:04 +00:00
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,
2020-10-31 02:59:42 +00:00
databases: req.body?.dirtyRecords.databases,
2020-10-29 03:55:04 +00:00
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