-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
li zhang
committed
Jan 9, 2019
1 parent
b99b2cf
commit 94acc15
Showing
23 changed files
with
250 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
process.env.NODE_ENV = 'dev' | ||
|
||
module.exports = require('../src/util/readToml')(`/config/${process.env.NODE_ENV}.toml`) |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const Router = require('koa-router') | ||
const router = new Router() | ||
|
||
const service = require('../../service/weaponService') | ||
const valid = require('../../valid') | ||
|
||
router.post('/bb/weapon', async(ctx, next) => { | ||
let e = { | ||
name: ctx.params.name, | ||
phy: ctx.params.phy || 0, | ||
bld: ctx.params.bld || 0, | ||
} | ||
valid.string('weapon.name', e.name).is().lengthIn(1, 20) | ||
valid.number('weapon.phy', e.phy).is().in(500) | ||
valid.number('weapon.bld', e.bld).is().in(500) | ||
e = await service.save(e) | ||
ctx.ok(e._id) | ||
}) | ||
|
||
router.delete('/bb/weapon/:_id', async(ctx, next) => { | ||
let e = { | ||
_id: ctx.params._id, | ||
} | ||
await service.delete(e) | ||
ctx.ok() | ||
}) | ||
|
||
router.put('/bb/weapon/:_id', async(ctx, next) => { | ||
let e = { | ||
_id: ctx.params._id, | ||
name: ctx.params.name, | ||
phy: ctx.params.phy, | ||
bld: ctx.params.bld, | ||
} | ||
if (e.name) valid.string('weapon.name', e.name).is().lengthIn(1, 20) | ||
if (e.phy) valid.number('weapon.phy', e.phy).is().in(500) | ||
if (e.bld) valid.number('weapon.bld', e.bld).is().in(500) | ||
await service.update(e) | ||
ctx.ok() | ||
}) | ||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const Router = require('koa-router') | ||
const router = new Router() | ||
|
||
const service = require('../../service/weaponService') | ||
|
||
router.get('/weapon/:_id', async(ctx, next) => { | ||
let e = { | ||
_id: ctx.params._id | ||
} | ||
let weapon = await service.findById(e) | ||
ctx.ok(weapon) | ||
}) | ||
router.get('/weapon/count', async(ctx, next) => { | ||
let filter = { | ||
name: ctx.params.name || '', | ||
} | ||
let count = await service.count(filter) | ||
ctx.ok(count) | ||
}) | ||
router.get('/weapon', async(ctx, next) => { | ||
let filter = { | ||
name: ctx.params.name || '', | ||
start: parseInt(ctx.params.start) || 0, | ||
limit: parseInt(ctx.params.limit) || 10 | ||
} | ||
let list = await service.find(filter) | ||
ctx.ok(list) | ||
}) | ||
|
||
module.exports = router |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const config = require('../../config/env') | ||
const mongoose = require('mongoose') | ||
|
||
module.exports = { | ||
drop: async () => { | ||
await mongoose.connect(config.db.host, {useNewUrlParser: true}) | ||
mongoose.connection.db.dropDatabase() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const mongoose = require('mongoose') | ||
const model = mongoose.model('weapon', {name: String, phy: Number, bld: Number}) | ||
model.null = {isNull: true} | ||
module.exports = model |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
const Router = require('koa-router') | ||
const router = new Router() | ||
|
||
const xController = require('./controller/xController') | ||
router.use('', xController.routes(), xController.allowedMethods()) | ||
const bbWeaponController = require('../controller/bb/weaponController') | ||
router.use('', bbWeaponController.routes(), bbWeaponController.allowedMethods()) | ||
|
||
const weaponController = require('../controller/everyone/weaponController') | ||
router.use('', weaponController.routes(), weaponController.allowedMethods()) | ||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const model = require('../model/weapon') | ||
const failError = require('../error/failError') | ||
|
||
module.exports = { | ||
save: async(e) => { | ||
let exists = await model.findOne({name: e.name}, '-__v') | ||
if (exists) { | ||
throw new failError('data exists') | ||
} | ||
e = new model(e) | ||
await e.save() | ||
return e | ||
}, | ||
delete: async(e) => { | ||
await model.deleteOne({_id: new model(e).id}) | ||
}, | ||
update: async(e) => { | ||
let exists = await model.findOne({_id: e._id}, '-__v') | ||
let next = new model({...exists, ...e}) | ||
await next.updateOne(next) | ||
}, | ||
findById: async(e) => { | ||
return await model.findOne({_id: e._id}, '-__v') || model.null | ||
}, | ||
count: async(filter) => { | ||
return await model.countDocuments({name: {$regex: `${filter.name}.*`}}) | ||
}, | ||
find: async(filter) => { | ||
let result = await model.find({name: {$regex: `${filter.name}.*`}}, '-__v').skip(filter.start).limit(filter.limit).sort('name') | ||
return result | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
module.exports = (pathFromProjectRoot) => { | ||
let result = require('toml').parse( | ||
require('fs').readFileSync( | ||
require('path').join(__dirname, '../../', pathFromProjectRoot), | ||
'utf-8' | ||
) | ||
) | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const weaponOperator = require('./weapon/operator') | ||
|
||
module.exports = { | ||
saveWeapon: () => { | ||
weaponOperator.save() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[[list]] | ||
name = 'Chikage' | ||
phy = 92 | ||
bld = 92 | ||
[[list]] | ||
name = 'Rakuyo' | ||
phy = 82 | ||
bld = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const model = require('../../../src/model/weapon') | ||
|
||
module.exports = { | ||
save: () => { | ||
let data = require('toml').parse( | ||
require('fs').readFileSync( | ||
require('path').join(__dirname, './data.toml'), | ||
'utf-8' | ||
) | ||
) | ||
data.list.forEach(async e => { | ||
await new model(e).save() | ||
}) | ||
} | ||
} |
Oops, something went wrong.