1
1
import { Injectable } from '@nestjs/common' ;
2
2
import { WebhookEvent } from '../../webhooks.decorators' ;
3
3
import {
4
+ TaxFormStatus ,
4
5
TaxFormStatusUpdatedEvent ,
5
6
TaxFormStatusUpdatedEventData ,
6
7
TrolleyWebhookEvent ,
@@ -23,28 +24,33 @@ export class TaxFormHandler {
23
24
recipient : trolley_recipient ,
24
25
taxFormData : TaxFormStatusUpdatedEventData ,
25
26
) {
27
+ const taxFormStatus =
28
+ taxFormData . status === TaxFormStatus . Reviewed
29
+ ? tax_form_status . ACTIVE
30
+ : tax_form_status . INACTIVE ;
31
+
26
32
const existingFormAssociation =
27
33
await this . prisma . user_tax_form_associations . findFirst ( {
28
34
where : {
29
35
user_id : recipient . user_id ,
30
36
tax_form_id : taxFormId ,
31
- tax_form_status : { notIn : [ tax_form_status . voided ] } ,
37
+ tax_form_status : tax_form_status . ACTIVE ,
32
38
} ,
33
39
} ) ;
34
40
35
41
if ( ! existingFormAssociation ) {
36
42
return this . prisma . user_tax_form_associations . create ( {
37
43
data : {
38
44
user_id : recipient . user_id ,
39
- tax_form_status : taxFormData . status ,
45
+ tax_form_status : taxFormStatus ,
40
46
date_filed : taxFormData . signedAt ,
41
47
tax_form_id : taxFormId ,
42
48
} ,
43
49
} ) ;
44
50
}
45
51
46
52
// voided forms associations are removed from DB
47
- if ( taxFormData . status === tax_form_status . voided ) {
53
+ if ( taxFormData . status === TaxFormStatus . Voided ) {
48
54
return this . prisma . user_tax_form_associations . delete ( {
49
55
where : {
50
56
id : existingFormAssociation . id ,
@@ -55,7 +61,7 @@ export class TaxFormHandler {
55
61
return this . prisma . user_tax_form_associations . update ( {
56
62
where : { id : existingFormAssociation ?. id } ,
57
63
data : {
58
- tax_form_status : taxFormData . status ,
64
+ tax_form_status : taxFormStatus ,
59
65
date_filed : taxFormData . signedAt ,
60
66
} ,
61
67
} ) ;
0 commit comments