Browse Source

应用增改接口

release_1.2.1
wenlele 3 years ago
parent
commit
beac398659
  1. 2
      code/VideoAccess-VCMP/api/.vscode/launch.json
  2. 0
      code/VideoAccess-VCMP/api/app/lib/controllers/application/auth.js
  3. 49
      code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js
  4. 5
      code/VideoAccess-VCMP/api/app/lib/routes/application/index.js

2
code/VideoAccess-VCMP/api/.vscode/launch.json

@ -16,7 +16,7 @@
"-p 4000", "-p 4000",
"-f http://localhost:4000", "-f http://localhost:4000",
"-g postgres://postgres:123@10.8.30.32:5432/video_access", "-g postgres://postgres:123@10.8.30.32:5432/video_access",
"--redisHost 10.8.30.34", "--redisHost 10.8.30.112",
"--redisPort 6379", "--redisPort 6379",
"--axyApiUrl http://127.0.0.1:4100", "--axyApiUrl http://127.0.0.1:4100",
"--iotAuthApi http://127.0.0.1:4200", "--iotAuthApi http://127.0.0.1:4200",

0
code/VideoAccess-VCMP/api/app/lib/controllers/application/auth.js

49
code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js

@ -1,11 +1,56 @@
'use strict'; 'use strict';
const fs = require('fs'); const fs = require('fs');
const moment = require('moment') const moment = require('moment')
const uuid = require('uuid');
async function edit (ctx, next) {
let errMsg = '创建应用失败'
const transaction = await ctx.fs.dc.orm.transaction();
try {
const { models } = ctx.fs.dc;
const { userId } = ctx.fs.api
const data = ctx.request.body;
if (data.id) {
// 修改
const storageData = Object.assign({}, data,)
await models.Application.update(storageData, {
where: {
id: data.id
},
transaction
})
} else {
// 添加
const storageData = Object.assign({}, data, {
appKey: uuid.v4(),
appSecret: uuid.v4(),
createUserId: userId,
createTime: moment().format(),
forbidden: true
})
await models.Application.create(storageData, { transaction })
}
await transaction.commit();
ctx.status = 204;
} catch (error) {
await transaction.rollback();
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: errMsg
}
}
}
module.exports = {
};
module.exports = {
edit,
get,
};

5
code/VideoAccess-VCMP/api/app/lib/routes/application/index.js

@ -5,5 +5,10 @@ const application = require('../../controllers/application');
module.exports = function (app, router, opts) { module.exports = function (app, router, opts) {
// app.fs.api.logAttr['GET/application'] = { content: '获取应用信息', visible: false };
// router.get('/application', application.get);
app.fs.api.logAttr['POST/application'] = { content: '创建/修改应用', visible: false };
router.post('/application', application.edit);
}; };

Loading…
Cancel
Save