feat(job#create,job#set): userId parameter

See vatesfr/xo-web#1733
This commit is contained in:
Pierre Donias 2016-11-14 10:56:10 +01:00
parent ea6ff4224e
commit 19ce06e0bb
2 changed files with 12 additions and 4 deletions

View File

@ -18,7 +18,9 @@ get.params = {
} }
export async function create ({job}) { export async function create ({job}) {
job.userId = this.session.get('user_id') if (!job.userId) {
job.userId = this.session.get('user_id')
}
return (await this.createJob(job)).id return (await this.createJob(job)).id
} }
@ -29,6 +31,7 @@ create.params = {
job: { job: {
type: 'object', type: 'object',
properties: { properties: {
userId: {type: 'string', optional: true},
name: {type: 'string', optional: true}, name: {type: 'string', optional: true},
type: {type: 'string'}, type: {type: 'string'},
key: {type: 'string'}, key: {type: 'string'},
@ -51,7 +54,11 @@ create.params = {
} }
export async function set ({job}) { export async function set ({job}) {
await this.updateJob(job) if (!job.userId) {
job.userId = this.session.get('user_id')
}
return this.updateJob(job)
} }
set.permission = 'admin' set.permission = 'admin'
@ -61,6 +68,7 @@ set.params = {
type: 'object', type: 'object',
properties: { properties: {
id: {type: 'string'}, id: {type: 'string'},
userId: {type: 'string', optional: true},
name: {type: 'string', optional: true}, name: {type: 'string', optional: true},
type: {type: 'string'}, type: {type: 'string'},
key: {type: 'string'}, key: {type: 'string'},

View File

@ -45,9 +45,9 @@ export default class {
return job_.properties return job_.properties
} }
async updateJob ({id, type, name, key, method, paramsVector}) { async updateJob ({id, userId, type, name, key, method, paramsVector}) {
const oldJob = await this.getJob(id) const oldJob = await this.getJob(id)
assign(oldJob, {type, name, key, method, paramsVector}) assign(oldJob, {userId, type, name, key, method, paramsVector})
return /* await */ this._jobs.save(oldJob) return /* await */ this._jobs.save(oldJob)
} }