diff --git a/controllers/dispute.js b/controllers/dispute.js index a41675a..26eb80a 100644 --- a/controllers/dispute.js +++ b/controllers/dispute.js @@ -8,13 +8,10 @@ exports.updateDisputeProfile = async (req, res) => { const bodyContract = req.body const dispute = await getDisputeDb(arbitratorAddress, disputeId) - // don't want to lose our subscribers on update - let subscribers = [] - if (dispute) subscribers = dispute.subscribers + // update db with body const newDispute = await updateDisputeDb(new Dispute({ - ...bodyContract, - subscribers + ...bodyContract })) return res.status(201).json(newDispute) } @@ -27,18 +24,6 @@ exports.getDispute = async (req, res) => { return res.json(dispute) } -exports.addSubscriber = async (req, res) => { - const disputeId = req.params.disputeId - const arbitratorAddress = req.params.arbitratorAddress - const address = req.body.address - - const dispute = await getDisputeDb(arbitratorAddress, disputeId) - dispute.subscribers.push(address) - - await updateDisputeDb(dispute) - return res.status(201).json(dispute) -} - const getDisputeDb = (arbitratorAddress, disputeId) => { return new Promise((resolve, reject) => { Dispute diff --git a/controllers/profile.js b/controllers/profile.js index 52e761d..70cec2a 100644 --- a/controllers/profile.js +++ b/controllers/profile.js @@ -177,9 +177,9 @@ exports.addNotification = async (req, res) => { const txHash = req.params.txHash const notficationDetails = req.body let ProfileInstance = await getProfileDb(address) - // if not exists, we create this new user + if (_.isNull(ProfileInstance)) - throw new Error('Profile does not exist') + return res.status(400).json({"message": `Profile ${address} does not exist`}) const indexContract = ProfileInstance.notifications.findIndex( notification => { diff --git a/models/Disputes.js b/models/Disputes.js index a8929f3..edaad7f 100644 --- a/models/Disputes.js +++ b/models/Disputes.js @@ -2,7 +2,6 @@ const mongoose = require('mongoose') const Schema = mongoose.Schema const DisputesSchema = new Schema({ - hash: String, id: String, disputeId: Number, arbitratorAddress: String, @@ -10,21 +9,16 @@ const DisputesSchema = new Schema({ partyA : String, partyB : String, title : String, - deadline : Number, - status : String, - fee: Number, information : String, justification : String, - subscribers: [], // jurors can subscribe to notifications for a dispute - ruling: Number, // 0 means no decision - session: Number, // session that dispute was active resolutionOptions: [{ name: String, description: String, value: Number }], - createdAt: Number, - ruledAt: Number, + appealCreatedAt: [], + appealRuledAt: [], + appealDeadlines: [], updated_at: { type: Date, default: Date.now diff --git a/models/Profile.js b/models/Profile.js index 403f52c..aa23cf2 100644 --- a/models/Profile.js +++ b/models/Profile.js @@ -29,9 +29,7 @@ const ProfileSchema = new Schema({ disputes : [{ disputeId: Number, // joint key arbitratorAddress: String, // joint key - isJuror: Boolean, - hasRuled: Boolean, - votes: [Number], + appealDraws: [], netPNK: Number }], notifications: [{ diff --git a/routes/index.js b/routes/index.js index 6bc9487..0765561 100644 --- a/routes/index.js +++ b/routes/index.js @@ -207,29 +207,6 @@ router.get( DisputeHandlers.getDispute ) -/** - * @api {get} arbitrators/:arbitratorAddress/disputes/:disputeId fetch dispute by arbitrator address and disputeId - * - * @apiGroup Profile - * - * @apiParam {String} unique hash of the dispute - * - * - * @apiSuccessExample {json} Success - * HTTP/1.1 200 OK - * { - * "_id": "59aca9607879b17103bb1b43", - * "contracts": [], - * "disputes": [], - * "__v": 0, - * "created_at": "2017-09-04T01:16:16.726Z" - * } - */ -router.post( - '/arbitrators/:arbitratorAddress/disputes/:disputeId/subscribers', - DisputeHandlers.addSubscriber -) - /** * @api {post} arbitrators/:arbitratorAddress Add/Update a arbitrator * diff --git a/tests/disputes.test.js b/tests/disputes.test.js index 63cc255..699084b 100644 --- a/tests/disputes.test.js +++ b/tests/disputes.test.js @@ -5,7 +5,6 @@ describe('Disputes', () => { test('add subscriber to dispute', async () => { const testArbitratorAddress = "0x0" + Math.random() const testDisputeId = 1 - const testSubscriberAddress = "0x1" const fakeDispute = { disputeId: testDisputeId, @@ -17,16 +16,6 @@ describe('Disputes', () => { ).send(fakeDispute) expect(response.statusCode).toBe(201) expect(response.body.disputeId).toBe(testDisputeId) - expect(response.body.subscribers.length).toBe(0) - - response = await request(app) - .post(`/arbitrators/${testArbitratorAddress}/disputes/${testDisputeId}/subscribers`) - .send({ - address: testSubscriberAddress - }) - - expect(response.statusCode).toBe(201) - expect(response.body.subscribers.length).toBe(1) - expect(response.body.subscribers[0]).toEqual(testSubscriberAddress) + expect(response.body.arbitratorAddress).toBe(testArbitratorAddress) }) })