-
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, application relatio…
…nships (#2652) * fix(EMS-3524): no pdf - data migration - account relationships * fix(EMS-3524): fix typos * fix(EMS-3524): no pdf - data migration - application relationships * fix(EMS-3524): no pdf - data migraiton - createCuid function * fix(EMS-3524): no pdf - data migration export contract relationships * chore(EMS-3524): remove unused function * fix(EMS-3524): no pdf - data migration - loss payee relationships * chore(EMS-3524): no pdf - data migration - clean up * chore(schema): update creditPeriodWithBuyer keystone varchar * fix(EMS-3524): documentation improvements * fix(EMS-3524): fix typos * fix(EMS-3524): address todo comments * fix(EMS-3524): no pdf - data migration - missing fields/relationships * fix(EMS-3524): update README.md * fix(EMS-3524): no pdf - data migration - default currency codes * chore(ui): application mapping try/catch handlers * fix(EMS-3524): fix typos * fix(EMS-3524): fix loss payee relationship issues
- Loading branch information
Showing
67 changed files
with
1,359 additions
and
432 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ DATABASE_URL= | |
|
||
# DATABASE - data migration | ||
DATABASE_USER= | ||
CUID_FINGERPRINT= | ||
|
||
# API | ||
API_URL= | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
17 changes: 17 additions & 0 deletions
17
src/api/data-migration/version-1-to-version-2/create-cuid/index.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,17 @@ | ||
import dotenv from 'dotenv'; | ||
import { init } from '@paralleldrive/cuid2'; | ||
|
||
dotenv.config(); | ||
|
||
/** | ||
* createCuid | ||
* Create a CUID. | ||
* This is only used for data migration | ||
*/ | ||
const createCuid = init({ | ||
random: Math.random, | ||
length: 25, | ||
fingerprint: process.env.CUID_FINGERPRINT, | ||
}); | ||
|
||
export default createCuid; |
35 changes: 35 additions & 0 deletions
35
.../version-1-to-version-2/create-new-account-status-relationships/account-status-columns.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,35 @@ | ||
import { Connection } from 'mysql2/promise'; | ||
import executeSqlQuery from '../execute-sql-query'; | ||
import { AccountStatus } from '../../../types'; | ||
|
||
/** | ||
* updateAccountStatusColumns | ||
* Update "account status" columns for all existing accounts. | ||
* 1) Map over each account status entry. | ||
* 2) Update the Account table to have a status ID/relationship. | ||
* @param {Connection} connection: SQL database connection | ||
* @param {Array<AccountStatus>} statusRows: Account status entries | ||
* @param {Array<AccountStatus>} accountStatuses: Account statuses | ||
* @returns {Promise<Array<object>>} executeSqlQuery response | ||
*/ | ||
const updateAccountStatusColumns = async (connection: Connection, statusRows: Array<AccountStatus>, accountStatuses: Array<AccountStatus>) => { | ||
console.info('✅ Updating account status columns for all accounts (account table)'); | ||
|
||
const accountPromises = statusRows.map(async (accountStatus: AccountStatus, index: number) => { | ||
const status = accountStatuses[index]; | ||
|
||
const loggingMessage = `Updating status column in account table for account status ${accountStatus.id}`; | ||
|
||
const query = ` | ||
UPDATE Account SET status='${status.id}' WHERE id='${accountStatus.id}' | ||
`; | ||
|
||
const updated = await executeSqlQuery({ connection, query, loggingMessage }); | ||
|
||
return updated; | ||
}); | ||
|
||
return Promise.all(accountPromises); | ||
}; | ||
|
||
export default updateAccountStatusColumns; |
33 changes: 33 additions & 0 deletions
33
...ion/version-1-to-version-2/create-new-account-status-relationships/account-status-rows.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,33 @@ | ||
import { format } from 'date-fns'; | ||
import { Connection } from 'mysql2/promise'; | ||
import executeSqlQuery from '../execute-sql-query'; | ||
import { AccountMvp } from '../../../types'; | ||
|
||
/** | ||
* createAccountStatusRows | ||
* Create new "account status" rows for all existing accounts. | ||
* 1) Map over each account entry. | ||
* 2) Insert status data into the AccountStatus table - using isVerified, isBlocked and updatedAt from the original accounts data. | ||
* @param {Connection} connection: SQL database connection | ||
* @param {Array<AccountMvp>} accounts: MVP accounts | ||
* @returns {Promise<Array<object>>} executeSqlQuery responses | ||
*/ | ||
const createAccountStatusRows = async (connection: Connection, accounts: Array<AccountMvp>) => { | ||
console.info('✅ Creating account status rows for all accounts (account status table)'); | ||
|
||
const accountStatusData = accounts.map( | ||
(account: AccountMvp) => `('${account.id}', ${account.isBlocked}, ${account.isVerified}, '${format(account.updatedAt, 'yyyy-MM-dd HH:mm')}')`, | ||
); | ||
|
||
const loggingMessage = 'Creating new status rows for all accounts'; | ||
|
||
const query = ` | ||
INSERT INTO AccountStatus (id, isBlocked, isVerified, updatedAt) VALUES ${accountStatusData}; | ||
`; | ||
|
||
await executeSqlQuery({ connection, query, loggingMessage }); | ||
|
||
return accounts; | ||
}; | ||
|
||
export default createAccountStatusRows; |
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
42 changes: 0 additions & 42 deletions
42
...-1-to-version-2/create-new-application-relationships/company-different-trading-address.ts
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
...ersion-2/create-new-application-relationships/create-company-different-trading-address.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,46 @@ | ||
import { Connection } from 'mysql2/promise'; | ||
import createCuid from '../create-cuid'; | ||
import executeSqlQuery from '../execute-sql-query'; | ||
import { Application } from '../../../types'; | ||
|
||
/** | ||
* createCompanyDifferentTradingAddress | ||
* Create new "company different trading address" entries with company relationships. | ||
* 1) Map over each application. | ||
* 2) Generate "different trading address" values. | ||
* 3) Insert the values into the CompanyDifferentTradingAddress table. | ||
* @param {Connection} connection: SQL database connection | ||
* @param {Array<Application>} applications: Applications | ||
* @returns {Promise<Array<object>>} executeSqlQuery responses | ||
*/ | ||
const createCompanyDifferentTradingAddress = async (connection: Connection, applications: Array<Application>) => { | ||
const loggingMessage = 'Creating companyDifferentTradingAddresses entries with company relationships'; | ||
|
||
console.info(`✅ ${loggingMessage}`); | ||
|
||
try { | ||
const promises = applications.map(async (application: Application) => { | ||
const theValues = `('${createCuid()}', '${application.company}')`; | ||
|
||
const query = ` | ||
INSERT INTO CompanyDifferentTradingAddress (id, company) VALUES ${theValues}; | ||
`; | ||
|
||
const updated = await executeSqlQuery({ | ||
connection, | ||
query, | ||
loggingMessage: `Creating CompanyDifferentTradingAddress entry for application ${application.id}`, | ||
}); | ||
|
||
return updated; | ||
}); | ||
|
||
return Promise.all(promises); | ||
} catch (err) { | ||
console.error(`🚨 error ${loggingMessage} %O`, err); | ||
|
||
throw new Error(`🚨 error ${loggingMessage} ${err}`); | ||
} | ||
}; | ||
|
||
export default createCompanyDifferentTradingAddress; |
39 changes: 29 additions & 10 deletions
39
...reate-new-application-relationships/export-contract-agent/create-agent-service-charges.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,27 +1,46 @@ | ||
import { Context } from '.keystone/types'; // eslint-disable-line | ||
import { Connection } from 'mysql2/promise'; | ||
import createCuid from '../../create-cuid'; | ||
import executeSqlQuery from '../../execute-sql-query'; | ||
import { Application } from '../../../../types'; | ||
|
||
/** | ||
* createAgentServiceCharges | ||
* Create new "export contract agent service charge" entires | ||
* @param {Context} context: KeystoneJS context API | ||
* @param {Array<object>} agentServiceIdsConnectArray: Array of agent service IDs "connect" objects | ||
* @returns {Promise<Array<ApplicationExportContractAgentServiceCharge>>} Export contract agent service charge entries | ||
* Create new "export contract agent service charges" entries | ||
* 1) Map over each application. | ||
* 2) Generate "agent service charge" values (CUID) | ||
* 3) Insert the values into the ExportContractAgentServiceCharge table. | ||
* @param {Connection} connection: SQL database connection | ||
* @param {Array<Application>} applications: Applications | ||
* @returns {Promise<Array<object>>} executeSqlQuery responses | ||
*/ | ||
const createAgentServiceCharges = async (context: Context, agentServiceIdsConnectArray: Array<object>) => { | ||
const loggingMessage = 'Creating exportContractAgentServiceCharges with agent service relationships'; | ||
const createAgentServiceCharges = async (connection: Connection, applications: Array<Application>) => { | ||
const loggingMessage = 'Creating exportContract agent service charges'; | ||
|
||
console.info(`✅ ${loggingMessage}`); | ||
|
||
try { | ||
const created = await context.db.ExportContractAgentServiceCharge.createMany({ | ||
data: agentServiceIdsConnectArray, | ||
const servicesPromises = applications.map(async (application: Application) => { | ||
const theValues = `('${createCuid()}')`; | ||
|
||
const query = ` | ||
INSERT INTO ExportContractAgentServiceCharge (id) VALUES ${theValues}; | ||
`; | ||
|
||
const updated = await executeSqlQuery({ | ||
connection, | ||
query, | ||
loggingMessage: `Creating ExportContractAgentServiceCharge entry for application ${application.id}`, | ||
}); | ||
|
||
return updated; | ||
}); | ||
|
||
return created; | ||
return Promise.all(servicesPromises); | ||
} catch (err) { | ||
console.error(`🚨 error ${loggingMessage} %O`, err); | ||
|
||
throw new Error(`🚨 error ${loggingMessage} ${err}`); | ||
} | ||
}; | ||
|
||
export default createAgentServiceCharges; |
Oops, something went wrong.