From beac398659262553e02c4861ed07bb5073fcf36a Mon Sep 17 00:00:00 2001 From: wenlele Date: Thu, 11 Aug 2022 09:04:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=A2=9E=E6=94=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/VideoAccess-VCMP/api/.vscode/launch.json | 2 +- .../app/lib/controllers/application/auth.js | 0 .../app/lib/controllers/application/index.js | 49 ++++++++++++++++++- .../api/app/lib/routes/application/index.js | 5 ++ 4 files changed, 53 insertions(+), 3 deletions(-) delete mode 100644 code/VideoAccess-VCMP/api/app/lib/controllers/application/auth.js diff --git a/code/VideoAccess-VCMP/api/.vscode/launch.json b/code/VideoAccess-VCMP/api/.vscode/launch.json index 14736de..2aa9572 100644 --- a/code/VideoAccess-VCMP/api/.vscode/launch.json +++ b/code/VideoAccess-VCMP/api/.vscode/launch.json @@ -16,7 +16,7 @@ "-p 4000", "-f http://localhost:4000", "-g postgres://postgres:123@10.8.30.32:5432/video_access", - "--redisHost 10.8.30.34", + "--redisHost 10.8.30.112", "--redisPort 6379", "--axyApiUrl http://127.0.0.1:4100", "--iotAuthApi http://127.0.0.1:4200", diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/application/auth.js b/code/VideoAccess-VCMP/api/app/lib/controllers/application/auth.js deleted file mode 100644 index e69de29..0000000 diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js b/code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js index 9d5e12f..3e363ba 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/application/index.js @@ -1,11 +1,56 @@ 'use strict'; const fs = require('fs'); 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 = { - - }; \ No newline at end of file + edit, + get, +}; \ No newline at end of file diff --git a/code/VideoAccess-VCMP/api/app/lib/routes/application/index.js b/code/VideoAccess-VCMP/api/app/lib/routes/application/index.js index e06bc00..2f688b1 100644 --- a/code/VideoAccess-VCMP/api/app/lib/routes/application/index.js +++ b/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) { + // 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); };