-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2961 from bomoko/feature/refactor_task_objects
Feature PR - Refactor task interfaces
- Loading branch information
Showing
3 changed files
with
115 additions
and
103 deletions.
There are no files selected for viewing
13 changes: 0 additions & 13 deletions
13
services/api/src/resources/task/models/taskRegistration.test.ts
This file was deleted.
Oops, something went wrong.
58 changes: 39 additions & 19 deletions
58
services/api/src/resources/task/models/taskRegistration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,45 @@ | ||
export const newTaskRegistrationFromObject = ( | ||
payload: Partial<TaskRegistration> | ||
) => { | ||
let obj = new TaskRegistration(); | ||
return { ...obj, ...payload }; | ||
}; | ||
// export const newTaskRegistrationFromObject = ( | ||
// payload: AdvancedTaskDefinitionInterface | ||
// ) => { | ||
// return new TaskRegistration(payload); | ||
// }; | ||
|
||
|
||
export class TaskRegistration { | ||
static TYPE_STANDARD = "COMMAND" | ||
static TYPE_ADVANCED = "IMAGE" | ||
id: number; | ||
export interface AdvancedTaskDefinitionInterface { | ||
id?: number; | ||
type: string; | ||
name: string; | ||
description: string; | ||
advanced_task_definition: number; | ||
environment: number; | ||
project: number; | ||
groupName: string; | ||
command: string; | ||
service: string; | ||
description?: string; | ||
environment?: number; | ||
project?: number; | ||
groupName?: string; | ||
created: string; | ||
deleted: string; | ||
image: string; | ||
permission: string; | ||
permission?: string; | ||
command?: string; | ||
service?: string; | ||
image?: string; | ||
} | ||
|
||
|
||
export const AdvancedTaskDefinitionType = { | ||
command: 'COMMAND', | ||
image: 'IMAGE' | ||
}; | ||
|
||
export const getAdvancedTaskDefinitionType = (taskDef:AdvancedTaskDefinitionInterface) => { | ||
if(taskDef.type.toLowerCase() == AdvancedTaskDefinitionType.command.toLowerCase()) { | ||
return AdvancedTaskDefinitionType.command; | ||
} | ||
return AdvancedTaskDefinitionType.image; | ||
} | ||
|
||
export const isAdvancedTaskDefinitionSystemLevelTask = (taskDef:AdvancedTaskDefinitionInterface): boolean => { | ||
return taskDef.project == null && taskDef.environment == null && taskDef.groupName == null; | ||
} | ||
|
||
export const doesAdvancedTaskDefinitionNeedAdminRights = (taskDef:AdvancedTaskDefinitionInterface): boolean => { | ||
return isAdvancedTaskDefinitionSystemLevelTask(taskDef) | ||
|| getAdvancedTaskDefinitionType(taskDef) == AdvancedTaskDefinitionType.image | ||
|| taskDef.groupName != undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters