Skip to content
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
12 changes: 11 additions & 1 deletion src/types/api/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,17 @@ export interface ApiAgentContactPost {
addressPostcode?: string;
}

export type ApiAgentContactPatch = Partial<ApiAgentContactPost>;
export type ApiAgentContactPatch = Partial<
VoidableProps<
ApiAgentContactPost,
| "middleName"
| "email"
| "phone"
| "landline"
| "addressStreet"
| "addressPostcode"
>
>;

export interface ApiAgentOrganization {
id: number;
Expand Down
115 changes: 115 additions & 0 deletions src/types/api/patch-voidable.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { describe, expectTypeOf, it } from "vitest";
import type {
Address,
PreferredCommunicationType,
ApiActivityLogPatch,
ApiAgentContactPatch,
AgentRoleType,
ApiAppreciationPatch,
ApiPersonPatch,
ApiRepresentativePatch,
AppreciationStatusType,
VolunteerStateAppreciationType,
} from "../..";

type Clearable<T> = T | null | undefined;

describe("PATCH types allow null only on nullable columns", () => {
it("appreciation", () => {
expectTypeOf<ApiAppreciationPatch["dateDue"]>().toEqualTypeOf<
Clearable<Date>
>();
expectTypeOf<ApiAppreciationPatch["dateDelivery"]>().toEqualTypeOf<
Clearable<Date>
>();
expectTypeOf<ApiAppreciationPatch["opportunityId"]>().toEqualTypeOf<
number | undefined
>();
expectTypeOf<ApiAppreciationPatch["status"]>().toEqualTypeOf<
AppreciationStatusType | undefined
>();
expectTypeOf<ApiAppreciationPatch["title"]>().toEqualTypeOf<
VolunteerStateAppreciationType | undefined
>();
});

it("person and representative", () => {
expectTypeOf<ApiPersonPatch["avatarUrl"]>().toEqualTypeOf<
Clearable<string>
>();
expectTypeOf<ApiPersonPatch["middleName"]>().toEqualTypeOf<
Clearable<string>
>();
expectTypeOf<ApiPersonPatch["phone"]>().toEqualTypeOf<
Clearable<string>
>();
expectTypeOf<ApiPersonPatch["landline"]>().toEqualTypeOf<
Clearable<string>
>();
expectTypeOf<ApiPersonPatch["email"]>().toEqualTypeOf<
Clearable<string>
>();
expectTypeOf<ApiPersonPatch["firstName"]>().toEqualTypeOf<
string | undefined
>();
expectTypeOf<ApiPersonPatch["lastName"]>().toEqualTypeOf<
string | undefined
>();
expectTypeOf<ApiPersonPatch["address"]>().toEqualTypeOf<
Address | undefined
>();
expectTypeOf<ApiPersonPatch["preferredComm"]>().toEqualTypeOf<
PreferredCommunicationType[] | undefined
>();
expectTypeOf<ApiPersonPatch>().not.toHaveProperty("id");
expectTypeOf<ApiRepresentativePatch["phone"]>().toEqualTypeOf<
Clearable<string>
>();
expectTypeOf<ApiRepresentativePatch["role"]>().toEqualTypeOf<
AgentRoleType | undefined
>();
expectTypeOf<ApiRepresentativePatch["agentId"]>().toEqualTypeOf<
number | undefined
>();
expectTypeOf<ApiRepresentativePatch>().not.toHaveProperty("id");
});

it("agent contact", () => {
expectTypeOf<ApiAgentContactPatch["middleName"]>().toEqualTypeOf<
Clearable<string>
>();
expectTypeOf<ApiAgentContactPatch["email"]>().toEqualTypeOf<
Clearable<string>
>();
expectTypeOf<ApiAgentContactPatch["phone"]>().toEqualTypeOf<
Clearable<string>
>();
expectTypeOf<ApiAgentContactPatch["landline"]>().toEqualTypeOf<
Clearable<string>
>();
expectTypeOf<ApiAgentContactPatch["addressStreet"]>().toEqualTypeOf<
Clearable<string>
>();
expectTypeOf<ApiAgentContactPatch["addressPostcode"]>().toEqualTypeOf<
Clearable<string>
>();
expectTypeOf<ApiAgentContactPatch["firstName"]>().toEqualTypeOf<
string | undefined
>();
expectTypeOf<ApiAgentContactPatch["lastName"]>().toEqualTypeOf<
string | undefined
>();
expectTypeOf<ApiAgentContactPatch["role"]>().toEqualTypeOf<
AgentRoleType | undefined
>();
});

it("activity log has no nullable fields", () => {
expectTypeOf<ApiActivityLogPatch["date"]>().toEqualTypeOf<
Date | undefined
>();
expectTypeOf<ApiActivityLogPatch["hours"]>().toEqualTypeOf<
number | undefined
>();
});
});
8 changes: 7 additions & 1 deletion src/types/api/person.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { VoidableProps } from "../utils";
import { Address } from "./location";

export enum PreferredCommunicationType {
Expand All @@ -21,4 +22,9 @@ export interface ApiPersonGet {
preferredComm?: PreferredCommunicationType[];
}

export type ApiPersonPatch = Partial<ApiPersonGet>;
export type ApiPersonPatch = Partial<
VoidableProps<
Omit<ApiPersonGet, "id">,
"avatarUrl" | "middleName" | "phone" | "landline" | "email"
>
>;
Loading