Skip to content

Commit

Permalink
save fulfillment
Browse files Browse the repository at this point in the history
  • Loading branch information
tenthirtyone committed Mar 31, 2021
1 parent e8304e3 commit 7b8a43d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
14 changes: 10 additions & 4 deletions client/src/components/BountyPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,22 +284,28 @@ export default function (props) {
};

const fulfill = async () => {
console.log(fulfillment);
let tx;
try {
await makeFulfillment(
tx = await makeFulfillment(
accounts[0],
contract,
bountyId,
fulfillment.attachment
);
await saveFulfillment(fulfillment);
const { _fulfillmentId } = tx.events.BountyFulfilled.returnValues;
await saveFulfillment({
...fulfillment,
owner: accounts[0],
fulfillers: [accounts[0]],
bountyId,
fulfillmentId: _fulfillmentId,
});
} catch (e) {
console.log(e);
return;
}

// Post fulfillment
console.log("finished");
};

return (
Expand Down
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ class BountiesAdmin {
process.exit();
}

async saveFulfillment(fulfillment) {
this.logger.info(
`Saving Fulfillment, bountyId: ${fulfillment.bountyId} fulfillmentId: ${fulfillment.fulfillmentId}`
);

return await this.db.models.Fulfillment(fulfillment).save();
}
async saveBounty(bounty) {
this.logger.info(`Saving Bounty: ${bounty.title}`);

Expand Down
18 changes: 18 additions & 0 deletions lib/db/models/Fulfillment.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const fulfillment = new Schema({
bountyId: { type: Number },
fulfillmentId: { type: Number },
owner: { type: String },
fulfillers: { type: [String] },
contactName: { type: String },
contactEmail: { type: String },
webLink: { type: String },
attachment: { type: String },
description: { type: String },
});

const Fulfillment = mongoose.model("Fulfillment", fulfillment);

module.exports = Fulfillment;
2 changes: 2 additions & 0 deletions lib/db/models/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const Bounty = require("./Bounty.model");
const Fulfillment = require("./Fulfillment.model");
const AccountSettings = require("./AccountSettings.model");

module.exports = {
Bounty,
Fulfillment,
AccountSettings,
};
6 changes: 2 additions & 4 deletions lib/routes/Bounties/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ router.put("/", async (req, res) => {
router.post("/fulfillment", async (req, res) => {
const { fulfillment } = req.body;
const bountiesAdmin = req.app.get("bountiesAdmin");
console.log(fulfillment);
try {
const { address } = req.session.passport.user;

//await bountiesAdmin.saveFulfillment(fulfillment);
try {
await bountiesAdmin.saveFulfillment(fulfillment);
} catch (e) {
return res.status(400).send();
}
Expand Down

0 comments on commit 7b8a43d

Please sign in to comment.