@intellegens/cornerstone-client 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -8,4 +8,22 @@ import { ApiReadControllerClient } from '../../..';
|
|
|
8
8
|
* @template TDto - Data Transfer Object representing the entity
|
|
9
9
|
*/
|
|
10
10
|
export declare class ApiCrudControllerClient<TKey, TDto> extends ApiReadControllerClient<TKey, TDto> {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new entity.
|
|
13
|
+
* @param dto - Insert request DTO
|
|
14
|
+
* @returns The created entity DTO
|
|
15
|
+
*/
|
|
16
|
+
create(dto: TDto): Promise<TDto>;
|
|
17
|
+
/**
|
|
18
|
+
* Updates an existing entity.
|
|
19
|
+
* @param id - The ID of the entity to update
|
|
20
|
+
* @param dto - Update request DTO
|
|
21
|
+
* @returns The updated entity DTO
|
|
22
|
+
*/
|
|
23
|
+
update(id: TKey, dto: TDto): Promise<TDto>;
|
|
24
|
+
/**
|
|
25
|
+
* Deletes an entity by ID.
|
|
26
|
+
* @param id - The ID of the entity to delete
|
|
27
|
+
*/
|
|
28
|
+
delete(id: TKey): Promise<void>;
|
|
11
29
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiReadControllerClient } from '../../..';
|
|
1
|
+
import { apiInitializationService, ApiReadControllerClient } from '../../..';
|
|
2
2
|
/**
|
|
3
3
|
* Generic API client for consuming any Cornerstone CrudController
|
|
4
4
|
*
|
|
@@ -8,4 +8,67 @@ import { ApiReadControllerClient } from '../../..';
|
|
|
8
8
|
* @template TDto - Data Transfer Object representing the entity
|
|
9
9
|
*/
|
|
10
10
|
export class ApiCrudControllerClient extends ApiReadControllerClient {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new entity.
|
|
13
|
+
* @param dto - Insert request DTO
|
|
14
|
+
* @returns The created entity DTO
|
|
15
|
+
*/
|
|
16
|
+
async create(dto) {
|
|
17
|
+
try {
|
|
18
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/Create`);
|
|
19
|
+
const response = await fetch(url, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers: { 'Content-Type': 'application/json' },
|
|
22
|
+
body: JSON.stringify(dto),
|
|
23
|
+
credentials: 'include',
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok)
|
|
26
|
+
throw new Error('Failed to create record');
|
|
27
|
+
return response.json();
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
throw err instanceof Error ? err : new Error('Unknown error creating record');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Updates an existing entity.
|
|
35
|
+
* @param id - The ID of the entity to update
|
|
36
|
+
* @param dto - Update request DTO
|
|
37
|
+
* @returns The updated entity DTO
|
|
38
|
+
*/
|
|
39
|
+
async update(id, dto) {
|
|
40
|
+
try {
|
|
41
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/Update?id=${encodeURIComponent(String(id))}`);
|
|
42
|
+
const response = await fetch(url, {
|
|
43
|
+
method: 'PUT',
|
|
44
|
+
headers: { 'Content-Type': 'application/json' },
|
|
45
|
+
body: JSON.stringify(dto),
|
|
46
|
+
credentials: 'include',
|
|
47
|
+
});
|
|
48
|
+
if (!response.ok)
|
|
49
|
+
throw new Error('Failed to update record');
|
|
50
|
+
return response.json();
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
throw err instanceof Error ? err : new Error('Unknown error updating record');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Deletes an entity by ID.
|
|
58
|
+
* @param id - The ID of the entity to delete
|
|
59
|
+
*/
|
|
60
|
+
async delete(id) {
|
|
61
|
+
try {
|
|
62
|
+
const url = await apiInitializationService.getApiUrl(this.baseControllerPath, `/Delete?id=${encodeURIComponent(String(id))}`);
|
|
63
|
+
const response = await fetch(url, {
|
|
64
|
+
method: 'DELETE',
|
|
65
|
+
credentials: 'include',
|
|
66
|
+
});
|
|
67
|
+
if (!response.ok)
|
|
68
|
+
throw new Error('Failed to delete record');
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
throw err instanceof Error ? err : new Error('Unknown error deleting record');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
11
74
|
}
|
|
@@ -8,7 +8,7 @@ import { IIdentifiable, ReadSelectedDefinition } from '../../../../data';
|
|
|
8
8
|
* @template TDto - Data Transfer Object representing the entity
|
|
9
9
|
*/
|
|
10
10
|
export declare class ApiReadControllerClient<TKey, TDto = IIdentifiable<TKey>> {
|
|
11
|
-
|
|
11
|
+
protected readonly baseControllerPath: string;
|
|
12
12
|
/**
|
|
13
13
|
* Constructor
|
|
14
14
|
* @param baseControllerPath Base path to API controller
|