Skip to content

Commit 46b39ce

Browse files
committed
Refactor createObject, createProperty, createTag, and createType functions to remove null handling
1 parent 24e7d47 commit 46b39ce

5 files changed

Lines changed: 9 additions & 27 deletions

File tree

src/api/objects/createObject.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@ import { mapObject } from "../../mappers/objects";
22
import { CreateObjectRequest, RawSpaceObject, SpaceObject } from "../../models";
33
import { apiEndpoints, apiFetch } from "../../utils";
44

5-
export async function createObject(
6-
spaceId: string,
7-
request: CreateObjectRequest,
8-
): Promise<{ object: SpaceObject | null }> {
5+
export async function createObject(spaceId: string, request: CreateObjectRequest): Promise<{ object: SpaceObject }> {
96
const { url, method } = apiEndpoints.createObject(spaceId);
107

118
const response = await apiFetch<{ object: RawSpaceObject }>(url, {
129
method: method,
1310
body: JSON.stringify(request),
1411
});
1512

16-
return {
17-
object: response ? await mapObject(response.payload.object) : null,
18-
};
13+
return { object: await mapObject(response.payload.object) };
1914
}

src/api/properties/createProperty.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@ import { mapProperty } from "../../mappers/properties";
22
import { CreatePropertyRequest, Property, RawProperty } from "../../models";
33
import { apiEndpoints, apiFetch } from "../../utils";
44

5-
export async function createProperty(
6-
spaceId: string,
7-
request: CreatePropertyRequest,
8-
): Promise<{ property: Property | null }> {
5+
export async function createProperty(spaceId: string, request: CreatePropertyRequest): Promise<{ property: Property }> {
96
const { url, method } = apiEndpoints.createProperty(spaceId);
107

118
const response = await apiFetch<{ property: RawProperty }>(url, {
129
method: method,
1310
body: JSON.stringify(request),
1411
});
1512

16-
return {
17-
property: response ? mapProperty(response.payload.property) : null,
18-
};
13+
return { property: mapProperty(response.payload.property) };
1914
}

src/api/tags/createTag.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@ import { mapTag } from "../../mappers/properties";
22
import { CreateTagRequest, RawTag, Tag } from "../../models";
33
import { apiEndpoints, apiFetch } from "../../utils";
44

5-
export async function createTag(
6-
spaceId: string,
7-
propertyId: string,
8-
request: CreateTagRequest,
9-
): Promise<{ tag: Tag | null }> {
5+
export async function createTag(spaceId: string, propertyId: string, request: CreateTagRequest): Promise<{ tag: Tag }> {
106
const { url, method } = apiEndpoints.createTag(spaceId, propertyId);
117

128
const response = await apiFetch<{ tag: RawTag }>(url, {
139
method: method,
1410
body: JSON.stringify(request),
1511
});
1612

17-
return {
18-
tag: response ? mapTag(response.payload.tag) : null,
19-
};
13+
return { tag: mapTag(response.payload.tag) };
2014
}

src/api/types/createType.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ import { mapType } from "../../mappers/types";
22
import { CreateTypeRequest, RawType, Type } from "../../models";
33
import { apiEndpoints, apiFetch } from "../../utils";
44

5-
export async function createType(spaceId: string, request: CreateTypeRequest): Promise<{ type: Type | null }> {
5+
export async function createType(spaceId: string, request: CreateTypeRequest): Promise<{ type: Type }> {
66
const { url, method } = apiEndpoints.createType(spaceId);
77

88
const response = await apiFetch<{ type: RawType }>(url, {
99
method: method,
1010
body: JSON.stringify(request),
1111
});
1212

13-
return {
14-
type: response ? await mapType(response.payload.type) : null,
15-
};
13+
return { type: await mapType(response.payload.type) };
1614
}

src/components/CreateForm/CreateObjectForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export function CreateObjectForm({ draftValues, enableDrafts }: CreateObjectForm
185185

186186
const response = await createObject(selectedSpaceId, request);
187187

188-
if (response.object?.id) {
188+
if (response.object.id) {
189189
if (selectedListId) {
190190
const request: AddObjectsToListRequest = { objects: [response.object.id] };
191191
await addObjectsToList(selectedSpaceId, selectedListId, request);

0 commit comments

Comments
 (0)