Skip to content

Commit

Permalink
Merge pull request #3055 from bcgov/fix/3052
Browse files Browse the repository at this point in the history
fix(3052): add missing private cloud create requests
  • Loading branch information
junminahn authored Jun 7, 2024
2 parents 0962e8e + fd8f9ba commit cdc1c42
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const apiHandler = createApiHandler({
export const GET = apiHandler(async ({ pathParams, session }) => {
const { idOrLicencePlate } = pathParams;

const where = idOrLicencePlate.length > 6 ? { id: idOrLicencePlate } : { licencePlate: idOrLicencePlate };
const where = idOrLicencePlate.length > 7 ? { id: idOrLicencePlate } : { licencePlate: idOrLicencePlate };

const product = await prisma.privateCloudProject.findUnique({
where,
Expand Down
105 changes: 105 additions & 0 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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) => {};

0 comments on commit cdc1c42

Please sign in to comment.