generated from brocoders/nestjs-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2.5.10 square platform marketplace updates
- Loading branch information
1 parent
79cd3de
commit ed55fb8
Showing
10 changed files
with
158 additions
and
30 deletions.
There are no files selected for viewing
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
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
39 changes: 39 additions & 0 deletions
39
src/database/migrations/1700008096601-EncryptSquareTokens.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,39 @@ | ||
import { Logger } from '@nestjs/common'; | ||
import { MerchantEntity } from 'src/moa-square/entities/merchant.entity.js'; | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
import { EncryptionTransformer } from 'typeorm-encrypted'; | ||
import { MoaSquareEncryptionTransformerConfig } from '../../moa-square/moa-square.config.js'; | ||
|
||
export class EncryptSquareTokens1700008096601 implements MigrationInterface { | ||
private readonly logger = new Logger(EncryptSquareTokens1700008096601.name); | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
this.logger.verbose(this.up.name); | ||
|
||
const merchants: Array<MerchantEntity> = await queryRunner.query( | ||
'SELECT id, squareAccessToken, squareRefreshToken FROM merchant', | ||
); | ||
const transformer = new EncryptionTransformer( | ||
MoaSquareEncryptionTransformerConfig, | ||
); | ||
|
||
for (const merchant of merchants) { | ||
const encryptedSquareAccessToken = transformer.to( | ||
merchant.squareAccessToken, | ||
); | ||
await queryRunner.query( | ||
`UPDATE merchant SET squareAccessToken = '${encryptedSquareAccessToken}' WHERE id = '${merchant.id}'`, | ||
); | ||
|
||
const encryptedSquareRefreshToken = transformer.to( | ||
merchant.squareRefreshToken, | ||
); | ||
await queryRunner.query( | ||
`UPDATE merchant SET squareRefreshToken = '${encryptedSquareRefreshToken}' WHERE id = '${merchant.id}'`, | ||
); | ||
} | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
public async down(_queryRunner: QueryRunner): Promise<void> {} | ||
} |
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
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