Skip to content
Merged
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: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NODE_ENV=development
PORT=5400
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions src/api/swaggerV6.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,31 @@ paths:
schema:
$ref: '#/definitions/error_model'
x-swagger-router-controller: AgreementRegistry
put:
tags:
- agreement-registry
description: Update an existing agreement
operationId: agreementsAgreementPUT
parameters:
- name: agreement
in: path
description: XXX
required: true
type: string
- name: agreementBody
in: body
description: XXX
required: true
schema:
$ref: '#/definitions/agreement'
responses:
'200':
description: Success
'400':
description: Bad request
schema:
$ref: '#/definitions/error_model'
x-swagger-router-controller: AgreementRegistry
/states:
get:
tags:
Expand Down
5 changes: 5 additions & 0 deletions src/controllers/v6/AgreementRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = {

agreementsAgreementGET: _agreementsAgreementGET,
agreementsAgreementDELETE: _agreementsAgreementDELETE,
agreementsAgreementPUT: _agreementsAgreementPUT,

agreementsAgreementTermsGuaranteesGET: _agreementsAgreementTermsGuaranteesGET,
agreementsAgreementTermsGuaranteesGuaranteeGET: _agreementsAgreementTermsGuaranteesGuaranteeGET
Expand Down Expand Up @@ -92,6 +93,10 @@ function _agreementsAgreementGET (req, res, next) {
agreements.agreementIdGET(req.swagger.params, res, next);
}

function _agreementsAgreementPUT (req, res, next) {
agreements.agreementsAgreementPUT(req.swagger.params, res, next);
}

/**
* agreementsGET.
* @param {Object} req request
Expand Down
37 changes: 37 additions & 0 deletions src/controllers/v6/agreements/agreements.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports = {
agreementsGET: _agreementsGET,
agreementIdGET: _agreementIdGET,
agreementIdDELETE: _agreementIdDELETE,
agreementsAgreementPUT: _agreementsAgreementPUT,
agreementsAgreementTermsGuaranteesGET: _agreementsAgreementTermsGuaranteesGET,
agreementsAgreementTermsGuaranteesGuaranteeGET: _agreementsAgreementTermsGuaranteesGuaranteeGET
};
Expand Down Expand Up @@ -204,6 +205,42 @@ function _agreementIdDELETE (args, res) {
}
}

function _agreementsAgreementPUT (args, res) {
logger.info('New request to UPDATE agreement');
// Use correct parameter names from Swagger
const agreementId = args.agreement?.value;
// Accept both 'agreementBody' and fallback to 'body' for backward compatibility
const agreementBody = args.agreementBody?.value || args.body?.value;
if (agreementId && agreementBody) {
$RefParser.dereference(agreementBody, function (err, schema) {
if (err) {
logger.error(err.toString());
res.status(500).json(new ErrorModel(500, err));
} else {
const AgreementModel = db.models.AgreementModel;
AgreementModel.findOneAndUpdate({
id: agreementId
}, schema, { new: true }, function (err, agreement) {
if (err) {
logger.error('Mongo error updating agreement: ' + err.toString());
res.status(500).json(new ErrorModel(500, err));
} else {
if (!agreement) {
logger.warn('There is no agreement with id: ' + agreementId);
return res.status(404).json(new ErrorModel(404, 'There is no agreement with id: ' + agreementId));
}
logger.info('Agreement updated successfully!');
res.status(200).json(agreement);
}
});
}
});
} else {
res.sendStatus(400);
logger.warn("Can't update agreement: missing id or body");
}
}

/**
* Get all agreement terms.
* @param {Object} args {}
Expand Down
Loading