Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions controllers/dispute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions controllers/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
12 changes: 3 additions & 9 deletions models/Disputes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@ const mongoose = require('mongoose')
const Schema = mongoose.Schema

const DisputesSchema = new Schema({
hash: String,
id: String,
disputeId: Number,
arbitratorAddress: String,
contractAddress: String,
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
Expand Down
4 changes: 1 addition & 3 deletions models/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand Down
23 changes: 0 additions & 23 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
13 changes: 1 addition & 12 deletions tests/disputes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
})
})