@@ -64,10 +64,10 @@ export class ApproversService {
6464 ) { }
6565
6666 /* Get the approver by id */
67- async getTransactionApproverById (
67+ getTransactionApproverById (
6868 id : number ,
6969 entityManager ?: EntityManager ,
70- ) : Promise < TransactionApprover | null > {
70+ ) : Promise < TransactionApprover > {
7171 if ( ! id ) return null ;
7272
7373 const find : FindOneOptions < TransactionApprover > = {
@@ -90,7 +90,7 @@ export class ApproversService {
9090 userId ?: number ,
9191 entityManager ?: EntityManager ,
9292 ) : Promise < TransactionApprover [ ] > {
93- if ( typeof transactionId !== 'number' || ( userId && typeof userId !== 'number' ) ) return [ ] ;
93+ if ( typeof transactionId !== 'number' || ( userId && typeof userId !== 'number' ) ) return null ;
9494
9595 return ( entityManager || this . repo ) . query (
9696 `
@@ -145,8 +145,8 @@ export class ApproversService {
145145 if (
146146 userKeysToSign . length === 0 &&
147147 transaction . creatorKey ?. userId !== user . id &&
148- ! ( transaction . observers && transaction . observers . some ( o => o . userId === user . id ) ) &&
149- ! ( transaction . signers && transaction . signers . some ( s => s . userKey ?. userId === user . id ) ) &&
148+ ! transaction . observers . some ( o => o . userId === user . id ) &&
149+ ! transaction . signers . some ( s => s . userKey ?. userId === user . id ) &&
150150 ! approvers . some ( a => a . userId === user . id )
151151 )
152152 throw new UnauthorizedException ( "You don't have permission to view this transaction" ) ;
@@ -206,7 +206,7 @@ export class ApproversService {
206206
207207 /* Soft deletes approvers' tree */
208208 async removeNode ( listId : number ) : Promise < void > {
209- if ( ! listId || typeof listId !== 'number' ) return ;
209+ if ( ! listId || typeof listId !== 'number' ) return null ;
210210
211211 await this . repo . query (
212212 `
@@ -291,7 +291,7 @@ export class ApproversService {
291291 if (
292292 dtoApprover . approvers &&
293293 dtoApprover . approvers . length > 0 &&
294- ( dtoApprover . threshold === undefined || isNaN ( dtoApprover . threshold ) )
294+ ( dtoApprover . threshold === null || isNaN ( dtoApprover . threshold ) )
295295 )
296296 throw new Error ( this . THRESHOLD_REQUIRED ) ;
297297
@@ -305,17 +305,16 @@ export class ApproversService {
305305 /* Check if the approver threshold is less or equal to the number of approvers */
306306 if (
307307 dtoApprover . approvers &&
308- dtoApprover . threshold !== undefined &&
309308 ( dtoApprover . threshold > dtoApprover . approvers . length || dtoApprover . threshold === 0 )
310309 )
311310 throw new Error ( this . THRESHOLD_LESS_OR_EQUAL_APPROVERS ( dtoApprover . approvers . length ) ) ;
312311
313312 const data : DeepPartial < TransactionApprover > = {
314313 transactionId :
315- dtoApprover . listId === undefined || isNaN ( dtoApprover . listId ) ? transactionId : undefined ,
314+ dtoApprover . listId === null || isNaN ( dtoApprover . listId ) ? transactionId : null ,
316315 listId : dtoApprover . listId ,
317316 threshold :
318- dtoApprover . threshold && dtoApprover . approvers ? dtoApprover . threshold : undefined ,
317+ dtoApprover . threshold && dtoApprover . approvers ? dtoApprover . threshold : null ,
319318 userId : dtoApprover . userId ,
320319 } ;
321320
@@ -346,7 +345,7 @@ export class ApproversService {
346345 const nestedApprover = { ...nestedDtoApprover , listId : approver . id } ;
347346
348347 if ( ! nestedDtoApprover . approvers || nestedDtoApprover . approvers . length === 0 ) {
349- nestedApprover . threshold = undefined ;
348+ nestedApprover . threshold = null ;
350349 }
351350
352351 await createApprover ( { ...nestedDtoApprover , listId : approver . id } ) ;
@@ -429,7 +428,7 @@ export class ApproversService {
429428 /* Soft delete the parent if there are no more children */
430429 if ( newParentApproversLength === 0 ) {
431430 await transactionalEntityManager . softRemove ( TransactionApprover , parent ) ;
432- } else if ( parent . threshold != null && newParentApproversLength < parent . threshold ) {
431+ } else if ( newParentApproversLength < parent . threshold ) {
433432 /* Update the parent threshold if the current one is more than the children */
434433 await transactionalEntityManager . update ( TransactionApprover , parent . id , {
435434 threshold : newParentApproversLength ,
@@ -468,10 +467,10 @@ export class ApproversService {
468467 /* Update the list id and sets the transaction id to null */
469468 await transactionalEntityManager . update ( TransactionApprover , approver . id , {
470469 listId : dto . listId ,
471- transactionId : undefined ,
470+ transactionId : null ,
472471 } ) ;
473472 approver . listId = dto . listId ;
474- approver . transactionId = undefined ;
473+ approver . transactionId = null ;
475474 updated = true ;
476475
477476 return approver ;
@@ -552,8 +551,7 @@ export class ApproversService {
552551
553552 const result = await this . removeNode ( approver . id ) ;
554553
555- const dtos = approver . transactionId !== undefined ? [ { entityId : approver . transactionId } ] : [ ]
556- await emitTransactionStatusUpdate ( this . notificationsPublisher , dtos ) ;
554+ await emitTransactionStatusUpdate ( this . notificationsPublisher , [ { entityId : approver . transactionId } ] ) ;
557555
558556 return result ;
559557 }
@@ -584,7 +582,7 @@ export class ApproversService {
584582 const signatureKey = user . keys . find ( key => key . id === dto . userKeyId ) ;
585583
586584 /* Gets the public key that the signature belongs to */
587- const publicKey = signatureKey ? PublicKey . fromString ( signatureKey . publicKey ) : undefined ;
585+ const publicKey = PublicKey . fromString ( signatureKey ? .publicKey ) ;
588586
589587 /* Get the transaction body */
590588 const transaction = await this . dataSource . manager . findOne ( Transaction , {
@@ -606,7 +604,6 @@ export class ApproversService {
606604
607605 /* Verify the signature matches the transaction */
608606 if (
609- ! publicKey ||
610607 ! verifyTransactionBodyWithoutNodeAccountIdSignature ( sdkTransaction , dto . signature , publicKey )
611608 )
612609 throw new BadRequestException ( ErrorCodes . SNMP ) ;
@@ -671,13 +668,13 @@ export class ApproversService {
671668 ) {
672669 const find : FindManyOptions < TransactionApprover > = {
673670 where : {
674- listId : typeof approver . listId === 'number' ? approver . listId : undefined ,
675- userId : typeof approver . userId === 'number' ? approver . userId : undefined ,
671+ listId : typeof approver . listId === 'number' ? approver . listId : null ,
672+ userId : typeof approver . userId === 'number' ? approver . userId : null ,
676673 threshold :
677674 typeof approver . threshold === 'number' && approver . threshold !== 0
678675 ? approver . threshold
679- : undefined ,
680- transactionId : typeof approver . listId === 'number' ? undefined : transactionId ,
676+ : null ,
677+ transactionId : typeof approver . listId === 'number' ? null : transactionId ,
681678 } ,
682679 } ;
683680
@@ -709,9 +706,9 @@ export class ApproversService {
709706 /* Validates the approver DTO */
710707 private validateApprover ( approver : CreateTransactionApproverDto ) : void {
711708 if (
712- ( approver . listId === null || ! approver . listId || isNaN ( approver . listId ) ) &&
713- ( approver . threshold === null || ! approver . threshold || isNaN ( approver . threshold ) || approver . threshold === 0 ) &&
714- ( approver . userId === null || ! approver . userId || isNaN ( approver . userId ) ) &&
709+ ( approver . listId === null || isNaN ( approver . listId ) ) &&
710+ ( approver . threshold === null || isNaN ( approver . threshold ) || approver . threshold === 0 ) &&
711+ ( approver . userId === null || isNaN ( approver . userId ) ) &&
715712 ( ! approver . approvers || approver . approvers . length === 0 )
716713 )
717714 throw new BadRequestException ( this . CANNOT_CREATE_EMPTY_APPROVER ) ;
0 commit comments