Browse Source

获取已绑定项目并分页

dev
巴林闲侠 3 years ago
parent
commit
808abc1570
  1. 120
      api/app/lib/controllers/project/bind.js
  2. 8
      api/app/lib/controllers/project/index.js

120
api/app/lib/controllers/project/bind.js

@ -3,72 +3,72 @@
async function bindAnxin2pep (ctx) { async function bindAnxin2pep (ctx) {
const transaction = await ctx.fs.dc.orm.transaction(); const transaction = await ctx.fs.dc.orm.transaction();
try { try {
const models = ctx.fs.dc.models; // const models = ctx.fs.dc.models;
const { clickHouse } = ctx.app.fs // const { clickHouse } = ctx.app.fs
const { bindId, name, pepProjectId, anxinProjectId = [], app = [] } = ctx.request.body // const { bindId, name, pepProjectId, anxinProjectId = [], app = [] } = ctx.request.body
let bindId_ = bindId // let bindId_ = bindId
const existRes = await models.ProjectCorrelation.findOne({ // const existRes = await models.ProjectCorrelation.findOne({
where: { // where: {
pepProjectId: pepProjectId // pepProjectId: pepProjectId
} // }
}) // })
let storageData = { // let storageData = {
name, pepProjectId, anxinProjectId, // name, pepProjectId, anxinProjectId,
} // }
if (bindId_) { // if (bindId_) {
if (!existRes) { // if (!existRes) {
throw '尚无已绑定的项企项目' // throw '尚无已绑定的项企项目'
} // }
// 修改 // // 修改
await models.ProjectCorrelation.update(storageData, { // await models.ProjectCorrelation.update(storageData, {
where: { // where: {
pepProjectId: pepProjectId // pepProjectId: pepProjectId
}, // },
transaction // transaction
}) // })
} else { // } else {
// 新增 // // 新增
if (existRes) { // if (existRes) {
// 但是有之前的数据 // // 但是有之前的数据
if (existRes.del) { // if (existRes.del) {
// 不过之前的删除了 // // 不过之前的删除了
} else { // } else {
// 没有删除 重复添加 // // 没有删除 重复添加
throw '当前项企项目已绑定' // throw '当前项企项目已绑定'
} // }
} else { // } else {
const createRes = await models.ProjectCorrelation.create(storageData, { // const createRes = await models.ProjectCorrelation.create(storageData, {
transaction // transaction
}) // })
bindId_ = createRes.id // bindId_ = createRes.id
await models.ProjectApp.bulkCreate(app.map((a, i, arr) => { // await models.ProjectApp.bulkCreate(app.map((a, i, arr) => {
if (!a.name || !a.url) { // if (!a.name || !a.url) {
throw `${a.name} ${a.url} 缺少必要参数` // throw `${a.name} ${a.url} 缺少必要参数`
} // }
let curUrlArr = a.url.split('://') // let curUrlArr = a.url.split('://')
if(curUrlArr.length < 2){ // if(curUrlArr.length < 2){
throw `${a.name} ${a.url} url 地址错误` // throw `${a.name} ${a.url} url 地址错误`
} // }
for (let ii = i; ii < arr.length; ii++) { // for (let ii = i; ii < arr.length; ii++) {
let // let
} // }
return { // return {
name: a.name, // name: a.name,
url: a.url, // url: a.url,
projectId: bindId_, // projectId: bindId_,
lock: false, // lock: false,
} // }
})) // }))
} // }
} // }
await transaction.commit(); // await transaction.commit();
ctx.status = 204; // ctx.status = 204;
} catch (error) { } catch (error) {
await transaction.rollback(); await transaction.rollback();
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);

8
api/app/lib/controllers/project/index.js

@ -50,6 +50,9 @@ async function pomsProject (ctx) {
} }
const proRes = await models.ProjectCorrelation.findAll(findOption) const proRes = await models.ProjectCorrelation.findAll(findOption)
delete findOption.limit
delete findOption.offset
const proCount = await models.ProjectCorrelation.count(findOption)
let pepProjectIds = new Set() let pepProjectIds = new Set()
let anxinProjectIds = new Set() let anxinProjectIds = new Set()
@ -76,7 +79,10 @@ async function pomsProject (ctx) {
delete p.dataValues.anxinProjectId delete p.dataValues.anxinProjectId
} }
ctx.status = 200; ctx.status = 200;
ctx.body = proRes ctx.body = {
count: proCount,
rows: proRes
}
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400; ctx.status = 400;

Loading…
Cancel
Save