apxtrib/api/routes/nations.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-01-22 09:53:09 +00:00
const express = require( 'express' );
2023-05-16 08:31:27 +00:00
const conf = require(`${process.env.dirtown}/conf.json`);
2023-01-22 09:53:09 +00:00
// Classes
2023-04-27 04:17:20 +00:00
const Nations = require( '../models/Nations.js' );
2023-01-22 09:53:09 +00:00
// Middlewares
const checkHeaders = require( '../middlewares/checkHeaders' );
const isAuthenticated = require( '../middlewares/isAuthenticated' );
const router = express.Router();
/*
Manage the social world
@Todo
Manage a new nation
A major create a nation with at least a town => nation:{name, towns:[]} contracts/nationname.js + contracts/townsname.js
Manage a new towns in a nation => update nation:[nationname:towns:[]} contracts/townname.js
*/
router.post( '/push', checkHeaders, ( req, res ) => {
2023-03-27 05:52:21 +00:00
// Get information from other apxtrib instance in req.body
2023-01-22 09:53:09 +00:00
// check req.body.hashnext => means this is a candidate to validate next block
//
// return it's own information back with the last call to Nationchains.synchronize()
2023-05-16 08:31:27 +00:00
res.send( { status: 200, payload: { moreinfo: fs.readFileSync( `${conf.tribes}/${conf.mayorId}/nationchains/nodes/${conf.rootURL}`, 'utf-8' ) } } )
2023-01-22 09:53:09 +00:00
} )
2023-05-12 05:59:32 +00:00
router.get('/synchro',checkHeaders, isAuthenticated,(req,res)=>{
// run a sync from a list of electedtown to update nationchains folder
console.log('TODO')
})
2023-01-22 09:53:09 +00:00
module.exports = router;