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
void main(List<String> arguments, dynamic message) { | |
print('GITHUB: Arguments from your isolate: $arguments'); | |
print('GITHUB: Message from your isolate: $message'); | |
// V3 | |
} |
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
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
final parser = RootRouterParser(); | |
final delegate = RootRouterDelegate(); | |
const indexes = ['First', 'Second', 'Third', 'Fourth', 'Fifth']; |
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
// ... | |
async makeRemittance(fromId: number, toId: number, sum: number, withError = false, transaction = true): Promise<RemittanceResultDto> { | |
const fromUser = await this.userRepository.findOne(fromId, { transaction }); | |
const toUser = await this.userRepository.findOne(toId, { transaction }); | |
if (fromUser === undefined) { | |
throw new Error(NOT_FOUND_USER_WITH_ID(fromId)); | |
} | |
if (toUser === undefined) { | |
throw new Error(NOT_FOUND_USER_WITH_ID(toId)); |
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
// ... | |
@Post('remittance-with-typeorm-transaction') | |
@ApiResponse({ | |
type: RemittanceResultDto, | |
}) | |
async makeRemittanceWithTypeOrmTransaction(@Body() remittanceDto: RemittanceDto) { | |
return await this.connection.transaction(transactionManager => { | |
return this.appService.makeRemittanceWithTypeOrmV1(transactionManager, remittanceDto.userIdFrom, remittanceDto.userIdTo, remittanceDto.sum, remittanceDto.withError); | |
}); | |
} |
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
import { getConnection } from 'typeorm'; | |
// ... | |
@Post('remittance-with-typeorm-transaction') | |
@ApiResponse({ | |
type: RemittanceResultDto, | |
}) | |
async makeRemittanceWithTypeOrmTransaction(@Body() remittanceDto: RemittanceDto) { | |
return await getConnection().transaction(transactionManager => { | |
return this.appService.makeRemittanceWithTypeOrmV1(transactionManager, remittanceDto.userIdFrom, remittanceDto.userIdTo, remittanceDto.sum, remittanceDto.withError); | |
}); |
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
@Controller() | |
@ApiTags('app') | |
export class AppController { | |
constructor( | |
private readonly appService: AppService, | |
private readonly connection: Connection, // <-- it is - what we need | |
) { | |
} | |
// ... | |
} |
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
async makeRemittanceWithTypeOrmV1(transactionEntityManager: EntityManager, fromId: number, toId: number, sum: number, withError = false) { | |
const fromUser = await transactionEntityManager.findOne(User, fromId); // <-- we need to use only provided transactionEntityManager, for make all requests in transaction | |
const toUser = await transactionEntityManager.findOne(User, toId); // <-- and there | |
if (fromUser === undefined) { | |
throw new Error(NOT_FOUND_USER_WITH_ID(fromId)); | |
} | |
if (toUser === undefined) { | |
throw new Error(NOT_FOUND_USER_WITH_ID(toId)); | |
} | |
if (fromUser.defaultPurseId === null) { |
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
@Injectable() | |
export class AppServiceV2 { | |
constructor( | |
@InjectRepository(Purse) | |
private readonly purseRepository: Repository<Purse>, | |
) { | |
} | |
async savePurse(purse: Purse) { | |
await this.purseRepository.save(purse); | |
} |
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
// ... | |
@Transaction() // <-- this | |
async makeRemittanceWithTypeOrmV2(fromId: number, toId: number, sum: number, withError: boolean, @TransactionManager() transactionEntityManager: EntityManager = null /* <-- and this */) { | |
const fromUser = await transactionEntityManager.findOne(User, fromId); | |
const toUser = await transactionEntityManager.findOne(User, toId); | |
if (fromUser === undefined) { | |
throw new Error(NOT_FOUND_USER_WITH_ID(fromId)); | |
} | |
if (toUser === undefined) { | |
throw new Error(NOT_FOUND_USER_WITH_ID(toId)); |
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
@Controller() | |
@ApiTags('app') | |
export class AppController { | |
constructor( | |
private readonly appService: AppService, | |
private readonly connection: Connection, // <-- use this | |
) { | |
} | |
// ... | |
} |
NewerOlder