You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
'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 = {
|
|
|
|
edit,
|
|
|
|
get,
|
|
|
|
};
|