-
-
Save ju5t/2ee007af55c3dc8b235f3839ec4c2dac to your computer and use it in GitHub Desktop.
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
"use strict"; | |
var database = require('./db'); | |
var files = require('./files/storage'); | |
var unzip = require('unzip'); | |
var util = require('util'); | |
// Set some variables | |
var id = '2ce8a281-3354-4f67-b41a-b0d8d2466c6b'; | |
var query = util.format('select * from inspections where task = "%s"', id); | |
class Inspection { | |
constructor(id, data) { | |
this.id = id; | |
this.data = data; | |
} | |
} | |
// Get the record for this task | |
database.query(query).then(rows => { | |
var data = rows[0]; | |
if (rows.length === 0) { | |
throw(new Error(`No entries found for ${inspection_id}`)); | |
} else { | |
return new Inspection(id, data); | |
} | |
}) | |
.then(inspection => { | |
files.get(`${inspection.id}.zip`) | |
.pipe(unzip.Extract({path: `tmp/${inspection.id}/`})) | |
.on('close', () => { | |
console.log('Extraction done'); | |
return inspection; | |
}) | |
}).then(inspection => { | |
console.dir(inspection); | |
}) | |
.catch(error => { | |
throw(error); | |
}); | |
database.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment