Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ren22 committed Mar 2, 2018
1 parent df0df64 commit 28b3282
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ function baseDatasetQuery() {
}

function checkFetchRes(resp) {
if (resp.status >= 200 && resp.status < 300) {
if (resp.ok) {
return resp
}
else {
} else {
throw new Error(`An error occurred during fetch request - status ${resp.status}`);
}
}
Expand Down Expand Up @@ -271,12 +270,13 @@ const Resolvers = {
if(ds._source.annotation_counts && ds._source.ds_status === 'FINISHED') {
let inpAllLvlCounts = ds._source.annotation_counts[0].counts;
inpFdrLvls.forEach(lvl => {
inpAllLvlCounts.find(lvlCount => {
if (lvlCount.level === lvl) {
outFdrLvls.push(lvlCount.level);
outFdrCounts.push(lvlCount.n);
}
})
let findRes = inpAllLvlCounts.find(lvlCount => {
return lvlCount.level === lvl
});
if (findRes) {
outFdrLvls.push(findRes.level);
outFdrCounts.push(findRes.n);
}
});
}
return {
Expand Down Expand Up @@ -549,7 +549,7 @@ const Resolvers = {
method: 'POST',
body: JSON.stringify(body),
headers: {'Content-Type': 'application/json'}});
await checkFetchRes(processOptImage);
checkFetchRes(processOptImage);
return 'success';
} catch (e) {
logger.error(e.message);
Expand All @@ -565,23 +565,23 @@ const Resolvers = {
const smAPIUrl = `http://${config.services.sm_engine_api_host}/v1/datasets/${datasetId}/del-optical-image`;
try {
await checkPermissions(datasetId, payload);

let rawOpticalImage = await pg.select('optical_image').from('dataset').where('id', '=', datasetId);
let opticalImageIds = await pg.select('id').from('optical_image').where('ds_id', '=', datasetId);
await allUrls.push(basePath +
allUrls.push(basePath +
`${config.img_upload.categories.raw_optical_image.path}delete/${rawOpticalImage[0].optical_image}`);
for (let image of opticalImageIds) {
await allUrls.push(basePath + `${config.img_upload.categories.optical_image.path}delete/${image.id}`)}
opticalImageIds.forEach(image => {
allUrls.push(basePath + `${config.img_upload.categories.optical_image.path}delete/${image.id}`)
});
for (let url of allUrls) {
let res = await fetch(url, {
method: 'delete'});
await checkFetchRes(res);
checkFetchRes(res);
}
let dbDelFetch = await fetch (smAPIUrl, {
let dbDelFetch = await fetch(smAPIUrl, {
method: 'POST',
body: JSON.stringify({datasetId}),
headers: {'Content-Type': 'application/json'}});
await checkFetchRes(dbDelFetch);
checkFetchRes(dbDelFetch);
return 'success';
} catch (e) {
logger.error(e.message);
Expand Down

0 comments on commit 28b3282

Please sign in to comment.