Skip to content

Commit

Permalink
Merge pull request #14 from stub-roh/dev_review
Browse files Browse the repository at this point in the history
[Fix] review api
  • Loading branch information
stub-roh authored Nov 26, 2021
2 parents ea8beb7 + 3575aa3 commit 31fb440
Showing 1 changed file with 42 additions and 47 deletions.
89 changes: 42 additions & 47 deletions src/routes/did.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ didRouter.post(
else addressYN = true;
}
if (reviewCont) {
if (!productId || !reviewRat) {
if (!productId) {
rtnBody.errorcode = 'KDE0001';
rtnBody.errordetail = 'Req. params not existed';
return res.status(422).jsonp(rtnBody);
Expand Down Expand Up @@ -104,42 +104,29 @@ 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
if (reviewYN) {
console.debug('---step here---');
let claimDoc = {};
claimDoc["id"] = didID;

let encUserName = crypto.AES.encrypt(userName, hexPub).toString();
let encProductId = crypto.AES.encrypt(productId, hexPub).toString();
let encReviewConts = crypto.AES.encrypt(reviewCont, hexPub).toString();
let encReviewRat = crypto.AES.encrypt(reviewRat, hexPub).toString();
console.debug(encUserName);
console.debug(encProductId);
console.debug(encReviewConts);
console.debug(encReviewRat);

let claimReviewValue = {};
claimReviewValue["userName"] = encUserName;
claimReviewValue["productId"] = encProductId;
Expand All @@ -155,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 @@ -227,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 @@ -326,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 31fb440

Please sign in to comment.