Skip to content

Instantly share code, notes, and snippets.

@ju5t

ju5t/promises.js Secret

Created March 18, 2018 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ju5t/2ee007af55c3dc8b235f3839ec4c2dac to your computer and use it in GitHub Desktop.
Save ju5t/2ee007af55c3dc8b235f3839ec4c2dac to your computer and use it in GitHub Desktop.
"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