This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/models/abstractModel.ts

32 lines
797 B
TypeScript

import {objectToCamelCase} from '@/helpers/case'
import {omitBy, isNil} from '@/helpers/utils'
import type {Right} from '@/models/constants/rights'
export default class AbstractModel {
/**
* The max right the user has on this object, as returned by the x-max-right header from the api.
*/
maxRight: Right | null = null
/**
* The abstract constructor takes an object and merges its data with the default data of this model.
*/
constructor(data : Object = {}) {
data = objectToCamelCase(data)
// Put all data in our model while overriding those with a value of null or undefined with their defaults
Object.assign(
this,
this.defaults(),
omitBy(data, isNil),
)
}
/**
* Default attributes that define the "empty" state.
*/
defaults(): Object {
return {}
}
}