Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
asset,
amount
};
});
for (let i = 0; i < tx.inputs.length; i++) {
const input = tx.inputs[i];
const outpoint = {
txHash: input.input.txHash.hash,
index: input.input.index,
};
// search for this tx and index
const output = await outputsDAL.findOutpoint(outpoint.txHash, outpoint.index);
if (!output) {
throw new HttpError(httpStatus.BAD_REQUEST, 'One of the inputs is not yet in the blockchain');
}
txCustom.Inputs.push({
id: i + 1, // fake id
Output: output,
});
}
const assets = getTransactionAssets(txCustom);
res.status(httpStatus.OK).json(jsonResponse.create(httpStatus.OK, assets));
} catch (error) {
throw new HttpError(error.status || httpStatus.INTERNAL_SERVER_ERROR, error.customMessage);
}
},
create: async function(req, res) {
static error(res, e, code = HTTPStatus.BAD_REQUEST) {
let error = e;
if (typeof e === 'string') {
error = new Error(e);
}
if (env === 'development') {
console.log(error);
}
return res
.status(code)
.json({
error: {
message: error.message,
statusCode: code
},
});
}
function query(req, res, next) {
if (!req.query.period || ! PERIOD_TO_INTERVAL.hasOwnProperty(req.query.period)) {
const err = new APIError('Period is not provided or wrong', httpStatus.BAD_REQUEST);
return next(err);
}
if (!req.query.sensor) {
const err = new APIError('Sensor is not provided', httpStatus.BAD_REQUEST);
return next(err);
}
const data = [{
name: 'Time ON',
value: Math.floor((Math.random() * 100) + 1)
}, {
name: 'Time OFF',
value: Math.floor((Math.random() * 100) + 1)
}];
constructor(message) {
super(message || 'Bad Request', httpStatus.BAD_REQUEST);
}
};
msg: userConfig.validationMessage.districtInvalid,
},
],
},
{
field: 'tempaddress.vdc',
validate: [
{
condition: 'IsMONGOID',
msg: userConfig.validationMessage.vdcInvalid,
},
],
},
]);
if (!isEmpty(errors)) {
return otherHelper.sendResponse(res, HttpStatus.BAD_REQUEST, false, null, errors, 'Validation Error.', null);
} else {
return next();
}
};
if (!job) {
return next(new APIError('Job not found', httpStatus.NOT_FOUND));
}
if (job.postedUser.toString() === req.user._id.toString()) {
return next(new APIError('Unable to apply for a job you posted', httpStatus.FORBIDDEN));
}
const today = new Date().getDate();
if (job.isDeleted || (job.expirationDate && job.expirationDate < today)) {
return next(new APIError('Job not found', httpStatus.NOT_FOUND));
}
if (!req.file) {
return next(new APIError('Resume is required', httpStatus.BAD_REQUEST));
}
if (!req.body.coveringLetter) {
return next(new APIError('Covering letter is required', httpStatus.BAD_REQUEST));
}
const msg = {
to: job.applicationEmailAddress,
from: config.email.fromAddress,
subject: `Job Application : ${job.title}`,
text: req.body.coveringLetter,
attachments: [
{
content: req.file.buffer.toString('base64'),
filename: req.file.originalname,
type: req.file.mimetype,
validation.catValidate = (req, res, next) => {
const data = req.body;
const validateArray = [
{
field: 'title',
validate: [
{
condition: 'IsEmpty',
msg: blogConfig.validate.empty,
},
],
},
];
const errors = otherHelper.validation(data, validateArray);
if (!isEmpty(errors)) {
return otherHelper.sendResponse(res, httpStatus.BAD_REQUEST, false, null, errors, 'invalid input', null);
} else {
next();
}
};
module.exports = validation;
this.jsonBodyParser(request, response, (err: Error | null) => {
if (err) {
this.terminateResponse(
response,
HTTPStatus.BAD_REQUEST,
`Failed to parse body of request: ${err.message}`
)
return
}
for (const path of this.sortedPostPaths) {
if (request.url!.startsWith(path)) {
this.postPaths.get(path)!(
(request as any).body,
{ headers: request.headers as Dictionary, url: request.url! },
this.sendResponse.bind(this, response)
)
return
}
}
this.terminateResponse(response, HTTPStatus.NOT_FOUND, 'Endpoint not found.')
proof: async function(req, res) {
const { date, ticker } = req.query;
if (!date || !ticker) {
throw new HttpError(httpStatus.BAD_REQUEST, 'Both date and ticker must be supplied');
}
const data = await service.oracle.proof(ticker, date);
res.status(httpStatus.OK).json(jsonResponse.create(httpStatus.OK, data));
},
lastUpdated: async function(req, res) {
},
],
},
{
field: 'isHalfDay',
validate: [
{
condition: 'IsEmpty',
msg: holidayConfig.validationMessage.isHalfDayRequired,
},
],
},
]);
if (!isEmpty(errors)) {
return otherHelper.sendResponse(res, HttpStatus.BAD_REQUEST, false, null, errors, 'Validation Error.', null);
} else {
return next();
}
};