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

23 lines
754 B
TypeScript
Raw Normal View History

import {objectToCamelCase} from '@/helpers/case'
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
export default abstract class AbstractModel<Model extends IAbstract = IAbstract> implements IAbstract {
2022-08-04 18:57:43 +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
/**
* Takes an object and merges its data with the default data of this model.
*/
assignData(data: Partial<Model>) {
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, omitBy(data, isNil))
}
}