Skip to content

Commit

Permalink
Merge pull request #116 from pshenmic/feat/linting
Browse files Browse the repository at this point in the history
Enforce Javascript Standard linting rules
  • Loading branch information
pshenmic authored Apr 23, 2024
2 parents d983292 + 75a1324 commit a2159c7
Show file tree
Hide file tree
Showing 43 changed files with 3,496 additions and 8,815 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
- name: NPM install
run: cd packages/api && npm install

- name: Check lint rules
run: cd packages/api && npm run lint

- name: Run unit tests
run: cd packages/api && npm run test:unit

Expand Down
4 changes: 2 additions & 2 deletions packages/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ require('dotenv').config()
const server = require('./src/server')

server.start()
.then((_server) => server.listen(_server))
.then(() => console.log(`Platform Explorer API started`))
.then((_server) => server.listen(_server))
.then(() => console.log('Platform Explorer API started'))
4 changes: 3 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"test:unit": "node --test test/unit/*.spec.js",
"test:integration": "node --test --test-concurrency=1 test/integration/*.spec.js",
"db:migrate": "node ./test/utils/migrate.js ../indexer/migrations",
"db:drop": "node ./test/utils/drop.js"
"db:drop": "node ./test/utils/drop.js",
"lint": "standard ."
},
"dependencies": {
"@fastify/cors": "^8.3.0",
Expand All @@ -21,6 +22,7 @@
"pg": "^8.11.3"
},
"devDependencies": {
"standard": "^17.1.0",
"supertest": "^6.3.4"
}
}
14 changes: 7 additions & 7 deletions packages/api/src/cache.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
let cacheStorage = {}
const cacheStorage = {}

const cache = {}

cache.set = (key, value, timeout) => {
cacheStorage[key] = value
cacheStorage[key] = value

if (timeout) {
setTimeout(() => cache.delete(key), timeout)
}
if (timeout) {
setTimeout(() => cache.delete(key), timeout)
}
}

cache.delete = (key) => {
cacheStorage[key] = undefined
cacheStorage[key] = undefined
}

cache.get = (key) => cacheStorage[key]
cache.get = (key) => cacheStorage[key]

module.exports = cache
22 changes: 11 additions & 11 deletions packages/api/src/constants.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module.exports = {
BLOCK_TIME: 5000,
StateTransitionEnum: {
DATA_CONTRACT_CREATE: 0,
DOCUMENTS_BATCH: 1,
IDENTITY_CREATE: 2,
IDENTITY_TOP_UP: 3,
DATA_CONTRACT_UPDATE: 4,
IDENTITY_UPDATE: 5,
IDENTITY_CREDIT_WITHDRAWAL: 6,
IDENTITY_CREDIT_TRANSFER: 7
}
BLOCK_TIME: 5000,
StateTransitionEnum: {
DATA_CONTRACT_CREATE: 0,
DOCUMENTS_BATCH: 1,
IDENTITY_CREATE: 2,
IDENTITY_TOP_UP: 3,
DATA_CONTRACT_UPDATE: 4,
IDENTITY_UPDATE: 5,
IDENTITY_CREDIT_WITHDRAWAL: 6,
IDENTITY_CREDIT_TRANSFER: 7
}
}
41 changes: 20 additions & 21 deletions packages/api/src/controllers/BlocksController.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
const Block = require('../models/Block');
const BlocksDAO = require('../dao/BlocksDAO');
const BlocksDAO = require('../dao/BlocksDAO')

