// FIXME so far, no acls for jobs

export async function getAll () {
  return /* await */ this.getAllJobs()
}

getAll.permission = 'admin'
getAll.description = 'Gets all available jobs'

export async function get (id) {
  return /* await */ this.getJob(id)
}

get.permission = 'admin'
get.description = 'Gets an existing job'
get.params = {
  id: {type: 'string'}
}

export async function create ({job}) {
  job.userId = this.session.get('user_id')

  return (await this.createJob(job)).id
}

create.permission = 'admin'
create.description = 'Creates a new job from description object'
create.params = {
  job: {
    type: 'object',
    properties: {
      name: {type: 'string', optional: true},
      type: {type: 'string'},
      key: {type: 'string'},
      method: {type: 'string'},
      paramsVector: {
        type: 'object',
        properties: {
          type: {type: 'string'},
          items: {
            type: 'array',
            items: {
              type: 'object'
            }
          }
        },
        optional: true
      }
    }
  }
}

export async function set ({job}) {
  if (!job.userId) {
    job.userId = this.session.get('user_id')
  }

  return this.updateJob(job)
}

set.permission = 'admin'
set.description = 'Modifies an existing job from a description object'
set.params = {
  job: {
    type: 'object',
    properties: {
      id: {type: 'string'},
      userId: {type: 'string', optional: true},
      name: {type: 'string', optional: true},
      type: {type: 'string'},
      key: {type: 'string'},
      method: {type: 'string'},
      paramsVector: {
        type: 'object',
        properties: {
          type: {type: 'string'},
          items: {
            type: 'array',
            items: {
              type: 'object'
            }
          }
        },
        optional: true
      }
    }
  }
}

async function delete_ ({id}) {
  await this.removeJob(id)
}

delete_.permission = 'admin'
delete_.description = 'Deletes an existing job'
delete_.params = {
  id: {type: 'string'}
}

export {delete_ as delete}

export async function runSequence ({idSequence}) {
  await this.runJobSequence(idSequence)
}

runSequence.permission = 'admin'
runSequence.description = 'Runs jobs sequentially, in the provided order'
runSequence.params = {
  idSequence: {type: 'array', items: {type: 'string'}}
}

@@ -399,16 +399,39 @@
 job%7D) %7B%0A
+  if (!job.userId) %7B%0A  
   job.us
@@ -464,16 +464,20 @@
 ser_id')
+%0A  %7D
 %0A%0A  retu
@@ -667,24 +667,72 @@
 operties: %7B%0A
+      userId: %7Btype: 'string', optional: true%7D,%0A
       name: 
@@ -1177,85 +1177,13 @@
 %7B%0A  
-if (!job.userId) %7B%0A    job.userId = this.session.get('user_id')%0A  %7D%0A%0A  return
+await
  thi
@@ -1356,24 +1356,24 @@
 operties: %7B%0A
+
       id: %7Bt
@@ -1392,56 +1392,8 @@
 '%7D,%0A
-      userId: %7Btype: 'string', optional: true%7D,%0A
     

Fix userId.