Skip to content

Commit

Permalink
Refactor createClaimDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
stub-roh committed Nov 26, 2021
1 parent 2a28236 commit 3575aa3
Showing 1 changed file with 40 additions and 41 deletions.
81 changes: 40 additions & 41 deletions src/routes/did.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,17 @@ didRouter.post(
'didID' : didID,
'claims' : claimDoc
};

const sequelize = Utils.createConnection();
const ClaimDocs = sequelize.import('../models/claim_docs');

ClaimDocs.create(claimData)
.then(claimDocRtn => {
console.log('success to create claim doc');
rtnBody.success = true;
rtnBody.result = didID;
return res.status(201).jsonp(rtnBody);
})
.catch(err => {
console.error('fail to create claim doc : ', err);
rtnBody.errorcode = 'KDE0010';
rtnBody.errordetail = err;
return res.status(401).jsonp(err);
})
.finally(() => {
sequelize.close();
});

let errorMsg = await createClaimDoc(claimData);
if (errorMsg) {
rtnBody.errorcode = 'KDE0010';
rtnBody.errordetail = errorMsg;
return res.status(401).jsonp(err);
} else {
rtnBody.success = true;
rtnBody.result = didID;
return res.status(201).jsonp(rtnBody);
}
}

// 02-3. in case of review
Expand Down Expand Up @@ -151,25 +142,16 @@ didRouter.post(
'claims' : claimDoc
};

const sequelize = Utils.createConnection();
const ClaimDocs = sequelize.import('../models/claim_docs');

ClaimDocs.create(claimData)
.then(claimDocRtn => {
console.log('success to create claim doc');
rtnBody.success = true;
rtnBody.result = didID;
return res.status(201).jsonp(rtnBody);
})
.catch(err => {
console.error('fail to create claim doc : ', err);
rtnBody.errorcode = 'KDE0010';
rtnBody.errordetail = err;
return res.status(401).jsonp(err);
})
.finally(() => {
sequelize.close();
});
let errorMsg = await createClaimDoc(claimData);
if (errorMsg) {
rtnBody.errorcode = 'KDE0010';
rtnBody.errordetail = errorMsg;
return res.status(401).jsonp(err);
} else {
rtnBody.success = true;
rtnBody.result = didID;
return res.status(201).jsonp(rtnBody);
}
}
} catch (exp) {
console.error('fail to create claim doc : ', exp);
Expand Down Expand Up @@ -223,14 +205,14 @@ didRouter.post(
raw : true
})
.then(claimDocRtn => {
console.log('success to create claim doc : ', claimDocRtn.claims);
console.log('success to find claim doc : ', claimDocRtn.claims);
// return res.status(200).send(JSON.stringify(claimDocRtn.claims));
rtnBody.success = true;
rtnBody.result = claimDocRtn.claims;
return res.status(200).jsonp(rtnBody);
})
.catch(err => {
console.error('fail to create claim doc : ', err);
console.error('fail to find claim doc : ', err);
rtnBody.errorcode = 'KDE0010';
rtnBody.errordetail = err;
return res.status(404).jsonp(rtnBody);
Expand Down Expand Up @@ -322,3 +304,20 @@ didRouter.post(
})
);

async function createClaimDoc(claimData) {
const sequelize = Utils.createConnection();
const ClaimDocs = sequelize.import('../models/claim_docs');

await ClaimDocs.create(claimData)
.then(claimDocRtn => {
console.log('success to create claim doc');
return;
})
.catch(err => {
console.error('fail to create claim doc : ', err);
return err;
})
.finally(() => {
sequelize.close();
});
}

0 comments on commit 3575aa3

Please sign in to comment.