2020-09-05 20:35:52 +00:00
|
|
|
import {objectToCamelCase} from '@/helpers/case'
|
2021-10-06 20:25:06 +00:00
|
|
|
import {omitBy, isNil} from '@/helpers/utils'
|
2022-08-13 13:26:57 +00:00
|
|
|
import type {Right} from '@/constants/rights'
|
2022-08-04 18:57:43 +00:00
|
|
|
import type {IAbstract} from '@/modelTypes/IAbstract'
|
2022-07-20 22:42:36 +00:00
|
|
|
|
2022-08-14 10:12:05 +00:00
|
|
|
export default abstract class AbstractModel<Model extends IAbstract = IAbstract> implements IAbstract {
|
2019-03-02 10:25:10 +00:00
|
|
|
|
2022-08-04 18:57:43 +00:00
|
|
|
|
2020-08-11 18:18:59 +00:00
|
|
|
/**
|
|
|
|
* The max right the user has on this object, as returned by the x-max-right header from the api.
|
|
|
|
*/
|
2022-06-23 01:14:58 +00:00
|
|
|
maxRight: Right | null = null
|
2022-08-14 10:15:45 +00:00
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
/**
|
2022-08-14 10:15:45 +00:00
|
|
|
* Takes an object and merges its data with the default data of this model.
|
|
|
|
*/
|
|
|
|
assignData(data: Partial<Model>) {
|
2020-04-14 20:46:27 +00:00
|
|
|
data = objectToCamelCase(data)
|
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
// Put all data in our model while overriding those with a value of null or undefined with their defaults
|
2022-08-14 10:15:45 +00:00
|
|
|
Object.assign(this, omitBy(data, isNil))
|
2019-03-02 10:25:10 +00:00
|
|
|
}
|
|
|
|
}
|