Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
clientRequest: any,
serverResponse: any,
dataAccess: DataAccess,
): Promise {
// Retrieves data access layer
let transactions;
// As the Node doesn't implement a cache, all transactions have to be retrieved directly on IPFS
// This operation can take a long time and then the timeout of the request should be increase
// PROT-187: Decrease or remove this value
clientRequest.setTimeout(REQUEST_TIMEOUT);
// Verifies if data sent from get request are correct
// clientRequest.query is expected to contain the topic of the transactions to search for
if (!clientRequest.query || !clientRequest.query.topic) {
serverResponse.status(httpStatus.UNPROCESSABLE_ENTITY).send('Incorrect data');
} else {
try {
// parse updatedBetween because in query everything is string
let timestampBoundaries: { from: number; to: number } | undefined;
if (clientRequest.query.timestampBoundaries) {
timestampBoundaries = JSON.parse(clientRequest.query.timestampBoundaries);
}
transactions = await dataAccess.getTransactionsByTopic(
clientRequest.query.topic,
timestampBoundaries,
);
serverResponse.status(httpStatus.OK).send(transactions);
} catch (e) {
// tslint:disable-next-line:no-console
// Retrieves data access layer
let dataAccessResponse;
// Used to compute request time
const requestStartTime = Date.now();
// Set the timeout from the value from config and convert seconds to milliseconds
// tslint:disable:no-magic-numbers
clientRequest.setTimeout(getPersistTransactionTimeout() * 1000);
// Verifies if data send from post are correct
// clientRequest.body is expected to contain data for data-acces layer:
// transactionData: data of the transaction
// topics (optional): arbitrary strings that reference the transaction
if (!clientRequest.body || !clientRequest.body.transactionData || !clientRequest.body.channelId) {
serverResponse.status(httpStatus.UNPROCESSABLE_ENTITY).send('Incorrect data');
} else {
try {
dataAccessResponse = await dataAccess.persistTransaction(
clientRequest.body.transactionData,
clientRequest.body.channelId,
clientRequest.body.topics,
);
// Log the request time
const requestEndTime = Date.now();
logger.debug(`persistTransaction latency: ${requestEndTime - requestStartTime}ms`, ['metric', 'latency']);
logger.debug(`persistTransaction successfully completed`, ['metric', 'successRate']);
serverResponse.status(httpStatus.OK).send(dataAccessResponse);
} catch (e) {
logger.error(`persistTransaction error: ${e}`);
.end(function(err, res){
expect(res.status).to.be.equal(httpStatus.UNPROCESSABLE_ENTITY);
done();
});
});
.end(function(err, res){
expect(res.status).to.be.equal(httpStatus.UNPROCESSABLE_ENTITY);
done();
});
});
router.post('/authentications/', function(req, res, next){
var logger = req.app.get('logger');
var actions = req.app.get('actions');
var models = req.app.get('models');
req.checkGroup('password');
req.checkGroup('email');
var errors = req.validationErrors();
if (errors) {
return res.status(httpStatus.UNPROCESSABLE_ENTITY).end();
}
var email = req.body.email;
var password = req.body.password;
actions.users.list({
where: {
email: email,
status: models.user.STATUS.ACTIVE
}
}, (err, users) => {
if(err) {
logger.error('server error users', err);
return res.status(httpStatus.INTERNAL_SERVER_ERROR).end();
}
if(!users || users.length === 0) {
return res.status(httpStatus.NOT_FOUND).end();
export function unprocessableEntity(arg1: T | string | Wrapper, arg2?: string): T {
return answer(HTTP.UNPROCESSABLE_ENTITY, arg1, arg2);
}
}, (err, item) => {
if(err instanceof ValidationError) {
return res.status(httpStatus.UNPROCESSABLE_ENTITY).end();
} else if(err) {
logger.error('DB error item', err);
return res.status(httpStatus.INTERNAL_SERVER_ERROR).end();
}
res.status(httpStatus.OK).json(item);
});
});
router.put('/items/:id', (req, res) => {
var logger = req.app.get('logger');
var actions = req.app.get('actions');
req.checkGroup('name');
var errors = req.validationErrors();
if (errors) {
return res.status(httpStatus.UNPROCESSABLE_ENTITY).end();
}
var name = req.body.name;
actions.items.list({
id: req.params.id
}, (err, items) => {
if (err) {
logger.error('DB error item', err);
return res.status(httpStatus.INTERNAL_SERVER_ERROR).end();
}
if (!items || items.length === 0) {
return res.status(httpStatus.NOT_FOUND).end();
}
actions.items.update(items[0], {
name
}, (err, item) => {
if (err) {
router.post('/users/resetPassword', (req, res) => {
var logger = req.app.get('logger');
var config = req.app.get('config');
var actions = req.app.get('actions');
var models = req.app.get('models');
req.checkGroup('email');
var errors = req.validationErrors();
if (errors) {
return res.status(httpStatus.UNPROCESSABLE_ENTITY).end();
}
var email = req.body.email;
actions.users.list({
where: {
email: email,
status: models.user.STATUS.ACTIVE
}
}, (err, users) => {
if(err) {
logger.error('DB error find reset user password configrmation', err);
return res.status(httpStatus.INTERNAL_SERVER_ERROR).end();
}
if(!users || users.length === 0) {
return res.status(httpStatus.NOT_FOUND).end();
}
router.post('/users/resetPassword/confirmation', (req, res) => {
var logger = req.app.get('logger');
var config = req.app.get('config');
var actions = req.app.get('actions');
var models = req.app.get('models');
req.checkGroup('password');
var errors = req.validationErrors();
if (errors) {
return res.status(httpStatus.UNPROCESSABLE_ENTITY).end();
}
var password = req.body.password;
actions.users.verifyResetPasswordToken(req.body.token, (err, response) => {
if(err) {
logger.error('server error reset user password configrmation', err);
return res.status(httpStatus.INTERNAL_SERVER_ERROR).end();
}
actions.users.list({
id: response.id
}, (err, users) => {
if(err) {
logger.error('DB error find reset user password configrmation', err);
return res.status(httpStatus.INTERNAL_SERVER_ERROR).end();
}
if(!users || users.length === 0 || users[0].status !== models.user.STATUS.ACTIVE) {