Skip to content

Commit a681cc7

Browse files
committed
PM-1143 - fix tax form status
1 parent 32c931a commit a681cc7

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

prisma/migrations/20250425134520_truncate_tax_forms/migration.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ALTER TABLE "user_tax_form_associations" DROP CONSTRAINT "user_tax_form_associat
88
DROP TABLE "user_tax_form_associations";
99
DROP TYPE "tax_form_status";
1010

11-
CREATE TYPE "tax_form_status" AS ENUM ('incomplete', 'submitted', 'reviewed', 'voided');
11+
CREATE TYPE "tax_form_status" AS ENUM ('ACTIVE', 'INACTIVE');
1212

1313
-- CreateTable
1414
CREATE TABLE "user_tax_form_associations" (

prisma/schema.prisma

+2-4
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,8 @@ enum reference_type {
249249
}
250250

251251
enum tax_form_status {
252-
incomplete
253-
submitted
254-
reviewed
255-
voided
252+
ACTIVE
253+
INACTIVE
256254
}
257255

258256
enum transaction_status {

src/api/repository/taxForm.repo.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from '@nestjs/common';
2-
import { TaxFormStatus } from 'src/dto/adminWinning.dto';
2+
import { tax_form_status } from '@prisma/client';
33
import { PrismaService } from 'src/shared/global/prisma.service';
44

55
@Injectable()
@@ -16,7 +16,7 @@ export class TaxFormRepository {
1616
const count = await this.prisma.user_tax_form_associations.count({
1717
where: {
1818
user_id: userId,
19-
tax_form_status: TaxFormStatus.Reviewed,
19+
tax_form_status: tax_form_status.ACTIVE,
2020
},
2121
});
2222

src/api/webhooks/trolley/handlers/tax-form.handler.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Injectable } from '@nestjs/common';
22
import { WebhookEvent } from '../../webhooks.decorators';
33
import {
4+
TaxFormStatus,
45
TaxFormStatusUpdatedEvent,
56
TaxFormStatusUpdatedEventData,
67
TrolleyWebhookEvent,
@@ -23,28 +24,33 @@ export class TaxFormHandler {
2324
recipient: trolley_recipient,
2425
taxFormData: TaxFormStatusUpdatedEventData,
2526
) {
27+
const taxFormStatus =
28+
taxFormData.status === TaxFormStatus.Reviewed
29+
? tax_form_status.ACTIVE
30+
: tax_form_status.INACTIVE;
31+
2632
const existingFormAssociation =
2733
await this.prisma.user_tax_form_associations.findFirst({
2834
where: {
2935
user_id: recipient.user_id,
3036
tax_form_id: taxFormId,
31-
tax_form_status: { notIn: [tax_form_status.voided] },
37+
tax_form_status: tax_form_status.ACTIVE,
3238
},
3339
});
3440

3541
if (!existingFormAssociation) {
3642
return this.prisma.user_tax_form_associations.create({
3743
data: {
3844
user_id: recipient.user_id,
39-
tax_form_status: taxFormData.status,
45+
tax_form_status: taxFormStatus,
4046
date_filed: taxFormData.signedAt,
4147
tax_form_id: taxFormId,
4248
},
4349
});
4450
}
4551

4652
// voided forms associations are removed from DB
47-
if (taxFormData.status === tax_form_status.voided) {
53+
if (taxFormData.status === TaxFormStatus.Voided) {
4854
return this.prisma.user_tax_form_associations.delete({
4955
where: {
5056
id: existingFormAssociation.id,
@@ -55,7 +61,7 @@ export class TaxFormHandler {
5561
return this.prisma.user_tax_form_associations.update({
5662
where: { id: existingFormAssociation?.id },
5763
data: {
58-
tax_form_status: taxFormData.status,
64+
tax_form_status: taxFormStatus,
5965
date_filed: taxFormData.signedAt,
6066
},
6167
});

src/api/webhooks/trolley/trolley.types.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ export enum TrolleyWebhookEvent {
66

77
export type TrolleyEventHandler = (eventPayload: any) => Promise<unknown>;
88

9-
export type TaxFormStatus = 'incomplete' | 'submitted' | 'reviewed' | 'voided';
9+
export enum TaxFormStatus {
10+
Incomplete = 'incomplete',
11+
Submitted = 'submitted',
12+
Reviewed = 'reviewed',
13+
Voided = 'voided',
14+
}
1015

1116
export interface TaxFormStatusUpdatedEventData {
1217
recipientId: string;

0 commit comments

Comments
 (0)