Compare commits

..

1 Commits

Author SHA1 Message Date
Dominik Pschenitschni d6c2f94541
feat: improve models
continuous-integration/drone/pr Build was killed Details
2022-09-09 13:59:37 +02:00
7 changed files with 35 additions and 20 deletions

View File

@ -98,7 +98,7 @@
<script lang="ts">
import {defineComponent, type PropType} from 'vue'
import TaskModel from '@/models/task'
import TaskModel from '../../../models/task'
import type {ITask} from '@/modelTypes/ITask'
import PriorityLabel from './priorityLabel.vue'
import TaskService from '../../../services/task'

View File

@ -14,10 +14,13 @@ export default class AttachmentModel extends AbstractModel<IAttachment> implemen
constructor(data: Partial<IAttachment>) {
super()
this.assignData(data)
this.createdBy = new UserModel(this.createdBy)
this.file = new FileModel(this.file)
this.created = new Date(this.created)
this.assignData(data, (data) => {
return {
...data,
createdBy: new UserModel(data.createdBy),
file: new FileModel(data.file),
created: new Date(data.created),
}
})
}
}

View File

@ -21,12 +21,17 @@ export default class BucketModel extends AbstractModel<IBucket> implements IBuck
constructor(data: Partial<IBucket>) {
super()
this.assignData(data)
this.assignData(data, (data) => {
return {
...data,
tasks: data.tasks.map(t => new TaskModel(t)),
createdBy: new UserModel(data.createdBy),
created: new Date(data.created),
updated: new Date(data.updated),
}
})
this.tasks = this.tasks.map(t => new TaskModel(t))
this.createdBy = new UserModel(this.createdBy)
this.created = new Date(this.created)
this.updated = new Date(this.updated)
}
}

View File

@ -8,10 +8,13 @@ export default class CaldavTokenModel extends AbstractModel<ICaldavToken> implem
constructor(data: Partial<CaldavTokenModel>) {
super()
this.assignData(data)
this.assignData(data, (data) => {
return {
...data,
...data?.created && new Date(this.created),
}
})
if (this.created) {
this.created = new Date(this.created)
}
}
}

View File

@ -278,8 +278,10 @@ export default abstract class AbstractService<Model extends IAbstract = IAbstrac
try {
const response = await this.http.get(finalUrl, {params: prepareParams(params)})
const result = this.modelGetFactory(response.data)
result.maxRight = Number(response.headers['x-max-right']) as Right
const result = this.modelGetFactory({
...response.data,
maxRight: Number(response.headers['x-max-right']) as Right,
})
return result
} finally {
cancel()

View File

@ -18,8 +18,10 @@ export default class AttachmentService extends AbstractService<AttachmentModel>
}
processModel(model: IAttachment) {
model.created = formatISO(new Date(model.created))
return model
return {
...model,
created: formatISO(new Date(model.created)),
}
}
useCreateInterceptor() {

View File

@ -1,4 +1,4 @@
import type {IFile} from '@/modelTypes/IFile'
import type { IFile } from '@/modelTypes/IFile'
import AbstractService from '../abstractService'
// This service builds on top of the abstract service and basically just hides away method names.