-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(EMS-3524): no pdf - data migration - account, buyer relationships (…
…#2650) * fix(EMS-3524): no pdf - data migration - account status relationships * fix(EMS-3524): no pdf - data migration - buyer relationships * fix(EMS-3524): update README.md * fix(EMS-3524): minor code improvements
- Loading branch information
Showing
12 changed files
with
188 additions
and
165 deletions.
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
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
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
20 changes: 20 additions & 0 deletions
20
src/api/data-migration/version-1-to-version-2/get-all-buyer-contacts.ts
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,20 @@ | ||
import { Connection } from 'mysql2/promise'; | ||
import executeSqlQuery from './execute-sql-query'; | ||
|
||
/** | ||
* getAllBuyerContacts | ||
* Get all buyer contacts in the "BuyerContact" table. | ||
* @param {Connection} connection: SQL database connection | ||
* @returns {Promise<Array<object>>} executeSqlQuery response | ||
*/ | ||
const getAllBuyerContacts = async (connection: Connection) => { | ||
const loggingMessage = 'Getting all buyer contacts'; | ||
|
||
const query = 'SELECT * FROM BuyerContact'; | ||
|
||
const [contacts] = await executeSqlQuery({ connection, query, loggingMessage }); | ||
|
||
return contacts; | ||
}; | ||
|
||
export default getAllBuyerContacts; |
20 changes: 20 additions & 0 deletions
20
src/api/data-migration/version-1-to-version-2/get-all-buyer-relationships.ts
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,20 @@ | ||
import { Connection } from 'mysql2/promise'; | ||
import executeSqlQuery from './execute-sql-query'; | ||
|
||
/** | ||
* getAllBuyerRelationships | ||
* Get all buyer relationships in the "BuyerRelationship" table. | ||
* @param {Connection} connection: SQL database connection | ||
* @returns {Promise<Array<object>>} executeSqlQuery response | ||
*/ | ||
const getAllBuyerRelationships = async (connection: Connection) => { | ||
const loggingMessage = 'Getting all buyer relationships'; | ||
|
||
const query = 'SELECT * FROM BuyerRelationship'; | ||
|
||
const [relationships] = await executeSqlQuery({ connection, query, loggingMessage }); | ||
|
||
return relationships; | ||
}; | ||
|
||
export default getAllBuyerRelationships; |
20 changes: 20 additions & 0 deletions
20
src/api/data-migration/version-1-to-version-2/get-all-buyer-trading-histories.ts
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,20 @@ | ||
import { Connection } from 'mysql2/promise'; | ||
import executeSqlQuery from './execute-sql-query'; | ||
|
||
/** | ||
* getAllBuyerTradingHistories | ||
* Get all buyer trading history in the "BuyerTradingHistory" table. | ||
* @param {Connection} connection: SQL database connection | ||
* @returns {Promise<Array<object>>} executeSqlQuery response | ||
*/ | ||
const getAllBuyerTradingHistories = async (connection: Connection) => { | ||
const loggingMessage = 'Getting all buyer trading histories'; | ||
|
||
const query = 'SELECT * FROM BuyerTradingHistory'; | ||
|
||
const [tradingHistories] = await executeSqlQuery({ connection, query, loggingMessage }); | ||
|
||
return tradingHistories; | ||
}; | ||
|
||
export default getAllBuyerTradingHistories; |
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
51 changes: 21 additions & 30 deletions
51
...pi/data-migration/version-1-to-version-2/update-applications/move-buyer-contact-fields.ts
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 |
---|---|---|
@@ -1,42 +1,33 @@ | ||
import { Context } from '.keystone/types'; // eslint-disable-line | ||
import crypto from 'crypto'; | ||
import { Connection } from 'mysql2/promise'; | ||
import executeSqlQuery from '../execute-sql-query'; | ||
import { ApplicationBuyerMvp } from '../../../types'; | ||
|
||
/** | ||
* moveBuyerContactFields | ||
* Move MVP "buyers" fields into the new "No PDF" data model/structure. | ||
* NOTE: The buyer data we receive is raw database data. | ||
* In the database, boolean fields are TINYINT/integer values. | ||
* The KeystoneJS context/GraphQL API expects these fields to be booleans. | ||
* Therefore, since the TINYINT values will be 0 or 1, | ||
* we can safely transform any TINYINT fields to have a boolean value. | ||
* KeystoneJS will then automatically handle saving in the database as a TINYINT | ||
* @param {Array<ApplicationBuyerMvp>} context: KeystoneJS context API | ||
* @param {Context} context: KeystoneJS context API | ||
* @returns {Promise<Array<ApplicationBuyer>>} Updated buyers | ||
* @param {Array<ApplicationBuyerMvp>} buyers: Buyers | ||
* @param {Connection} connection: SQL database connection | ||
* @returns {Promise<Boolean>} | ||
*/ | ||
const moveBuyerContactFields = async (buyers: Array<ApplicationBuyerMvp>, context: Context) => { | ||
const mappedBuyerContactData = buyers.map((buyer: ApplicationBuyerMvp) => { | ||
const mapped = { | ||
application: { | ||
connect: { | ||
id: buyer.application, | ||
}, | ||
}, | ||
canContactBuyer: Boolean(buyer.canContactBuyer), | ||
contactEmail: buyer.contactEmail, | ||
contactFirstName: buyer.contactFirstName, | ||
contactLastName: buyer.contactLastName, | ||
contactPosition: buyer.contactPosition, | ||
}; | ||
|
||
return mapped; | ||
}); | ||
const moveBuyerContactFields = async (buyers: Array<ApplicationBuyerMvp>, connection: Connection): Promise<Array<object>> => { | ||
console.info('✅ Moving buyer contact relationships for all buyers'); | ||
|
||
const buyerContactValues = buyers.map((buyer: ApplicationBuyerMvp) => { | ||
const { application, canContactBuyer, contactEmail, contactFirstName, contactLastName, contactPosition } = buyer; | ||
|
||
const created = await context.db.BuyerContact.createMany({ | ||
data: mappedBuyerContactData, | ||
return `('${crypto.randomUUID()}', '${application}', ${canContactBuyer}, '${contactEmail}', '${contactFirstName}', '${contactLastName}', '${contactPosition}')`; | ||
}); | ||
|
||
return created; | ||
const loggingMessage = 'Creating new buyer contact relationships for all buyers'; | ||
|
||
const query = ` | ||
INSERT INTO BuyerContact (id, application, canContactBuyer, contactEmail, contactFirstName, contactLastName, contactPosition) VALUES ${buyerContactValues}; | ||
`; | ||
|
||
const updated = executeSqlQuery({ connection, query, loggingMessage }); | ||
|
||
return updated; | ||
}; | ||
|
||
export default moveBuyerContactFields; |
45 changes: 20 additions & 25 deletions
45
...ta-migration/version-1-to-version-2/update-applications/move-buyer-relationship-fields.ts
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 |
---|---|---|
@@ -1,38 +1,33 @@ | ||
import { Context } from '.keystone/types'; // eslint-disable-line | ||
import crypto from 'crypto'; | ||
import { Connection } from 'mysql2/promise'; | ||
import executeSqlQuery from '../execute-sql-query'; | ||
import { ApplicationBuyerMvp } from '../../../types'; | ||
|
||
/** | ||
* moveBuyerRelationshipFields | ||
* Move MVP "buyer relationships" fields into the new "No PDF" data model/structure. | ||
* NOTE: The buyer data we receive is raw database data. | ||
* In the database, boolean fields are TINYINT/integer values. | ||
* The KeystoneJS context/GraphQL API expects these fields to be booleans. | ||
* Therefore, since the TINYINT values will be 0 or 1, | ||
* we can safely transform any TINYINT fields to have a boolean value. | ||
* KeystoneJS will then automatically handle saving in the database as a TINYINT | ||
* @param {Array<ApplicationBuyerMvp>} context: KeystoneJS context API | ||
* @param {Context} context: KeystoneJS context API | ||
* @param {Array<ApplicationBuyerMvp>} buyers: Buyers | ||
* @param {Connection} connection: SQL database connection | ||
* @returns {Promise<Array<ApplicationBuyer>>} Updated buyers | ||
*/ | ||
const moveBuyerRelationshipFields = async (buyers: Array<ApplicationBuyerMvp>, context: Context) => { | ||
const mappedBuyerRelationshipData = buyers.map((buyer: ApplicationBuyerMvp) => { | ||
const mapped = { | ||
application: { | ||
connect: { | ||
id: buyer.application, | ||
}, | ||
}, | ||
exporterIsConnectedWithBuyer: Boolean(buyer.exporterIsConnectedWithBuyer), | ||
}; | ||
|
||
return mapped; | ||
}); | ||
const moveBuyerRelationshipFields = async (buyers: Array<ApplicationBuyerMvp>, connection: Connection): Promise<Array<object>> => { | ||
console.info('✅ Moving buyer relationship for all buyers'); | ||
|
||
const buyerRelationshipValues = buyers.map((buyer: ApplicationBuyerMvp) => { | ||
const { application, exporterIsConnectedWithBuyer } = buyer; | ||
|
||
const created = await context.db.BuyerRelationship.createMany({ | ||
data: mappedBuyerRelationshipData, | ||
return `('${crypto.randomUUID()}', '${application}', ${exporterIsConnectedWithBuyer})`; | ||
}); | ||
|
||
return created; | ||
const loggingMessage = 'Creating new buyer relationship for all buyers'; | ||
|
||
const query = ` | ||
INSERT INTO BuyerRelationship (id, application, exporterIsConnectedWithBuyer) VALUES ${buyerRelationshipValues}; | ||
`; | ||
|
||
const updated = await executeSqlQuery({ connection, query, loggingMessage }); | ||
|
||
return updated; | ||
}; | ||
|
||
export default moveBuyerRelationshipFields; |
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
Oops, something went wrong.