class BlocksController {
constructor(knex) {
this.blocksDAO = new BlocksDAO(knex)
}

getBlockByHash = async (request, response) => {
const {hash} = request.params
constructor (knex) {
this.blocksDAO = new BlocksDAO(knex)
}

const block = await this.blocksDAO.getBlockByHash(hash)
getBlockByHash = async (request, response) => {
const { hash } = request.params

if (!block) {
return response.status(404).send({message: 'not found'})
}
const block = await this.blocksDAO.getBlockByHash(hash)

response.send(block);
if (!block) {
return response.status(404).send({ message: 'not found' })
}

getBlocks = async (request, response) => {
const {page = 1, limit = 10, order = 'asc'} = request.query

if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values`})
}
response.send(block)
}

const blocks = await this.blocksDAO.getBlocks(Number(page), Number(limit), order)
getBlocks = async (request, response) => {
const { page = 1, limit = 10, order = 'asc' } = request.query

response.send(blocks);
if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({ message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values` })
}

const blocks = await this.blocksDAO.getBlocks(Number(page), Number(limit), order)

response.send(blocks)
}
}

module.exports = BlocksController
41 changes: 20 additions & 21 deletions packages/api/src/controllers/DataContractsController.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
const DataContract = require("../models/DataContract");
const DataContractsDAO = require("../dao/DataContractsDAO");
const DataContractsDAO = require('../dao/DataContractsDAO')

class DataContractsController {
constructor(knex) {
this.dataContractsDAO = new DataContractsDAO(knex)
}

getDataContractByIdentifier = async (request, response) => {
const {identifier} = request.params
constructor (knex) {
this.dataContractsDAO = new DataContractsDAO(knex)
}

const dataContract = await this.dataContractsDAO.getDataContractByIdentifier(identifier)
getDataContractByIdentifier = async (request, response) => {
const { identifier } = request.params

if (!dataContract) {
response.status(404).send({message: 'not found'})
}
const dataContract = await this.dataContractsDAO.getDataContractByIdentifier(identifier)

response.send(dataContract);
if (!dataContract) {
response.status(404).send({ message: 'not found' })
}

getDataContracts = async (request, response) => {
const {page = 1, limit = 10, order = 'asc'} = request.query

if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values`})
}
response.send(dataContract)
}

const dataContracts = await this.dataContractsDAO.getDataContracts(Number(page), Number(limit), order);
getDataContracts = async (request, response) => {
const { page = 1, limit = 10, order = 'asc' } = request.query

response.send(dataContracts)
if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({ message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values` })
}

const dataContracts = await this.dataContractsDAO.getDataContracts(Number(page), Number(limit), order)

response.send(dataContracts)
}
}

module.exports = DataContractsController
43 changes: 21 additions & 22 deletions packages/api/src/controllers/DocumentsController.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
const Document = require('../models/Document');
const DocumentsDAO = require('../dao/DocumentsDAO');
const DocumentsDAO = require('../dao/DocumentsDAO')

class DocumentsController {
constructor(knex) {
this.documentsDAO = new DocumentsDAO(knex)
}

getDocumentByIdentifier = async (request, response) => {
const {identifier} = request.params
constructor (knex) {
this.documentsDAO = new DocumentsDAO(knex)
}

const document = await this.documentsDAO.getDocumentByIdentifier(identifier)
getDocumentByIdentifier = async (request, response) => {
const { identifier } = request.params

if (!document) {
response.status(404).send({message: 'not found'})
}
const document = await this.documentsDAO.getDocumentByIdentifier(identifier)

response.send(document);
if (!document) {
response.status(404).send({ message: 'not found' })
}

getDocumentsByDataContract = async (request, response) => {
const {identifier} = request.params
const {page = 1, limit = 10, order = 'asc'} = request.query

if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values`})
}
response.send(document)
}

const documents = await this.documentsDAO.getDocumentsByDataContract(identifier, Number(page), Number(limit), order)
getDocumentsByDataContract = async (request, response) => {
const { identifier } = request.params
const { page = 1, limit = 10, order = 'asc' } = request.query

response.send(documents);
if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({ message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values` })
}

const documents = await this.documentsDAO.getDocumentsByDataContract(identifier, Number(page), Number(limit), order)

response.send(documents)
}
}

module.exports = DocumentsController
104 changes: 52 additions & 52 deletions packages/api/src/controllers/IdentitiesController.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,85 @@
const IdentitiesDAO = require("../dao/IdentitiesDAO");
const IdentitiesDAO = require('../dao/IdentitiesDAO')

