|
|
@ -527,10 +527,26 @@ async function getTagMetadata (ctx) { |
|
|
|
//申请资源
|
|
|
|
async function postMetadataResourceApplications(ctx) { |
|
|
|
try { |
|
|
|
const { resourceName, applyBy, resourceType, resourceId, restServiceId } = ctx.request.body; |
|
|
|
const { resourceName, applyBy, resourceType, resourceId, restServiceId, resourceCatalogId } = ctx.request.body; |
|
|
|
const models = ctx.fs.dc.models; |
|
|
|
if (restServiceId) { |
|
|
|
await models.ResourceConsumption.create({ applyAt: moment(), approveState: '审批中', ...ctx.request.body }); |
|
|
|
let resetapi = await models.RestfulApi.findOne({ |
|
|
|
where: { id: restServiceId }, |
|
|
|
include: [{ |
|
|
|
model: models.ResourceCatalog, |
|
|
|
attributes: ['id', 'name'], |
|
|
|
include: [{ |
|
|
|
model: models.Organization, |
|
|
|
attributes: ['id', 'name'], |
|
|
|
}] |
|
|
|
}] |
|
|
|
}) |
|
|
|
|
|
|
|
const dataToSave = { applyAt: moment(), approveState: '审批中', ...ctx.request.body } |
|
|
|
if (resetapi && resetapi.resourceCatalog && resetapi.resourceCatalog.organization) { |
|
|
|
dataToSave.orgId = resetapi.resourceCatalog.organization.id |
|
|
|
} |
|
|
|
await models.ResourceConsumption.create(dataToSave); |
|
|
|
ctx.body = { message: '申请资源成功' } |
|
|
|
ctx.status = 200; |
|
|
|
} else { |
|
|
@ -538,7 +554,6 @@ async function postMetadataResourceApplications (ctx) { |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { message: '参数不全,请重新申请资源' } |
|
|
|
} else { |
|
|
|
|
|
|
|
const postOne = await models.ResourceConsumption.findOne({ |
|
|
|
where: { applyBy: applyBy, resourceName: resourceName, resourceId, resourceType, approve_remarks: null } |
|
|
|
}); |
|
|
@ -546,7 +561,17 @@ async function postMetadataResourceApplications (ctx) { |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { message: '该用户已申请过该元数据资源' } |
|
|
|
} else { |
|
|
|
await models.ResourceConsumption.create({ applyAt: moment(), approveState: '审批中', ...ctx.request.body }); |
|
|
|
let resourceCatalog = await models.ResourceCatalog.findOne({ |
|
|
|
where: { id: resourceCatalogId }, |
|
|
|
include: [ |
|
|
|
{ model: models.Organization } |
|
|
|
] |
|
|
|
}) |
|
|
|
const dataToSave = { applyAt: moment(), approveState: '审批中', ...ctx.request.body } |
|
|
|
if (resourceCatalog && resourceCatalog.organization) { |
|
|
|
dataToSave.orgId = resourceCatalog.organization.id |
|
|
|
} |
|
|
|
await models.ResourceConsumption.create(dataToSave); |
|
|
|
ctx.body = { message: '申请资源成功' } |
|
|
|
ctx.status = 200; |
|
|
|
} |
|
|
|