- const { taskFunctionOperation, taskFunction, taskFunctionName } = message
- let response!: TaskFunctionOperationReturnType
- if (taskFunctionOperation === 'has') {
- response = this.hasTaskFunction(taskFunctionName as string)
- } else if (taskFunctionOperation === 'add') {
- response = this.addTaskFunction(
- taskFunctionName as string,
- // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
- new Function(`return ${taskFunction as string}`)() as TaskFunction<
- Data,
- Response
- >
- )
- } else if (taskFunctionOperation === 'remove') {
- response = this.removeTaskFunction(taskFunctionName as string)
- } else if (taskFunctionOperation === 'default') {
- response = this.setDefaultTaskFunction(taskFunctionName as string)
+ const { taskFunctionOperation, taskFunctionName, taskFunction } = message
+ let response!: TaskFunctionOperationResult
+ switch (taskFunctionOperation) {
+ case 'add':
+ response = this.addTaskFunction(
+ taskFunctionName as string,
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
+ new Function(`return ${taskFunction as string}`)() as TaskFunction<
+ Data,
+ Response
+ >
+ )
+ break
+ case 'remove':
+ response = this.removeTaskFunction(taskFunctionName as string)
+ break
+ case 'default':
+ response = this.setDefaultTaskFunction(taskFunctionName as string)
+ break
+ default:
+ response = { status: false, error: new Error('Unknown task operation') }
+ break