change sth
This commit is contained in:
parent
475bbaf807
commit
c105204d1f
@ -93,22 +93,22 @@ export class ApiServer {
|
||||
})
|
||||
}
|
||||
async connectDB() {
|
||||
const options = {
|
||||
useNewUrlParser: true,
|
||||
poolSize: 5,
|
||||
keepAlive: true,
|
||||
keepAliveInitialDelay: 300000,
|
||||
useUnifiedTopology: true,
|
||||
}
|
||||
const uri = process.env.DB_MAIN
|
||||
logger.info(`connect to ${uri} ...`)
|
||||
try {
|
||||
// await mongoose.createConnection(uri, options)
|
||||
await mongoose.connect(uri, options)
|
||||
logger.log('DB Connected')
|
||||
} catch (err) {
|
||||
logger.log(`DB Connection Error: ${err.message}`)
|
||||
}
|
||||
// const options = {
|
||||
// useNewUrlParser: true,
|
||||
// poolSize: 5,
|
||||
// keepAlive: true,
|
||||
// keepAliveInitialDelay: 300000,
|
||||
// useUnifiedTopology: true,
|
||||
// }
|
||||
// const uri = process.env.DB_MAIN
|
||||
// logger.info(`connect to ${uri} ...`)
|
||||
// try {
|
||||
// // await mongoose.createConnection(uri, options)
|
||||
// await mongoose.connect(uri, options)
|
||||
// logger.log('DB Connected')
|
||||
// } catch (err) {
|
||||
// logger.log(`DB Connection Error: ${err.message}`)
|
||||
// }
|
||||
let opts = { url: process.env.REDIS }
|
||||
new RedisClient(opts)
|
||||
logger.log('REDIS Connected')
|
||||
@ -162,7 +162,7 @@ export class ApiServer {
|
||||
public async start() {
|
||||
let self = this
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// await self.connectDB()
|
||||
await self.connectDB()
|
||||
self.initControllers()
|
||||
self.registerRouter()
|
||||
// self.setErrHandler()
|
||||
|
@ -6,6 +6,7 @@ import { ChainQueue } from 'queue/chain.queue'
|
||||
import { DocumentType } from '@typegoose/typegoose'
|
||||
import { BlockChain } from 'chain/BlockChain'
|
||||
import { ZError } from 'common/ZError'
|
||||
import { RedisClient } from 'redis/RedisClient'
|
||||
|
||||
class ChainController extends BaseController {
|
||||
@role('anon')
|
||||
@ -45,11 +46,19 @@ class ChainController extends BaseController {
|
||||
@router('post /chain/query_info')
|
||||
@router('get /chain/query_info')
|
||||
async queryUserInfo(req, res) {
|
||||
let { address } = req.params
|
||||
let { address, contract } = req.params
|
||||
if (!address) {
|
||||
throw new ZError(10, 'address is required')
|
||||
}
|
||||
let info = await new BlockChain().activityReactor.getMintableCount({ user: address })
|
||||
let key = `claim_${address.toLowerCase()}`
|
||||
let tokenStr = await new RedisClient().get(key)
|
||||
if (tokenStr) {
|
||||
return { id: parseInt(tokenStr) }
|
||||
}
|
||||
let info = await new BlockChain().activityReactor.getMintableCount({ user: address, address: contract })
|
||||
if (parseInt(info) > 0) {
|
||||
await new RedisClient().set(key, info)
|
||||
}
|
||||
return { id: parseInt(info) }
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user