-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3055 from bcgov/fix/3052
fix(3052): add missing private cloud create requests
- Loading branch information
Showing
3 changed files
with
172 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
data-migrations/migrations/20240607161718-add_missing_create_requests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
export const up = async (db, client) => { | ||
const session = client.startSession(); | ||
|
||
await session.withTransaction(async () => { | ||
const privateCloudProducts = await db.collection('PrivateCloudProject').find({}).sort({ createdAt: 1 }).toArray(); | ||
|
||
const result = []; | ||
|
||
await Promise.all( | ||
privateCloudProducts.map(async (product) => { | ||
const count = await db.collection('PrivateCloudRequest').count({ licencePlate: { $eq: product.licencePlate } }); | ||
|
||
if (count === 0) { | ||
result.push({ licencePlate: product.licencePlate, status: product.status, createdAt: product.createdAt }); | ||
|
||
const po = await db.collection('User').findOne({ _id: { $eq: product.projectOwnerId } }); | ||
|
||
const reqObj = { | ||
name: product.name, | ||
description: product.description, | ||
status: 'ACTIVE', | ||
licencePlate: product.licencePlate, | ||
projectOwnerId: product.projectOwnerId, | ||
primaryTechnicalLeadId: product.primaryTechnicalLeadId, | ||
secondaryTechnicalLeadId: product.secondaryTechnicalLeadId, | ||
ministry: product.ministry, | ||
cluster: product.cluster, | ||
golddrEnabled: product.golddrEnabled, | ||
productionQuota: product.productionQuota, | ||
testQuota: product.testQuota, | ||
developmentQuota: product.developmentQuota, | ||
toolsQuota: product.toolsQuota, | ||
commonComponents: product.commonComponents, | ||
isTest: product.isTest, | ||
createdAt: product.createdAt, | ||
}; | ||
|
||
const decisionData = await db.collection('PrivateCloudRequestedProject').insertOne({ ...reqObj }); | ||
const requestData = await db.collection('PrivateCloudRequestedProject').insertOne({ ...reqObj }); | ||
|
||
await db.collection('PrivateCloudRequest').insertOne({ | ||
licencePlate: product.licencePlate, | ||
createdByEmail: po.email, | ||
type: 'CREATE', | ||
decisionStatus: 'PROVISIONED', | ||
isQuotaChanged: false, | ||
active: false, | ||
updatedAt: product.createdAt, | ||
decisionDataId: decisionData.insertedId, | ||
requestDataId: requestData.insertedId, | ||
decisionMakerEmail: '', | ||
decisionComment: '', | ||
decisionDate: product.createdAt, | ||
createdAt: product.createdAt, | ||
}); | ||
} | ||
}), | ||
); | ||
|
||
console.log('add_missing_create_requests:', result); | ||
}); | ||
|
||
session.endSession(); | ||
}; | ||
|
||
export const down = async (db, client) => {}; |