mirror of
https://github.com/typicode/json-server.git
synced 2025-08-01 09:13:32 +08:00
eslint --fix
This commit is contained in:
@ -53,30 +53,28 @@ module.exports = (source, opts = { foreignKeySuffix: 'Id' }) => {
|
|||||||
router.use(nested(opts))
|
router.use(nested(opts))
|
||||||
|
|
||||||
// Create routes
|
// Create routes
|
||||||
db
|
db.forEach((value, key) => {
|
||||||
.forEach((value, key) => {
|
if (_.isPlainObject(value)) {
|
||||||
if (_.isPlainObject(value)) {
|
router.use(`/${key}`, singular(db, key))
|
||||||
router.use(`/${key}`, singular(db, key))
|
return
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (_.isArray(value)) {
|
if (_.isArray(value)) {
|
||||||
router.use(`/${key}`, plural(db, key, opts))
|
router.use(`/${key}`, plural(db, key, opts))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var sourceMessage = ''
|
var sourceMessage = ''
|
||||||
if (!_.isObject(source)) {
|
if (!_.isObject(source)) {
|
||||||
sourceMessage = `in ${source}`
|
sourceMessage = `in ${source}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const msg =
|
const msg =
|
||||||
`Type of "${key}" (${typeof value}) ${sourceMessage} is not supported. ` +
|
`Type of "${key}" (${typeof value}) ${sourceMessage} is not supported. ` +
|
||||||
`Use objects or arrays of objects.`
|
`Use objects or arrays of objects.`
|
||||||
|
|
||||||
throw new Error(msg)
|
throw new Error(msg)
|
||||||
})
|
}).value()
|
||||||
.value()
|
|
||||||
|
|
||||||
router.use((req, res) => {
|
router.use((req, res) => {
|
||||||
if (!res.locals.data) {
|
if (!res.locals.data) {
|
||||||
|
@ -299,8 +299,7 @@ module.exports = (db, name, opts) => {
|
|||||||
// Remove dependents documents
|
// Remove dependents documents
|
||||||
const removable = db._.getRemovable(db.getState(), opts)
|
const removable = db._.getRemovable(db.getState(), opts)
|
||||||
removable.forEach(item => {
|
removable.forEach(item => {
|
||||||
db
|
db.get(item.name)
|
||||||
.get(item.name)
|
|
||||||
.removeById(item.id)
|
.removeById(item.id)
|
||||||
.value()
|
.value()
|
||||||
})
|
})
|
||||||
|
@ -27,8 +27,7 @@ module.exports = (db, name) => {
|
|||||||
if (req.method === 'PUT') {
|
if (req.method === 'PUT') {
|
||||||
db.set(name, req.body).value()
|
db.set(name, req.body).value()
|
||||||
} else {
|
} else {
|
||||||
db
|
db.get(name)
|
||||||
.get(name)
|
|
||||||
.assign(req.body)
|
.assign(req.body)
|
||||||
.value()
|
.value()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user