Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions src/controllers/private/v1/ecosystems.private.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,12 @@ export const getEcosystemContract = async (
try {
const { id } = req.params;
const ecosystem = await Ecosystem.findById(id);

if (!ecosystem)
return res.status(404).json({
code: 404,
errorMsg: "Not found",
message: "Ecosystem not found",
});

try {
const contract = await getContractById(ecosystem.contract, "ecosystem");
return res.json(contract);
Expand Down
21 changes: 1 addition & 20 deletions src/controllers/private/v1/negotiation.private.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,37 +118,31 @@ export const authorizeExchangeConfiguration = async (
try {
const { id } = req.params;
const { policy } = req.body;

const exchangeConf = await ExchangeConfiguration.findById(id);

if (!exchangeConf) {
return res.status(404).json({
code: 404,
errorMsg: "Resource not found",
message: "Exchange Configuration could not be found",
});
}

if (exchangeConf.provider.toString() !== req.user.id.toString()) {
return res.status(400).json({
code: 400,
errorMsg: "Resource error",
message: "Exchange Configuration could not be authorized",
});
}

if (exchangeConf.negotiationStatus === "Authorized") {
return res.status(400).json({
code: 400,
errorMsg: "Invalid operation",
message: "Exchange configuration has already been authorized",
});
}

if (getDocumentId(exchangeConf.provider) !== req.user.id) {
return res.status(401).json({ error: "Unauthorized operation" });
}

try {
const contract = await generateBilateralContract({
dataConsumer: exchangeConf.consumer,
Expand All @@ -163,13 +157,11 @@ export const authorizeExchangeConfiguration = async (
} catch (err) {
return res
.status(409)
.json({ error: "Failed to generate contract: " + err.message });
.json({ errorMsg: "Failed to generate contract.", error: err.message });
}

exchangeConf.providerPolicies = policy;
exchangeConf.negotiationStatus = "Authorized";
exchangeConf.latestNegotiator = req.user.id;

await exchangeConf.save();
return res.status(200).json(exchangeConf);
} catch (err) {
Expand Down Expand Up @@ -222,17 +214,14 @@ export const acceptNegotiation = async (
) => {
try {
const { id } = req.params;

const exchangeConf = await ExchangeConfiguration.findById(id);

if (!exchangeConf) {
return res.status(404).json({
code: 404,
errorMsg: "Resource not found",
message: "Exchange Configuration could not be found",
});
}

if (exchangeConf.negotiationStatus === "SignatureReady") {
return res.status(400).json({
code: 400,
Expand All @@ -243,9 +232,7 @@ export const acceptNegotiation = async (
}

exchangeConf.negotiationStatus = "SignatureReady";

await exchangeConf.save();

return res.json(exchangeConf);
} catch (err) {
next(err);
Expand All @@ -264,7 +251,6 @@ export const signExchangeConfiguration = async (
try {
const { id } = req.params;
const { signature } = req.body;

const exchangeConf = await ExchangeConfiguration.findById(id).populate<{
provider: IParticipant;
consumer: IParticipant;
Expand All @@ -290,30 +276,26 @@ export const signExchangeConfiguration = async (
populate: serviceOfferingPopulation,
},
]);

if (!exchangeConf) {
return res.status(404).json({
code: 404,
errorMsg: "Resource not found",
message: "Exchange Configuration could not be found",
});
}

if (exchangeConf.negotiationStatus !== "SignatureReady") {
return res.status(400).json({
code: 400,
errorMsg: "Invalid operation",
message: "Exchange configuration is not ready for signature",
});
}

const signingParty =
req.user.id === getDocumentId(exchangeConf.provider)
? "provider"
: "consumer";

exchangeConf.signatures[signingParty] = signature;

try {
// If both have applied signatures, we can inject the policies
// this avoid injecting the same policies multiple times
Expand Down Expand Up @@ -351,7 +333,6 @@ export const signExchangeConfiguration = async (
}

await exchangeConf.save();

// The client can handle UI to show depending on the contract status
return res.json({
code: 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ export const updateServiceOffering = async (

if (!updatedServiceOffering) {
return res.status(404).json({
req,
res,
code: 404,
errorMsg: "Resource not found",
message: "The service offering could not be found",
Expand All @@ -105,8 +103,6 @@ export const deleteServiceOffering = async (
);
if (!serviceOffering) {
return res.status(404).json({
req,
res,
code: 404,
errorMsg: "Resource not found",
message: "The service offering could not be found",
Expand Down
8 changes: 2 additions & 6 deletions src/controllers/public/v1/dataResources.public.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ export const getDataResourceById = async (
try {
const dataResource = await DataResource.findById(req.params.id).populate([{ path: "representation", model: Representation }]).lean();
if (!dataResource) {
return res.json({
req,
res,
return res.status(404).json({
code: 404,
errorMsg: "Resource not found",
message: "The data resource could not be found",
Expand All @@ -110,9 +108,7 @@ export const getDCATDataResourceById = async (
try {
const dataResource = await DataResource.findById(req.params.id).lean();
if (!dataResource) {
return res.json({
req,
res,
return res.status(404).json({
code: 404,
errorMsg: "Resource not found",
message: "The data resource could not be found",
Expand Down
13 changes: 3 additions & 10 deletions tests/dataResources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let providerId = "";
let dataResourcesId: "";
let jwt = "";

describe("Data Resources Routes Tests", () => {
describe("Data Resources Routes Tests", function () {
let loadMongooseStub;
before(async () => {
loadMongooseStub = stub(loadMongoose, "loadMongoose").callsFake(
Expand Down Expand Up @@ -69,7 +69,6 @@ describe("Data Resources Routes Tests", () => {
.send(dataResourceData)
.expect(201);
dataResourcesId = response.body._id;

expect(response.body).to.be.an("object");
//assertions
});
Expand All @@ -89,7 +88,6 @@ describe("Data Resources Routes Tests", () => {
const response = await request(app)
.get(`/v1/dataResources/${dataResourcesId}`)
.expect(200);
//assertions
//expect response id = dataresourceid
});

Expand All @@ -98,7 +96,6 @@ describe("Data Resources Routes Tests", () => {
.get(`/v1/dataResources/${dataResourcesId}`)
.set("Authorization", `Bearer ${jwt}`)
.expect(200);
//assertions
//expect response id = dataresourceid
});

Expand All @@ -107,8 +104,8 @@ describe("Data Resources Routes Tests", () => {
.get("/v1/dataResources/me")
.set("Authorization", `Bearer ${jwt}`)
.expect(200);
expect(response.body).to.not.be.empty;
//assertions
//expect response not empty
});

it("Should get DCAT Data Resources", async () => {
Expand All @@ -123,17 +120,13 @@ describe("Data Resources Routes Tests", () => {

it("should get all dataResources", async () => {
const response = await request(app).get("/v1/dataResources").expect(200);
//assertions
//expect response not empty
expect(response.body).to.not.be.empty;
});

it("should delete DataResource by id", async () => {
const response = await request(app)
.delete(`/v1/dataResources/${dataResourcesId}`)
.set("Authorization", `Bearer ${jwt}`)
.expect(204);
//assertions
//expect
//error test get data resources deleted
});
});
Loading