4 changed files with 373 additions and 309 deletions
@ -0,0 +1,45 @@ |
|||
'use strict'; |
|||
|
|||
async function get (ctx, next) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { limit, page, orderBy, orderDirection } = ctx.query |
|||
const { userId } = ctx.fs.api |
|||
|
|||
let findOption = { |
|||
attributes: { exclude: ['delete', 'recycleTime',] }, |
|||
where: { |
|||
createUserId: userId, |
|||
recycleTime: null, |
|||
delete: false |
|||
}, |
|||
order: [ |
|||
[orderBy || 'id', orderDirection || 'DESC'] |
|||
], |
|||
include: [{ |
|||
model: models.CameraAbility |
|||
}, { |
|||
model: models.CameraKind |
|||
}] |
|||
} |
|||
if (limit) { |
|||
findOption.limit = limit |
|||
} |
|||
if (page && limit) { |
|||
findOption.offset = page * limit |
|||
} |
|||
|
|||
const cameraRes = await models.Camera.findAll(findOption) |
|||
|
|||
ctx.status = 200; |
|||
ctx.body = cameraRes |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = {} |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
get, |
|||
}; |
@ -0,0 +1,8 @@ |
|||
'use strict'; |
|||
|
|||
const camera = require('../../controllers/camera'); |
|||
|
|||
module.exports = function (app, router, opts) { |
|||
app.fs.api.logAttr['GET/camera'] = { content: '获取摄像头列表', visible: false }; |
|||
router.get('/camera', camera.get); |
|||
}; |
Loading…
Reference in new issue