2020-09-05 22:35:52 +02:00
|
|
|
import {objectToCamelCase} from '@/helpers/case'
|
2021-10-06 22:25:06 +02:00
|
|
|
import {omitBy, isNil} from '@/helpers/utils'
|
2019-03-02 11:25:10 +01:00
|
|
|
|
|
|
|
export default class AbstractModel {
|
|
|
|
|
2020-08-11 20:18:59 +02:00
|
|
|
/**
|
|
|
|
* The max right the user has on this object, as returned by the x-max-right header from the api.
|
|
|
|
* @type {number|null}
|
|
|
|
*/
|
|
|
|
maxRight = null
|
|
|
|
|
2019-03-02 11:25:10 +01:00
|
|
|
/**
|
|
|
|
* The abstract constructor takes an object and merges its data with the default data of this model.
|
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
constructor(data) {
|
2020-04-14 22:46:27 +02:00
|
|
|
data = objectToCamelCase(data)
|
|
|
|
|
2019-03-02 11:25:10 +01:00
|
|
|
// Put all data in our model while overriding those with a value of null or undefined with their defaults
|
2021-10-06 22:25:06 +02:00
|
|
|
Object.assign(
|
|
|
|
this,
|
|
|
|
this.defaults(),
|
|
|
|
omitBy(data, isNil),
|
|
|
|
)
|
2019-03-02 11:25:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default attributes that define the "empty" state.
|
|
|
|
* @return {{}}
|
|
|
|
*/
|
|
|
|
defaults() {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
}
|