1
0

Make all api fields snake_case (#105)

Change all snake/camelCase mix and match to camelCase everywhere

Fix conversion to not interfer with service interceptors

Add dynamic conversion between camelCase and snake_case to services

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/105
This commit is contained in:
konrad
2020-04-12 21:54:46 +00:00
parent de36296bac
commit 4a413e7f3c
60 changed files with 296 additions and 189 deletions

View File

@ -5,7 +5,7 @@ import FileModel from './file'
export default class AttachmentModel extends AbstractModel {
constructor(data) {
super(data)
this.created_by = new UserModel(this.created_by)
this.createdBy = new UserModel(this.createdBy)
this.file = new FileModel(this.file)
this.created = new Date(this.created)
}
@ -13,9 +13,9 @@ export default class AttachmentModel extends AbstractModel {
defaults() {
return {
id: 0,
task_id: 0,
taskId: 0,
file: FileModel,
created_by: UserModel,
createdBy: UserModel,
created: null,
}
}

View File

@ -5,14 +5,14 @@ export default class LabelModel extends AbstractModel {
constructor(data) {
super(data)
// Set the default color
if (this.hex_color === '') {
this.hex_color = 'e8e8e8'
if (this.hexColor === '') {
this.hexColor = 'e8e8e8'
}
if (this.hex_color.substring(0, 1) !== '#') {
this.hex_color = '#' + this.hex_color
if (this.hexColor.substring(0, 1) !== '#') {
this.hexColor = '#' + this.hexColor
}
this.textColor = this.hasDarkColor() ? '#4a4a4a' : '#e5e5e5'
this.created_by = new UserModel(this.created_by)
this.createdBy = new UserModel(this.createdBy)
this.created = new Date(this.created)
this.updated = new Date(this.updated)
@ -22,10 +22,10 @@ export default class LabelModel extends AbstractModel {
return {
id: 0,
title: '',
hex_color: '',
hexColor: '',
description: '',
created_by: UserModel,
listID: 0,
createdBy: UserModel,
listId: 0,
textColor: '',
created: null,
@ -34,11 +34,11 @@ export default class LabelModel extends AbstractModel {
}
hasDarkColor() {
if (this.hex_color === '#') {
if (this.hexColor === '#') {
return true // Defaults to dark
}
let rgb = parseInt(this.hex_color.substring(1, 7), 16); // convert rrggbb to decimal
let rgb = parseInt(this.hexColor.substring(1, 7), 16); // convert rrggbb to decimal
let r = (rgb >> 16) & 0xff; // extract red
let g = (rgb >> 8) & 0xff; // extract green
let b = (rgb >> 0) & 0xff; // extract blue

View File

@ -5,7 +5,7 @@ export default class LabelTask extends AbstractModel {
return {
id: 0,
taskID: 0,
label_id: 0,
labelId: 0,
}
}
}

View File

@ -7,7 +7,7 @@ export default class ListModel extends AbstractModel {
// The constructor of AbstractModel handles all the default parsing.
super(data)
this.shared_by = new UserModel(this.shared_by)
this.sharedBy = new UserModel(this.sharedBy)
this.created = new Date(this.created)
this.updated = new Date(this.updated)
@ -19,8 +19,8 @@ export default class ListModel extends AbstractModel {
id: 0,
hash: '',
right: 0,
shared_by: UserModel,
sharing_type: 0,
sharedBy: UserModel,
sharingType: 0,
listID: 0,
created: null,

View File

@ -7,8 +7,8 @@ export default class ListModel extends AbstractModel {
constructor(data) {
super(data)
if (this.hex_color !== '' && this.hex_color.substring(0, 1) !== '#') {
this.hex_color = '#' + this.hex_color
if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') {
this.hexColor = '#' + this.hexColor
}
// Make all tasks to task models
@ -31,8 +31,8 @@ export default class ListModel extends AbstractModel {
owner: UserModel,
tasks: [],
namespaceID: 0,
is_archived: false,
hex_color: '',
isArchived: false,
hexColor: '',
created: null,
updated: null,

View File

@ -6,8 +6,8 @@ export default class NamespaceModel extends AbstractModel {
constructor(data) {
super(data)
if (this.hex_color !== '' && this.hex_color.substring(0, 1) !== '#') {
this.hex_color = '#' + this.hex_color
if (this.hexColor !== '' && this.hexColor.substring(0, 1) !== '#') {
this.hexColor = '#' + this.hexColor
}
this.lists = this.lists.map(l => {
@ -27,8 +27,8 @@ export default class NamespaceModel extends AbstractModel {
description: '',
owner: UserModel,
lists: [],
is_archived: false,
hex_color: '',
isArchived: false,
hexColor: '',
created: null,
updated: null,

View File

@ -10,7 +10,7 @@ export default class PasswordResetModel extends AbstractModel {
defaults() {
return {
token: '',
new_password: '',
newPassword: '',
email: '',
}
}

View File

@ -9,7 +9,7 @@ export default class TaskModel extends AbstractModel {
super(data)
this.id = Number(this.id)
this.listID = Number(this.listID)
this.listId = Number(this.listId)
// Make date objects from timestamps
this.dueDate = this.dueDate ? new Date(this.dueDate) : null
@ -50,8 +50,8 @@ export default class TaskModel extends AbstractModel {
}
// Make all subtasks to task models
Object.keys(this.related_tasks).forEach(relationKind => {
this.related_tasks[relationKind] = this.related_tasks[relationKind].map(t => {
Object.keys(this.relatedTasks).forEach(relationKind => {
this.relatedTasks[relationKind] = this.relatedTasks[relationKind].map(t => {
return new TaskModel(t)
})
})
@ -83,14 +83,14 @@ export default class TaskModel extends AbstractModel {
parentTaskID: 0,
hexColor: '',
percentDone: 0,
related_tasks: {},
relatedTasks: {},
attachments: [],
createdBy: UserModel,
created: null,
updated: null,
listID: 0, // Meta, only used when creating a new task
listId: 0, // Meta, only used when creating a new task
}
}

View File

@ -9,8 +9,8 @@ export default class TaskAssigneeModel extends AbstractModel {
defaults() {
return {
created: null,
user_id: 0,
task_id: 0,
userId: 0,
taskId: 0,
}
}
}

View File

@ -12,7 +12,7 @@ export default class TaskCommentModel extends AbstractModel {
defaults() {
return {
id: 0,
task_id: 0,
taskId: 0,
comment: '',
author: UserModel,
created: null,

View File

@ -4,18 +4,18 @@ import UserModel from './user'
export default class TaskRelationModel extends AbstractModel {
constructor(data) {
super(data)
this.created_by = new UserModel(this.created_by)
this.createdBy = new UserModel(this.createdBy)
this.created = new Date(this.created)
}
defaults() {
return {
id: 0,
other_task_id: 0,
task_id: 0,
relation_kind: '',
otherTaskId: 0,
taskId: 0,
relationKind: '',
created_by: UserModel,
createdBy: UserModel,
created: null,
}
}

View File

@ -6,7 +6,7 @@ export default class TeamListModel extends TeamShareBaseModel {
return merge(
super.defaults(),
{
listID: 0,
listId: 0,
}
)
}

View File

@ -7,7 +7,7 @@ export default class TeamMemberModel extends UserModel {
super.defaults(),
{
admin: false,
teamID: 0,
teamId: 0,
}
)
}

View File

@ -13,7 +13,7 @@ export default class TeamShareBaseModel extends AbstractModel {
defaults() {
return {
teamID: 0,
teamId: 0,
right: 0,
created: null,

View File

@ -7,7 +7,7 @@ export default class UserListModel extends UserShareBaseModel {
return merge(
super.defaults(),
{
listID: 0,
listId: 0,
}
)
}

View File

@ -9,7 +9,7 @@ export default class UserShareBaseModel extends AbstractModel {
defaults() {
return {
userID: '',
userId: '',
right: 0,
created: null,