Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #6

Merged
merged 1 commit into from
Mar 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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