File tree 1 file changed +6
-16
lines changed
apps/nestjs-backend/src/features/calculation
1 file changed +6
-16
lines changed Original file line number Diff line number Diff line change @@ -246,26 +246,16 @@ export class BatchService {
246
246
} ) ;
247
247
const dropTempTableSql = this . knex . schema . dropTable ( tempTableName ) . toQuery ( ) ;
248
248
249
- const prisma = this . prismaService . txClient ( ) ;
250
-
251
- const batchOperators = async ( ) => {
249
+ await this . prismaService . $tx ( async ( tx ) => {
252
250
// temp table should in one transaction
253
- await prisma . $executeRawUnsafe ( createTempTableSql ) ;
251
+ await tx . $executeRawUnsafe ( createTempTableSql ) ;
254
252
// 2.initialize temporary table data
255
- await prisma . $executeRawUnsafe ( insertTempTableSql ) ;
253
+ await tx . $executeRawUnsafe ( insertTempTableSql ) ;
256
254
// 3.update data
257
- await wrapWithValidationErrorHandler ( ( ) => prisma . $executeRawUnsafe ( updateRecordSql ) ) ;
255
+ await wrapWithValidationErrorHandler ( ( ) => tx . $executeRawUnsafe ( updateRecordSql ) ) ;
258
256
// 4.delete temporary table
259
- await prisma . $executeRawUnsafe ( dropTempTableSql ) ;
260
- } ;
261
-
262
- if ( this . cls . get ( 'tx.id' ) ) {
263
- await batchOperators ( ) ;
264
- } else {
265
- await this . prismaService . $transaction ( async ( ) => {
266
- await batchOperators ( ) ;
267
- } ) ;
268
- }
257
+ await tx . $executeRawUnsafe ( dropTempTableSql ) ;
258
+ } ) ;
269
259
}
270
260
271
261
private async executeUpdateRecordsInner (
You can’t perform that action at this time.
0 commit comments