spee.ch/server/controllers/api/claim/shortId/index.js

25 lines
723 B
JavaScript

const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const db = require('../../../../models');
const chainquery = require('chainquery');
/*
route to get a short claim id from long claim Id
*/
const claimShortId = async ({ ip, originalUrl, body, params }, res) => {
try {
let shortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(params.longId, params.name).catch(() => {});
if(shortId === null) {
shortId = await db.Claim.getShortClaimIdFromLongClaimId(params.longId, params.name);
}
res.status(200).json({success: true, data: shortId});
} catch(error) {
handleErrorResponse(originalUrl, ip, error, res);
}
};
module.exports = claimShortId;