class IdentitiesController {
constructor(knex) {
this.identitiesDAO = new IdentitiesDAO(knex)
}

getIdentityByIdentifier = async (request, response) => {
const {identifier} = request.params;
constructor (knex) {
this.identitiesDAO = new IdentitiesDAO(knex)
}

const identity = await this.identitiesDAO.getIdentityByIdentifier(identifier)
getIdentityByIdentifier = async (request, response) => {
const { identifier } = request.params

if (!identity) {
return response.status(404).send({message: 'not found'})
}
const identity = await this.identitiesDAO.getIdentityByIdentifier(identifier)

response.send(identity)
if (!identity) {
return response.status(404).send({ message: 'not found' })
}

getIdentities = async (request, response) => {
const {page = 1, limit = 10, order = 'asc'} = request.query

if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values`})
}
response.send(identity)
}

const identities = await this.identitiesDAO.getIdentities(Number(page), Number(limit), order)
getIdentities = async (request, response) => {
const { page = 1, limit = 10, order = 'asc' } = request.query

response.send(identities)
if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({ message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values` })
}

getTransactionsByIdentity = async (request, response) => {
const {identifier} = request.params
const {page = 1, limit = 10, order = 'asc'} = request.query
const identities = await this.identitiesDAO.getIdentities(Number(page), Number(limit), order)

if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values`})
}
response.send(identities)
}

const transactions = await this.identitiesDAO.getTransactionsByIdentity(identifier, Number(page), Number(limit), order)
getTransactionsByIdentity = async (request, response) => {
const { identifier } = request.params
const { page = 1, limit = 10, order = 'asc' } = request.query

response.send(transactions)
if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({ message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values` })
}

getDataContractsByIdentity = async (request, response) => {
const {identifier} = request.params
const {page = 1, limit = 10, order = 'asc'} = request.query
const transactions = await this.identitiesDAO.getTransactionsByIdentity(identifier, Number(page), Number(limit), order)

if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values`})
}
response.send(transactions)
}

const dataContracts = await this.identitiesDAO.getDataContractsByIdentity(identifier, Number(page), Number(limit), order)
getDataContractsByIdentity = async (request, response) => {
const { identifier } = request.params
const { page = 1, limit = 10, order = 'asc' } = request.query

response.send(dataContracts)
if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({ message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values` })
}

getDocumentsByIdentity = async (request, response) => {
const {identifier} = request.params
const {page = 1, limit = 10, order = 'asc'} = request.query
const dataContracts = await this.identitiesDAO.getDataContractsByIdentity(identifier, Number(page), Number(limit), order)

if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values`})
}
response.send(dataContracts)
}

const documents = await this.identitiesDAO.getDocumentsByIdentity(identifier, Number(page), Number(limit), order)
getDocumentsByIdentity = async (request, response) => {
const { identifier } = request.params
const { page = 1, limit = 10, order = 'asc' } = request.query

response.send(documents)
if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({ message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values` })
}

getTransfersByIdentity = async (request, response) => {
const {identifier} = request.params
const {page = 1, limit = 10, order = 'asc'} = request.query
const documents = await this.identitiesDAO.getDocumentsByIdentity(identifier, Number(page), Number(limit), order)

if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values`})
}
response.send(documents)
}

const transfers = await this.identitiesDAO.getTransfersByIdentity(identifier, Number(page), Number(limit), order)
getTransfersByIdentity = async (request, response) => {
const { identifier } = request.params
const { page = 1, limit = 10, order = 'asc' } = request.query

response.send(transfers)
if (order !== 'asc' && order !== 'desc') {
return response.status(400).send({ message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values` })
}

const transfers = await this.identitiesDAO.getTransfersByIdentity(identifier, Number(page), Number(limit), order)

response.send(transfers)
}
}

module.exports = IdentitiesController
Loading

0 comments on commit a2159c7

Please sign in to comment.