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

Loading…
Cancel
Save