Skip to content

Commit

Permalink
Merge pull request #224 from bpedersen2/backend-next-compat
Browse files Browse the repository at this point in the history
Backend next compat
  • Loading branch information
nitrosx authored Oct 3, 2023
2 parents 5a9c97c + a4d8327 commit 7b15776
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 132 deletions.
63 changes: 31 additions & 32 deletions common/scicat-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ exports.Dataset = class {
*/

async find(filter) {
const jsonFilter = JSON.stringify(filter);
//console.log(">>> Dataset.find filter", jsonFilter);
const url = jsonFilter
? baseUrl + "/Datasets?filter=" + jsonFilter
: baseUrl + "/Datasets";

const jsonFilter = JSON.stringify(filter ? filter : {});
// console.log(">>> Dataset.find filter", jsonFilter);
const url = baseUrl + "/datasets?filter=" + jsonFilter;
const res = await superagent.get(url);
return JSON.parse(res.text);
}
Expand All @@ -34,8 +33,8 @@ exports.Dataset = class {
//console.log(">>> Dataset.findById pid", encodedId);
//console.log(">>> Dataset.findById filter", jsonFilter);
const url = jsonFilter
? baseUrl + "/Datasets/" + encodedId + "?filter=" + jsonFilter
: baseUrl + "/Datasets/" + encodedId;
? baseUrl + "/datasets/" + encodedId + "?filter=" + jsonFilter
: baseUrl + "/datasets/" + encodedId;
const res = await superagent.get(url);
return JSON.parse(res.text);
}
Expand All @@ -50,8 +49,8 @@ exports.Dataset = class {
const jsonFilter = JSON.stringify(filter);
//console.log(">>> Dataset.count filter", jsonFilter);
const url = jsonFilter
? baseUrl + "/Datasets?filter=" + jsonFilter
: baseUrl + "/Datasets";
? baseUrl + "/datasets?filter=" + jsonFilter
: baseUrl + "/datasets";
const res = await superagent.get(url);
const datasets = JSON.parse(res.text);
return { count: datasets.length };
Expand All @@ -70,10 +69,10 @@ exports.Dataset = class {
//console.log(">>> Dataset.findByIdFiles pid", encodedId);
//console.log(">>> Dataset.findByIdFiles filter", jsonFilter);
const url = jsonFilter
? baseUrl + "/Datasets/" + encodedId + "?filter=" + jsonFilter
: baseUrl + "/Datasets/" + encodedId;
? baseUrl + "/datasets/" + encodedId + "/origdatablocks?filter=" + jsonFilter
: baseUrl + "/datasets/" + encodedId + "/origdatablocks";
const res = await superagent.get(url);
return JSON.parse(res.text)["origdatablocks"];
return JSON.parse(res.text);
}
};

Expand All @@ -85,14 +84,14 @@ exports.PublishedData = class {
*/

async find(filter) {
console.log("PublishedData.find - BEGIN");
console.log("publisheddata.find - BEGIN");
const jsonFilter = JSON.stringify(filter);
console.log("PublishedData.find filter", jsonFilter);
console.log("publisheddata.find filter", jsonFilter);
const url = jsonFilter
? baseUrl + "/PublishedData?filter=" + jsonFilter
: baseUrl + "/PublishedData";
? baseUrl + "/publisheddata?filter=" + jsonFilter
: baseUrl + "/publisheddata";
const res = await superagent.get(url);
console.log("PublishedData.find - END");
console.log("publisheddata.find - END");
return JSON.parse(res.text);
}

Expand All @@ -106,11 +105,11 @@ exports.PublishedData = class {
async findById(id, filter) {
const encodedId = encodeURIComponent(id);
const jsonFilter = JSON.stringify(filter);
//console.log(">>> PublishedData.findById pid", encodedId);
//console.log(">>> PublishedData.findById filter", jsonFilter);
//console.log(">>> publisheddata.findById pid", encodedId);
//console.log(">>> publisheddata.findById filter", jsonFilter);
const url = jsonFilter
? baseUrl + "/PublishedData/" + encodedId + "?filter=" + jsonFilter
: baseUrl + "/PublishedData/" + encodedId;
? baseUrl + "/publisheddata/" + encodedId + "?filter=" + jsonFilter
: baseUrl + "/publisheddata/" + encodedId;
const res = await superagent.get(url);
return JSON.parse(res.text);
}
Expand All @@ -123,10 +122,10 @@ exports.PublishedData = class {

async count(where) {
const jsonWhere = JSON.stringify(where);
//console.log(">>> PublishedData.count where", jsonWhere);
//console.log(">>> publisheddata.count where", jsonWhere);
const url = jsonWhere
? baseUrl + "/PublishedData/count?where=" + jsonWhere
: baseUrl + "/PublishedData/count";
? baseUrl + "/publisheddata/count?where=" + jsonWhere
: baseUrl + "/publisheddata/count";
const res = await superagent.get(url);
return JSON.parse(res.text);
}
Expand All @@ -143,8 +142,8 @@ exports.Instrument = class {
const jsonFilter = JSON.stringify(filter);
//console.log(">>> Instrument.find filter", jsonFilter);
const url = jsonFilter
? baseUrl + "/Instruments?filter=" + jsonFilter
: baseUrl + "/Instruments";
? baseUrl + "/instruments?filter=" + jsonFilter
: baseUrl + "/instruments";
const res = await superagent.get(url);
return JSON.parse(res.text);
}
Expand All @@ -162,8 +161,8 @@ exports.Instrument = class {
//console.log(">>> Instrument.findById id", encodedId);
//console.log(">>> Instrument.findById filter", jsonFilter);
const url = jsonFilter
? baseUrl + "/Instruments/" + encodedId + "?filter=" + jsonFilter
: baseUrl + "/Instruments/" + encodedId;
? baseUrl + "/instruments/" + encodedId + "?filter=" + jsonFilter
: baseUrl + "/instruments/" + encodedId;
const res = await superagent.get(url);
return JSON.parse(res.text);
}
Expand All @@ -178,8 +177,8 @@ exports.Instrument = class {
const jsonWhere = JSON.stringify(where);
//console.log(">>> Instrument.count where", jsonWhere);
const url = jsonWhere
? baseUrl + "/Instruments/count?where=" + jsonWhere
: baseUrl + "/Instruments/count";
? baseUrl + "/instruments/count?where=" + jsonWhere
: baseUrl + "/instruments/count";
const res = await superagent.get(url);
return JSON.parse(res.text);
}
Expand All @@ -196,8 +195,8 @@ exports.Sample = class {
const jsonFilter = JSON.stringify(filter);
//console.log(">>> Sample.find filter", jsonFilter);
const url = jsonFilter
? baseUrl + "/Samples?filter=" + jsonFilter
: baseUrl + "/Samples";
? baseUrl + "/samples?filter=" + jsonFilter
: baseUrl + "/samples";
const res = await superagent.get(url);
return JSON.parse(res.text);
}
Expand Down
Loading

0 comments on commit 7b15776

Please sign in to comment.