Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

799 - Update model to have count of transactions and reports replaced with a boolean #1835

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe('ContactListComponent', () => {
next: 'https://next',
previous: 'https://previous',
results: [
Contact.fromJSON({ id: 1, transaction_count: 0, report_count: 0 }),
Contact.fromJSON({ id: 2, transaction_count: 5, report_count: 0 }),
Contact.fromJSON({ id: 1, has_transaction_or_report: false }),
Contact.fromJSON({ id: 2, has_transaction_or_report: true }),
],
};

Expand Down Expand Up @@ -102,22 +102,12 @@ describe('ContactListComponent', () => {

it('#canDeleteItem returns boolean status', () => {
const item: Contact = Contact.fromJSON({
transaction_count: 0,
report_count: 0,
has_transaction_or_report: false,
});
let status: boolean = component.canDeleteItem(item);
expect(status).toBeTrue();

item.transaction_count = 2;
status = component.canDeleteItem(item);
expect(status).toBeFalse();

item.transaction_count = undefined;
status = component.canDeleteItem(item);
expect(status).toBeFalse();

item.transaction_count = 0;
item.report_count = 1;
item.has_transaction_or_report = true;
status = component.canDeleteItem(item);
expect(status).toBeFalse();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class ContactListComponent extends TableListBaseComponent<Contact> {
}

public canDeleteItem(item: Contact): boolean {
return item.transaction_count === 0 && item.report_count === 0;
return !item.has_transaction_or_report;
}

public onRestoreClick() {
Expand Down
23 changes: 11 additions & 12 deletions front-end/src/app/shared/models/contact.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,12 @@ export class Contact extends BaseModel {
created: string | undefined;
updated: string | undefined;
deleted: string | undefined;
transaction_count: number | undefined;
report_count: number | undefined;
has_transaction_or_report = false;

// prettier-ignore
static fromJSON(json: any): Contact { // eslint-disable-line @typescript-eslint/no-explicit-any
return plainToInstance(Contact, json);
}
return plainToInstance(Contact, json);
}

getNameString(): string {
return this.name ? this.name : `${this.last_name}, ${this.first_name} ${this.middle_name ?? ''}`;
Expand Down Expand Up @@ -316,8 +315,8 @@ export class CandidateLookupResponse {

// prettier-ignore
static fromJSON(json: any): CandidateLookupResponse { // eslint-disable-line @typescript-eslint/no-explicit-any
return plainToClass(CandidateLookupResponse, json);
}
return plainToClass(CandidateLookupResponse, json);
}

toSelectItemGroups(includeFecfileResults: boolean): SelectItemGroup[] {
const fecApiSelectItems =
Expand Down Expand Up @@ -383,8 +382,8 @@ export class CommitteeLookupResponse {

// prettier-ignore
static fromJSON(json: any): CommitteeLookupResponse { // eslint-disable-line @typescript-eslint/no-explicit-any
return plainToClass(CommitteeLookupResponse, json);
}
return plainToClass(CommitteeLookupResponse, json);
}

toSelectItemGroups(includeFecfileResults: boolean): SelectItemGroup[] {
const fecApiSelectItems =
Expand Down Expand Up @@ -431,8 +430,8 @@ export class IndividualLookupResponse {

// prettier-ignore
static fromJSON(json: any): IndividualLookupResponse { // eslint-disable-line @typescript-eslint/no-explicit-any
return plainToClass(IndividualLookupResponse, json);
}
return plainToClass(IndividualLookupResponse, json);
}

toSelectItemGroups(): SelectItemGroup[] {
const fecfileSelectItems =
Expand Down Expand Up @@ -467,8 +466,8 @@ export class OrganizationLookupResponse {

// prettier-ignore
static fromJSON(json: any): OrganizationLookupResponse { // eslint-disable-line @typescript-eslint/no-explicit-any
return plainToClass(OrganizationLookupResponse, json);
}
return plainToClass(OrganizationLookupResponse, json);
}

toSelectItemGroups(): SelectItemGroup[] {
const fecfileSelectItems =
Expand Down
2 changes: 1 addition & 1 deletion front-end/src/app/shared/utils/unit-test.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const testContact = Contact.fromJSON({
created: '8/27/2023',
updated: null,
deleted: null,
transaction_count: 3,
has_transaction_or_report: true,
});

export function getTestIndividualReceipt(): SchATransaction {
Expand Down