Skip to content

Commit

Permalink
Adding manual state to analysis and creating mutation to change this …
Browse files Browse the repository at this point in the history
…attribute
  • Loading branch information
thiagocmoreira committed May 28, 2019
1 parent 3767c67 commit f2cf343
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
16 changes: 16 additions & 0 deletions migrations/20190528150607_add_manual_state_to_analysis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function up (knex) {
return knex.schema.alterTable('analysis', (table) => {
table.string('manual_state')
})
}

function down (knex) {
return knex.schema.alterTable('analysis', t => {
t.dropColumn('manual_state')
})
}

export {
up,
down
}
17 changes: 17 additions & 0 deletions src/mutations/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ export default {
throw new Error(err.message)
}
},
setAnalysisManualState: async (root, { id, state }, context, info) => {
try {
let analysis = knexInstance('analysis')
.where({ id })

analysis = await analysis
.update({
manual_state: state,
updated_at: new Date()
})
.returning('*')

return analysis
} catch (err) {
throw new Error(err.message)
}
},
deleteAnalysis: async (root, { id }, context, info) => {
try {
let count = await knexInstance('analysis')
Expand Down
2 changes: 2 additions & 0 deletions src/type-defs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Analysis {
position_end: String
image_path: String
state: String
manual_state: String
report_id: ID
cable_id: ID
created_at: DateTime
Expand Down Expand Up @@ -61,6 +62,7 @@ type Mutation {
deleteReport (id: ID!): Boolean
createAnalysis (positionStart: Int, positionEnd: Int, reportId: ID, cableId: ID, imagePath: String): ID
updateAnalysis (id: ID!, imagePath: String, state: String): Analysis
setAnalysisManualState (id: ID!, state: String): Analysis
deleteAnalysis (id: ID!): Boolean
}
Expand Down

0 comments on commit f2cf343

Please sign in to comment.