From fd8f9baa0bb90d5d30d077491b038f8e5ec8b17a Mon Sep 17 00:00:00 2001 From: "j.dev" Date: Fri, 7 Jun 2024 10:57:39 -0700 Subject: [PATCH] fix(3052): add missing private cloud create requests --- .../[idOrLicencePlate]/nats-message/route.ts | 2 +- app/package-lock.json | 105 ++++++++++++++++++ ...40607161718-add_missing_create_requests.js | 66 +++++++++++ 3 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 data-migrations/migrations/20240607161718-add_missing_create_requests.js diff --git a/app/app/api/v1/private-cloud/products/[idOrLicencePlate]/nats-message/route.ts b/app/app/api/v1/private-cloud/products/[idOrLicencePlate]/nats-message/route.ts index 0dbfa852a..7940b4746 100644 --- a/app/app/api/v1/private-cloud/products/[idOrLicencePlate]/nats-message/route.ts +++ b/app/app/api/v1/private-cloud/products/[idOrLicencePlate]/nats-message/route.ts @@ -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, diff --git a/app/package-lock.json b/app/package-lock.json index ba4e0e6e5..b293a784e 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -15470,6 +15470,111 @@ "peerDependencies": { "zod": "^3.18.0" } + }, + "node_modules/react-email/node_modules/@next/swc-darwin-arm64": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.3.tgz", + "integrity": "sha512-3pEYo/RaGqPP0YzwnlmPN2puaF2WMLM3apt5jLW2fFdXD9+pqcoTzRk+iZsf8ta7+quAe4Q6Ms0nR0SFGFdS1A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/react-email/node_modules/@next/swc-darwin-x64": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.3.tgz", + "integrity": "sha512-6adp7waE6P1TYFSXpY366xwsOnEXM+y1kgRpjSRVI2CBDOcbRjsJ67Z6EgKIqWIue52d2q/Mx8g9MszARj8IEA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/react-email/node_modules/@next/swc-linux-arm64-gnu": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.3.tgz", + "integrity": "sha512-cuzCE/1G0ZSnTAHJPUT1rPgQx1w5tzSX7POXSLaS7w2nIUJUD+e25QoXD/hMfxbsT9rslEXugWypJMILBj/QsA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/react-email/node_modules/@next/swc-linux-arm64-musl": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.3.tgz", + "integrity": "sha512-0D4/oMM2Y9Ta3nGuCcQN8jjJjmDPYpHX9OJzqk42NZGJocU2MqhBq5tWkJrUQOQY9N+In9xOdymzapM09GeiZw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/react-email/node_modules/@next/swc-win32-arm64-msvc": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.3.tgz", + "integrity": "sha512-AEHIw/dhAMLNFJFJIJIyOFDzrzI5bAjI9J26gbO5xhAKHYTZ9Or04BesFPXiAYXDNdrwTP2dQceYA4dL1geu8A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/react-email/node_modules/@next/swc-win32-ia32-msvc": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.3.tgz", + "integrity": "sha512-vga40n1q6aYb0CLrM+eEmisfKCR45ixQYXuBXxOOmmoV8sYST9k7E3US32FsY+CkkF7NtzdcebiFT4CHuMSyZw==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/react-email/node_modules/@next/swc-win32-x64-msvc": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.3.tgz", + "integrity": "sha512-Q1/zm43RWynxrO7lW4ehciQVj+5ePBhOK+/K2P7pLFX3JaJ/IZVC69SHidrmZSOkqz7ECIOhhy7XhAFG4JYyHA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } } } } diff --git a/data-migrations/migrations/20240607161718-add_missing_create_requests.js b/data-migrations/migrations/20240607161718-add_missing_create_requests.js new file mode 100644 index 000000000..f23a78b69 --- /dev/null +++ b/data-migrations/migrations/20240607161718-add_missing_create_requests.js @@ -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) => {};