2019-11-24 13:16:24 +00:00
|
|
|
import AbstractService from './abstractService'
|
2022-07-20 22:42:36 +00:00
|
|
|
import LabelModel, { type ILabel } from '@/models/label'
|
2020-03-02 20:55:22 +00:00
|
|
|
import {formatISO} from 'date-fns'
|
2021-01-17 10:51:07 +00:00
|
|
|
import {colorFromHex} from '@/helpers/color/colorFromHex'
|
2019-03-07 19:48:40 +00:00
|
|
|
|
2022-07-20 22:42:36 +00:00
|
|
|
export default class LabelService extends AbstractService<ILabel> {
|
2019-03-07 19:48:40 +00:00
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
create: '/labels',
|
|
|
|
getAll: '/labels',
|
|
|
|
get: '/labels/{id}',
|
|
|
|
update: '/labels/{id}',
|
|
|
|
delete: '/labels/{id}',
|
|
|
|
})
|
|
|
|
}
|
2020-02-08 13:16:06 +00:00
|
|
|
|
2020-04-25 23:11:34 +00:00
|
|
|
processModel(label) {
|
2020-09-04 20:01:02 +00:00
|
|
|
label.created = formatISO(new Date(label.created))
|
|
|
|
label.updated = formatISO(new Date(label.updated))
|
2021-01-17 10:51:07 +00:00
|
|
|
label.hexColor = colorFromHex(label.hexColor)
|
2020-04-25 23:11:34 +00:00
|
|
|
return label
|
2020-02-08 13:16:06 +00:00
|
|
|
}
|
|
|
|
|
2019-03-07 19:48:40 +00:00
|
|
|
modelFactory(data) {
|
|
|
|
return new LabelModel(data)
|
|
|
|
}
|
2020-09-05 20:35:52 +00:00
|
|
|
|
2019-03-07 19:48:40 +00:00
|
|
|
beforeUpdate(label) {
|
2020-04-25 23:11:34 +00:00
|
|
|
return this.processModel(label)
|
2019-03-07 19:48:40 +00:00
|
|
|
}
|
2020-09-05 20:35:52 +00:00
|
|
|
|
2019-03-07 19:48:40 +00:00
|
|
|
beforeCreate(label) {
|
2020-04-25 23:11:34 +00:00
|
|
|
return this.processModel(label)
|
2019-03-07 19:48:40 +00:00
|
|
|
}
|
|
|
|
}
|