2019-03-02 10:25:10 +00:00
|
|
|
import AbstractService from './abstractService'
|
2022-11-13 21:04:57 +00:00
|
|
|
import ProjectModel from '@/models/project'
|
|
|
|
import type {IProject} from '@/modelTypes/IProject'
|
2019-03-02 10:25:10 +00:00
|
|
|
import TaskService from './task'
|
2021-01-17 10:51:07 +00:00
|
|
|
import {colorFromHex} from '@/helpers/color/colorFromHex'
|
2019-03-02 10:25:10 +00:00
|
|
|
|
2022-11-13 21:04:57 +00:00
|
|
|
export default class ProjectService extends AbstractService<IProject> {
|
2019-03-02 10:25:10 +00:00
|
|
|
constructor() {
|
|
|
|
super({
|
2023-03-25 13:54:20 +00:00
|
|
|
create: '/projects',
|
2022-11-13 21:04:57 +00:00
|
|
|
get: '/projects/{id}',
|
|
|
|
getAll: '/projects',
|
|
|
|
update: '/projects/{id}',
|
|
|
|
delete: '/projects/{id}',
|
2019-03-02 10:25:10 +00:00
|
|
|
})
|
|
|
|
}
|
2020-02-08 13:16:06 +00:00
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
modelFactory(data) {
|
2022-11-13 21:04:57 +00:00
|
|
|
return new ProjectModel(data)
|
2019-03-02 10:25:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
beforeUpdate(model) {
|
2022-06-30 16:04:41 +00:00
|
|
|
if(typeof model.tasks !== 'undefined') {
|
|
|
|
const taskService = new TaskService()
|
|
|
|
model.tasks = model.tasks.map(task => {
|
|
|
|
return taskService.beforeUpdate(task)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if(typeof model.hexColor !== 'undefined') {
|
|
|
|
model.hexColor = colorFromHex(model.hexColor)
|
|
|
|
}
|
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
return model
|
|
|
|
}
|
2020-03-25 21:27:29 +00:00
|
|
|
|
2022-11-13 21:04:57 +00:00
|
|
|
beforeCreate(project) {
|
|
|
|
project.hexColor = colorFromHex(project.hexColor)
|
|
|
|
return project
|
2020-03-25 21:27:29 +00:00
|
|
|
}
|
2020-05-31 19:17:10 +00:00
|
|
|
|
2022-11-13 21:04:57 +00:00
|
|
|
async background(project: Pick<IProject, 'id' | 'backgroundInformation'>) {
|
|
|
|
if (project.backgroundInformation === null) {
|
2021-10-09 14:34:57 +00:00
|
|
|
return ''
|
2020-05-31 19:17:10 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 17:37:20 +00:00
|
|
|
const response = await this.http({
|
2022-11-13 21:04:57 +00:00
|
|
|
url: `/projects/${project.id}/background`,
|
2020-05-31 19:17:10 +00:00
|
|
|
method: 'GET',
|
|
|
|
responseType: 'blob',
|
|
|
|
})
|
2021-10-11 17:37:20 +00:00
|
|
|
return window.URL.createObjectURL(new Blob([response.data]))
|
2020-05-31 19:17:10 +00:00
|
|
|
}
|
2021-03-21 17:11:24 +00:00
|
|
|
|
2022-11-13 21:04:57 +00:00
|
|
|
async removeBackground(project: Pick<IProject, 'id'>) {
|
2021-03-21 17:11:24 +00:00
|
|
|
const cancel = this.setLoading()
|
|
|
|
|
2021-10-11 17:37:20 +00:00
|
|
|
try {
|
2022-11-13 21:04:57 +00:00
|
|
|
const response = await this.http.delete(`/projects/${project.id}/background`, project)
|
2021-10-11 17:37:20 +00:00
|
|
|
return response.data
|
|
|
|
} finally {
|
|
|
|
cancel()
|
|
|
|
}
|
2021-03-21 17:11:24 +00:00
|
|
|
}
|
2019-03-02 10:25:10 +00:00
|
|
|
}
|