@carbonorm/carbonreact 3.4.1 → 3.4.4
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/dist/CarbonReact.d.ts +0 -3
- package/dist/api/hoc/getStatefulObjectWithWhere.d.ts +11 -0
- package/dist/api/hoc/watchInputElementChangeEvent.d.ts +2 -0
- package/dist/api/rest/C6.d.ts +579 -0
- package/dist/api/rest/Carbons.d.ts +88 -0
- package/dist/api/rest/Carbons.test.d.ts +14 -0
- package/dist/api/rest/Chat_Messages.d.ts +88 -0
- package/dist/api/rest/Chat_Messages.test.d.ts +20 -0
- package/dist/api/rest/Documentation.d.ts +88 -0
- package/dist/api/rest/Documentation.test.d.ts +11 -0
- package/dist/api/rest/Feature_Group_References.d.ts +88 -0
- package/dist/api/rest/Feature_Group_References.test.d.ts +13 -0
- package/dist/api/rest/Features.d.ts +88 -0
- package/dist/api/rest/Features.test.d.ts +14 -0
- package/dist/api/rest/Group_References.d.ts +88 -0
- package/dist/api/rest/Group_References.test.d.ts +13 -0
- package/dist/api/rest/Groups.d.ts +88 -0
- package/dist/api/rest/Groups.test.d.ts +15 -0
- package/dist/api/rest/History_Logs.d.ts +88 -0
- package/dist/api/rest/History_Logs.test.d.ts +13 -0
- package/dist/api/rest/Likes.d.ts +88 -0
- package/dist/api/rest/Likes.test.d.ts +13 -0
- package/dist/api/rest/Location_References.d.ts +88 -0
- package/dist/api/rest/Location_References.test.d.ts +14 -0
- package/dist/api/rest/Locations.d.ts +88 -0
- package/dist/api/rest/Locations.test.d.ts +18 -0
- package/dist/api/rest/Photos.d.ts +88 -0
- package/dist/api/rest/Photos.test.d.ts +20 -0
- package/dist/api/rest/Posts.d.ts +88 -0
- package/dist/api/rest/Posts.test.d.ts +22 -0
- package/dist/api/rest/Projects.d.ts +88 -0
- package/dist/api/rest/Projects.test.d.ts +21 -0
- package/dist/api/rest/Reports.d.ts +88 -0
- package/dist/api/rest/Reports.test.d.ts +11 -0
- package/dist/api/rest/Sessions.d.ts +88 -0
- package/dist/api/rest/Sessions.test.d.ts +14 -0
- package/dist/api/rest/Subscription.d.ts +88 -0
- package/dist/api/rest/Subscription.test.d.ts +20 -0
- package/dist/api/rest/User_Followers.d.ts +88 -0
- package/dist/api/rest/User_Followers.test.d.ts +16 -0
- package/dist/api/rest/User_Groups.d.ts +88 -0
- package/dist/api/rest/User_Groups.test.d.ts +13 -0
- package/dist/api/rest/User_Messages.d.ts +88 -0
- package/dist/api/rest/User_Messages.test.d.ts +20 -0
- package/dist/api/rest/User_Sessions.d.ts +88 -0
- package/dist/api/rest/User_Sessions.test.d.ts +14 -0
- package/dist/api/rest/User_Tasks.d.ts +88 -0
- package/dist/api/rest/User_Tasks.test.d.ts +22 -0
- package/dist/api/rest/Users.d.ts +88 -0
- package/dist/api/rest/Users.test.d.ts +44 -0
- package/dist/api/rest/WsLiveUpdates.d.ts +3 -0
- package/dist/components/WebSocket/CarbonWebSocket.d.ts +8 -4
- package/dist/index.cjs.js +5056 -2124
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +53 -0
- package/dist/index.esm.js +4957 -2105
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/CarbonReact.tsx +0 -3
- package/src/api/hoc/getStatefulObjectWithWhere.tsx +17 -0
- package/src/api/hoc/watchInputElementChangeEvent.tsx +24 -0
- package/src/api/rest/C6.tsx +2687 -0
- package/src/api/rest/Carbons.test.tsx +128 -0
- package/src/api/rest/Carbons.tsx +145 -0
- package/src/api/rest/Chat_Messages.test.tsx +138 -0
- package/src/api/rest/Chat_Messages.tsx +151 -0
- package/src/api/rest/Documentation.test.tsx +128 -0
- package/src/api/rest/Documentation.tsx +142 -0
- package/src/api/rest/Feature_Group_References.test.tsx +126 -0
- package/src/api/rest/Feature_Group_References.tsx +144 -0
- package/src/api/rest/Features.test.tsx +128 -0
- package/src/api/rest/Features.tsx +145 -0
- package/src/api/rest/Group_References.test.tsx +126 -0
- package/src/api/rest/Group_References.tsx +144 -0
- package/src/api/rest/Groups.test.tsx +130 -0
- package/src/api/rest/Groups.tsx +146 -0
- package/src/api/rest/History_Logs.test.tsx +130 -0
- package/src/api/rest/History_Logs.tsx +144 -0
- package/src/api/rest/Likes.test.tsx +126 -0
- package/src/api/rest/Likes.tsx +144 -0
- package/src/api/rest/Location_References.test.tsx +128 -0
- package/src/api/rest/Location_References.tsx +145 -0
- package/src/api/rest/Locations.test.tsx +137 -0
- package/src/api/rest/Locations.tsx +149 -0
- package/src/api/rest/Photos.test.tsx +139 -0
- package/src/api/rest/Photos.tsx +151 -0
- package/src/api/rest/Posts.test.tsx +142 -0
- package/src/api/rest/Posts.tsx +153 -0
- package/src/api/rest/Projects.test.tsx +144 -0
- package/src/api/rest/Projects.tsx +152 -0
- package/src/api/rest/Reports.test.tsx +128 -0
- package/src/api/rest/Reports.tsx +142 -0
- package/src/api/rest/Sessions.test.tsx +133 -0
- package/src/api/rest/Sessions.tsx +145 -0
- package/src/api/rest/Subscription.test.tsx +138 -0
- package/src/api/rest/Subscription.tsx +151 -0
- package/src/api/rest/User_Followers.test.tsx +130 -0
- package/src/api/rest/User_Followers.tsx +147 -0
- package/src/api/rest/User_Groups.test.tsx +126 -0
- package/src/api/rest/User_Groups.tsx +144 -0
- package/src/api/rest/User_Messages.test.tsx +137 -0
- package/src/api/rest/User_Messages.tsx +151 -0
- package/src/api/rest/User_Sessions.test.tsx +133 -0
- package/src/api/rest/User_Sessions.tsx +145 -0
- package/src/api/rest/User_Tasks.test.tsx +141 -0
- package/src/api/rest/User_Tasks.tsx +153 -0
- package/src/api/rest/Users.test.tsx +193 -0
- package/src/api/rest/Users.tsx +175 -0
- package/src/api/rest/WsLiveUpdates.tsx +150 -0
- package/src/components/WebSocket/CarbonWebSocket.tsx +22 -11
- package/src/index.ts +53 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
iPostC6RestResponse,
|
|
3
|
+
restRequest,
|
|
4
|
+
GET,
|
|
5
|
+
POST,
|
|
6
|
+
PUT,
|
|
7
|
+
DELETE,
|
|
8
|
+
iDeleteC6RestResponse,
|
|
9
|
+
iGetC6RestResponse,
|
|
10
|
+
iPutC6RestResponse,
|
|
11
|
+
removeInvalidKeys
|
|
12
|
+
} from "@carbonorm/carbonnode";
|
|
13
|
+
import {AxiosResponse} from "axios";
|
|
14
|
+
import {iAPI, Modify} from "restRequest";
|
|
15
|
+
import {deleteRestfulObjectArrays, updateRestfulObjectArrays} from "@carbonorm/carbonreact";
|
|
16
|
+
import {C6, iUser_Sessions, user_sessions, RestTableNames} from "./C6";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
CREATE TABLE `carbon_user_sessions` (
|
|
20
|
+
`user_id` binary(16) NOT NULL,
|
|
21
|
+
`user_ip` varchar(60) DEFAULT NULL,
|
|
22
|
+
`session_id` varchar(255) NOT NULL,
|
|
23
|
+
`session_expires` datetime NOT NULL,
|
|
24
|
+
`session_data` text,
|
|
25
|
+
`user_online_status` tinyint DEFAULT '1',
|
|
26
|
+
PRIMARY KEY (`session_id`)
|
|
27
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
28
|
+
**/
|
|
29
|
+
|
|
30
|
+
type GetCustomAndRequiredFields = {}
|
|
31
|
+
|
|
32
|
+
type GetRequestTableOverrides = {}
|
|
33
|
+
|
|
34
|
+
// required parameters, optional parameters, parameter type overrides, response, and table names
|
|
35
|
+
export const Get = restRequest<GetCustomAndRequiredFields, iUser_Sessions, GetRequestTableOverrides, iGetC6RestResponse<iUser_Sessions>, RestTableNames>({
|
|
36
|
+
C6: C6,
|
|
37
|
+
tableName: user_sessions.TABLE_NAME,
|
|
38
|
+
requestMethod: GET,
|
|
39
|
+
queryCallback: (request) => {
|
|
40
|
+
request.success ??= 'Successfully received user_sessions!'
|
|
41
|
+
request.error ??= 'An unknown issue occurred creating the user_sessions!'
|
|
42
|
+
return request
|
|
43
|
+
},
|
|
44
|
+
responseCallback: (response, _request) => {
|
|
45
|
+
updateRestfulObjectArrays<iUser_Sessions>(response?.data?.rest, "user_sessions", C6.user_sessions.PRIMARY_SHORT as (keyof iUser_Sessions)[])
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
type PutCustomAndRequiredFields = {}
|
|
50
|
+
|
|
51
|
+
type PutRequestTableOverrides = {}
|
|
52
|
+
|
|
53
|
+
export function putStateUser_Sessions(response : AxiosResponse<iPutC6RestResponse<iUser_Sessions>>, request : iAPI<Modify<iUser_Sessions, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
|
|
54
|
+
updateRestfulObjectArrays<iUser_Sessions>([
|
|
55
|
+
removeInvalidKeys<iUser_Sessions>({
|
|
56
|
+
...request,
|
|
57
|
+
...response?.data?.rest,
|
|
58
|
+
}, C6.TABLES)
|
|
59
|
+
], "user_sessions", user_sessions.PRIMARY_SHORT as (keyof iUser_Sessions)[])
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const Put = restRequest<PutCustomAndRequiredFields, iUser_Sessions, PutRequestTableOverrides, iPutC6RestResponse<iUser_Sessions>, RestTableNames>({
|
|
63
|
+
C6: C6,
|
|
64
|
+
tableName: user_sessions.TABLE_NAME,
|
|
65
|
+
requestMethod: PUT,
|
|
66
|
+
queryCallback: (request) => {
|
|
67
|
+
request.success ??= 'Successfully updated user_sessions data!'
|
|
68
|
+
request.error ??= 'An unknown issue occurred updating the user_sessions data!'
|
|
69
|
+
return request
|
|
70
|
+
},
|
|
71
|
+
responseCallback: putStateUser_Sessions
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
type PostCustomAndRequiredFields = {}
|
|
75
|
+
|
|
76
|
+
type PostRequestTableOverrides = {}
|
|
77
|
+
|
|
78
|
+
export function postStateUser_Sessions(response : AxiosResponse<iPostC6RestResponse<iUser_Sessions>>, request : iAPI<Modify<iUser_Sessions, PostRequestTableOverrides>> & PostCustomAndRequiredFields, id: string | number | boolean) {
|
|
79
|
+
if ('number' === typeof id || 'string' === typeof id) {
|
|
80
|
+
if (1 !== user_sessions.PRIMARY_SHORT.length) {
|
|
81
|
+
console.error("C6 received unexpected result's given the primary key length");
|
|
82
|
+
} else {
|
|
83
|
+
request[user_sessions.PRIMARY_SHORT[0]] = id
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
updateRestfulObjectArrays<iUser_Sessions>(
|
|
87
|
+
undefined !== request.dataInsertMultipleRows
|
|
88
|
+
? request.dataInsertMultipleRows.map((request, index) => {
|
|
89
|
+
return removeInvalidKeys<iUser_Sessions>({
|
|
90
|
+
...request,
|
|
91
|
+
...(index === 0 ? response?.data?.rest : {}),
|
|
92
|
+
}, C6.TABLES)
|
|
93
|
+
})
|
|
94
|
+
: [
|
|
95
|
+
removeInvalidKeys<iUser_Sessions>({
|
|
96
|
+
...request,
|
|
97
|
+
...response?.data?.rest,
|
|
98
|
+
}, C6.TABLES)
|
|
99
|
+
],
|
|
100
|
+
"user_sessions",
|
|
101
|
+
user_sessions.PRIMARY_SHORT as (keyof iUser_Sessions)[]
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const Post = restRequest<PostCustomAndRequiredFields, iUser_Sessions, PostRequestTableOverrides, iPostC6RestResponse<iUser_Sessions>, RestTableNames>({
|
|
106
|
+
C6: C6,
|
|
107
|
+
tableName: user_sessions.TABLE_NAME,
|
|
108
|
+
requestMethod: POST,
|
|
109
|
+
queryCallback: (request) => {
|
|
110
|
+
request.success ??= 'Successfully created the user_sessions data!'
|
|
111
|
+
request.error ??= 'An unknown issue occurred creating the user_sessions data!'
|
|
112
|
+
return request
|
|
113
|
+
},
|
|
114
|
+
responseCallback: postStateUser_Sessions
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
type DeleteCustomAndRequiredFields = {}
|
|
118
|
+
|
|
119
|
+
type DeleteRequestTableOverrides = {}
|
|
120
|
+
|
|
121
|
+
export function deleteStateUser_Sessions(_response : AxiosResponse<iDeleteC6RestResponse<iUser_Sessions>>, request : iAPI<Modify<iUser_Sessions, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
|
|
122
|
+
deleteRestfulObjectArrays<iUser_Sessions>([
|
|
123
|
+
request
|
|
124
|
+
], "user_sessions", user_sessions.PRIMARY_SHORT as (keyof iUser_Sessions)[])
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const Delete = restRequest<DeleteCustomAndRequiredFields, iUser_Sessions, DeleteRequestTableOverrides, iDeleteC6RestResponse<iUser_Sessions>, RestTableNames>({
|
|
128
|
+
C6: C6,
|
|
129
|
+
tableName: user_sessions.TABLE_NAME,
|
|
130
|
+
requestMethod: DELETE,
|
|
131
|
+
queryCallback: (request) => {
|
|
132
|
+
request.success ??= 'Successfully removed the user_sessions data!'
|
|
133
|
+
request.error ??= 'An unknown issue occurred removing the user_sessions data!'
|
|
134
|
+
return request
|
|
135
|
+
},
|
|
136
|
+
responseCallback: deleteStateUser_Sessions
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export default {
|
|
140
|
+
// Export all GET, POST, PUT, DELETE functions for each table
|
|
141
|
+
Get,
|
|
142
|
+
Post,
|
|
143
|
+
Put,
|
|
144
|
+
Delete,
|
|
145
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import {xdescribe, expect, test} from '@jest/globals';
|
|
2
|
+
import {CarbonReact} from "@carbonorm/carbonreact";
|
|
3
|
+
import {checkAllRequestsComplete} from "@carbonorm/carbonnode";
|
|
4
|
+
import {act, waitFor} from '@testing-library/react';
|
|
5
|
+
import {C6, iRestfulObjectArrayTypes, iUser_Tasks, user_tasks } from "api/rest/C6";
|
|
6
|
+
import User_Tasks from "./User_Tasks";
|
|
7
|
+
|
|
8
|
+
const randomString = Math.random().toString(36).substring(7);
|
|
9
|
+
const randomInt = Math.floor(Math.random() * 1000000);
|
|
10
|
+
const fillString = 'string' + randomString + randomInt;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
CREATE TABLE `carbon_user_tasks` (
|
|
14
|
+
`task_id` binary(16) NOT NULL,
|
|
15
|
+
`user_id` binary(16) NOT NULL COMMENT 'This is the user the task is being assigned to',
|
|
16
|
+
`from_id` binary(16) DEFAULT NULL COMMENT 'Keeping this colum so forgen key will remove task if user deleted',
|
|
17
|
+
`task_name` varchar(40) NOT NULL,
|
|
18
|
+
`task_description` varchar(225) DEFAULT NULL,
|
|
19
|
+
`percent_complete` int DEFAULT '0',
|
|
20
|
+
`start_date` datetime DEFAULT NULL,
|
|
21
|
+
`end_date` datetime DEFAULT NULL,
|
|
22
|
+
PRIMARY KEY (`task_id`),
|
|
23
|
+
KEY `user_tasks_entity_entity_pk_fk` (`from_id`),
|
|
24
|
+
KEY `user_tasks_entity_task_pk_fk` (`task_id`),
|
|
25
|
+
KEY `carbon_user_tasks_carbons_entity_pk_fk_2` (`user_id`),
|
|
26
|
+
CONSTRAINT `carbon_user_tasks_carbons_entity_pk_fk` FOREIGN KEY (`task_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
27
|
+
CONSTRAINT `carbon_user_tasks_carbons_entity_pk_fk_2` FOREIGN KEY (`user_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
28
|
+
CONSTRAINT `carbon_user_tasks_carbons_entity_pk_fk_3` FOREIGN KEY (`from_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
29
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
30
|
+
**/
|
|
31
|
+
|
|
32
|
+
const Test_Data: iUser_Tasks = {
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default Test_Data;
|
|
37
|
+
|
|
38
|
+
xdescribe('REST User_Tasks api', () => {
|
|
39
|
+
|
|
40
|
+
let testData = Test_Data;
|
|
41
|
+
|
|
42
|
+
test('GET POST PUT DELETE', async () => {
|
|
43
|
+
|
|
44
|
+
await act(async () => {
|
|
45
|
+
|
|
46
|
+
let selectAllResponse = await User_Tasks.Get({})
|
|
47
|
+
|
|
48
|
+
if ('function' === typeof selectAllResponse) {
|
|
49
|
+
throw Error('selectAllResponse is a promise, this typically means this specific get request has already run during test setup.');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// We don't care if it is filled or not, just that the request can be made.
|
|
53
|
+
expect(selectAllResponse?.data?.rest).not.toBeUndefined();
|
|
54
|
+
|
|
55
|
+
const postResponse = await User_Tasks.Post(testData);
|
|
56
|
+
|
|
57
|
+
console.log('postResponse', postResponse?.data)
|
|
58
|
+
|
|
59
|
+
expect(postResponse?.data?.created).not.toBeUndefined();
|
|
60
|
+
|
|
61
|
+
const primaryKey = user_tasks.PRIMARY_SHORT[0];
|
|
62
|
+
|
|
63
|
+
const postID = postResponse?.data?.created
|
|
64
|
+
|
|
65
|
+
const singleRowSelect = await User_Tasks.Get({
|
|
66
|
+
[C6.WHERE]: {
|
|
67
|
+
[user_tasks[primaryKey.toUpperCase()]]: postID,
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
if ('function' === typeof singleRowSelect) {
|
|
72
|
+
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
console.log('singleRowSelect', singleRowSelect?.data)
|
|
76
|
+
|
|
77
|
+
// Ensure the expected response datastructure is returned
|
|
78
|
+
expect(singleRowSelect?.data?.rest).not.toBeUndefined();
|
|
79
|
+
|
|
80
|
+
// Make sure the previously created post is now returned
|
|
81
|
+
expect(typeof singleRowSelect?.data?.rest).toEqual('object');
|
|
82
|
+
|
|
83
|
+
// todo - make this work correctly with multiple primary keys
|
|
84
|
+
const selectedPostId = singleRowSelect?.data?.rest[0][primaryKey]
|
|
85
|
+
|
|
86
|
+
expect(selectedPostId).toEqual(postID);
|
|
87
|
+
|
|
88
|
+
const multipleRowSelect = await User_Tasks.Get({
|
|
89
|
+
[C6.WHERE]: {
|
|
90
|
+
[user_tasks[primaryKey.toUpperCase()]]: [C6.IN, [0, postID]],
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
if ('function' === typeof multipleRowSelect) {
|
|
95
|
+
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
console.log('singleRowSelect', multipleRowSelect?.data)
|
|
99
|
+
|
|
100
|
+
// Ensure the expected response datastructure is returned
|
|
101
|
+
expect(multipleRowSelect?.data?.rest).not.toBeUndefined();
|
|
102
|
+
|
|
103
|
+
// Make sure the previously created post is now returned
|
|
104
|
+
expect(typeof multipleRowSelect?.data?.rest).toEqual('object');
|
|
105
|
+
|
|
106
|
+
testData[primaryKey] = postID
|
|
107
|
+
|
|
108
|
+
testData.task_id = fillString.substring(0, 16);
|
|
109
|
+
testData.user_id = fillString.substring(0, 16);
|
|
110
|
+
testData.from_id = fillString.substring(0, 16);
|
|
111
|
+
testData.task_name = fillString.substring(0, 40);
|
|
112
|
+
testData.task_description = fillString.substring(0, 225);
|
|
113
|
+
testData.percent_complete = randomInt;
|
|
114
|
+
testData.start_date = fillString.substring(0, );
|
|
115
|
+
testData.end_date = fillString.substring(0, );
|
|
116
|
+
|
|
117
|
+
// wait for the global state to be updated
|
|
118
|
+
expect(CarbonReact.getState<iRestfulObjectArrayTypes>().user_tasks).not.toBeUndefined();
|
|
119
|
+
|
|
120
|
+
const updateResponse = await User_Tasks.Put(testData)
|
|
121
|
+
|
|
122
|
+
expect(updateResponse?.data?.updated).not.toBeUndefined();
|
|
123
|
+
|
|
124
|
+
const deleteResponse = await User_Tasks.Delete({
|
|
125
|
+
[primaryKey]: postID
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
console.log('deleteResponse', deleteResponse?.data)
|
|
129
|
+
|
|
130
|
+
expect(deleteResponse?.data?.deleted).not.toBeUndefined();
|
|
131
|
+
|
|
132
|
+
await waitFor(async () => {
|
|
133
|
+
expect(checkAllRequestsComplete()).toEqual(true);
|
|
134
|
+
}, {timeout: 10000, interval: 1000});
|
|
135
|
+
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
}, 100000);
|
|
139
|
+
|
|
140
|
+
})
|
|
141
|
+
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {
|
|
2
|
+
iPostC6RestResponse,
|
|
3
|
+
restRequest,
|
|
4
|
+
GET,
|
|
5
|
+
POST,
|
|
6
|
+
PUT,
|
|
7
|
+
DELETE,
|
|
8
|
+
iDeleteC6RestResponse,
|
|
9
|
+
iGetC6RestResponse,
|
|
10
|
+
iPutC6RestResponse,
|
|
11
|
+
removeInvalidKeys
|
|
12
|
+
} from "@carbonorm/carbonnode";
|
|
13
|
+
import {AxiosResponse} from "axios";
|
|
14
|
+
import {iAPI, Modify} from "restRequest";
|
|
15
|
+
import {deleteRestfulObjectArrays, updateRestfulObjectArrays} from "@carbonorm/carbonreact";
|
|
16
|
+
import {C6, iUser_Tasks, user_tasks, RestTableNames} from "./C6";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
CREATE TABLE `carbon_user_tasks` (
|
|
20
|
+
`task_id` binary(16) NOT NULL,
|
|
21
|
+
`user_id` binary(16) NOT NULL COMMENT 'This is the user the task is being assigned to',
|
|
22
|
+
`from_id` binary(16) DEFAULT NULL COMMENT 'Keeping this colum so forgen key will remove task if user deleted',
|
|
23
|
+
`task_name` varchar(40) NOT NULL,
|
|
24
|
+
`task_description` varchar(225) DEFAULT NULL,
|
|
25
|
+
`percent_complete` int DEFAULT '0',
|
|
26
|
+
`start_date` datetime DEFAULT NULL,
|
|
27
|
+
`end_date` datetime DEFAULT NULL,
|
|
28
|
+
PRIMARY KEY (`task_id`),
|
|
29
|
+
KEY `user_tasks_entity_entity_pk_fk` (`from_id`),
|
|
30
|
+
KEY `user_tasks_entity_task_pk_fk` (`task_id`),
|
|
31
|
+
KEY `carbon_user_tasks_carbons_entity_pk_fk_2` (`user_id`),
|
|
32
|
+
CONSTRAINT `carbon_user_tasks_carbons_entity_pk_fk` FOREIGN KEY (`task_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
33
|
+
CONSTRAINT `carbon_user_tasks_carbons_entity_pk_fk_2` FOREIGN KEY (`user_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
34
|
+
CONSTRAINT `carbon_user_tasks_carbons_entity_pk_fk_3` FOREIGN KEY (`from_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
35
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
36
|
+
**/
|
|
37
|
+
|
|
38
|
+
type GetCustomAndRequiredFields = {}
|
|
39
|
+
|
|
40
|
+
type GetRequestTableOverrides = {}
|
|
41
|
+
|
|
42
|
+
// required parameters, optional parameters, parameter type overrides, response, and table names
|
|
43
|
+
export const Get = restRequest<GetCustomAndRequiredFields, iUser_Tasks, GetRequestTableOverrides, iGetC6RestResponse<iUser_Tasks>, RestTableNames>({
|
|
44
|
+
C6: C6,
|
|
45
|
+
tableName: user_tasks.TABLE_NAME,
|
|
46
|
+
requestMethod: GET,
|
|
47
|
+
queryCallback: (request) => {
|
|
48
|
+
request.success ??= 'Successfully received user_tasks!'
|
|
49
|
+
request.error ??= 'An unknown issue occurred creating the user_tasks!'
|
|
50
|
+
return request
|
|
51
|
+
},
|
|
52
|
+
responseCallback: (response, _request) => {
|
|
53
|
+
updateRestfulObjectArrays<iUser_Tasks>(response?.data?.rest, "user_tasks", C6.user_tasks.PRIMARY_SHORT as (keyof iUser_Tasks)[])
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
type PutCustomAndRequiredFields = {}
|
|
58
|
+
|
|
59
|
+
type PutRequestTableOverrides = {}
|
|
60
|
+
|
|
61
|
+
export function putStateUser_Tasks(response : AxiosResponse<iPutC6RestResponse<iUser_Tasks>>, request : iAPI<Modify<iUser_Tasks, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
|
|
62
|
+
updateRestfulObjectArrays<iUser_Tasks>([
|
|
63
|
+
removeInvalidKeys<iUser_Tasks>({
|
|
64
|
+
...request,
|
|
65
|
+
...response?.data?.rest,
|
|
66
|
+
}, C6.TABLES)
|
|
67
|
+
], "user_tasks", user_tasks.PRIMARY_SHORT as (keyof iUser_Tasks)[])
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const Put = restRequest<PutCustomAndRequiredFields, iUser_Tasks, PutRequestTableOverrides, iPutC6RestResponse<iUser_Tasks>, RestTableNames>({
|
|
71
|
+
C6: C6,
|
|
72
|
+
tableName: user_tasks.TABLE_NAME,
|
|
73
|
+
requestMethod: PUT,
|
|
74
|
+
queryCallback: (request) => {
|
|
75
|
+
request.success ??= 'Successfully updated user_tasks data!'
|
|
76
|
+
request.error ??= 'An unknown issue occurred updating the user_tasks data!'
|
|
77
|
+
return request
|
|
78
|
+
},
|
|
79
|
+
responseCallback: putStateUser_Tasks
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
type PostCustomAndRequiredFields = {}
|
|
83
|
+
|
|
84
|
+
type PostRequestTableOverrides = {}
|
|
85
|
+
|
|
86
|
+
export function postStateUser_Tasks(response : AxiosResponse<iPostC6RestResponse<iUser_Tasks>>, request : iAPI<Modify<iUser_Tasks, PostRequestTableOverrides>> & PostCustomAndRequiredFields, id: string | number | boolean) {
|
|
87
|
+
if ('number' === typeof id || 'string' === typeof id) {
|
|
88
|
+
if (1 !== user_tasks.PRIMARY_SHORT.length) {
|
|
89
|
+
console.error("C6 received unexpected result's given the primary key length");
|
|
90
|
+
} else {
|
|
91
|
+
request[user_tasks.PRIMARY_SHORT[0]] = id
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
updateRestfulObjectArrays<iUser_Tasks>(
|
|
95
|
+
undefined !== request.dataInsertMultipleRows
|
|
96
|
+
? request.dataInsertMultipleRows.map((request, index) => {
|
|
97
|
+
return removeInvalidKeys<iUser_Tasks>({
|
|
98
|
+
...request,
|
|
99
|
+
...(index === 0 ? response?.data?.rest : {}),
|
|
100
|
+
}, C6.TABLES)
|
|
101
|
+
})
|
|
102
|
+
: [
|
|
103
|
+
removeInvalidKeys<iUser_Tasks>({
|
|
104
|
+
...request,
|
|
105
|
+
...response?.data?.rest,
|
|
106
|
+
}, C6.TABLES)
|
|
107
|
+
],
|
|
108
|
+
"user_tasks",
|
|
109
|
+
user_tasks.PRIMARY_SHORT as (keyof iUser_Tasks)[]
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const Post = restRequest<PostCustomAndRequiredFields, iUser_Tasks, PostRequestTableOverrides, iPostC6RestResponse<iUser_Tasks>, RestTableNames>({
|
|
114
|
+
C6: C6,
|
|
115
|
+
tableName: user_tasks.TABLE_NAME,
|
|
116
|
+
requestMethod: POST,
|
|
117
|
+
queryCallback: (request) => {
|
|
118
|
+
request.success ??= 'Successfully created the user_tasks data!'
|
|
119
|
+
request.error ??= 'An unknown issue occurred creating the user_tasks data!'
|
|
120
|
+
return request
|
|
121
|
+
},
|
|
122
|
+
responseCallback: postStateUser_Tasks
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
type DeleteCustomAndRequiredFields = {}
|
|
126
|
+
|
|
127
|
+
type DeleteRequestTableOverrides = {}
|
|
128
|
+
|
|
129
|
+
export function deleteStateUser_Tasks(_response : AxiosResponse<iDeleteC6RestResponse<iUser_Tasks>>, request : iAPI<Modify<iUser_Tasks, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
|
|
130
|
+
deleteRestfulObjectArrays<iUser_Tasks>([
|
|
131
|
+
request
|
|
132
|
+
], "user_tasks", user_tasks.PRIMARY_SHORT as (keyof iUser_Tasks)[])
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const Delete = restRequest<DeleteCustomAndRequiredFields, iUser_Tasks, DeleteRequestTableOverrides, iDeleteC6RestResponse<iUser_Tasks>, RestTableNames>({
|
|
136
|
+
C6: C6,
|
|
137
|
+
tableName: user_tasks.TABLE_NAME,
|
|
138
|
+
requestMethod: DELETE,
|
|
139
|
+
queryCallback: (request) => {
|
|
140
|
+
request.success ??= 'Successfully removed the user_tasks data!'
|
|
141
|
+
request.error ??= 'An unknown issue occurred removing the user_tasks data!'
|
|
142
|
+
return request
|
|
143
|
+
},
|
|
144
|
+
responseCallback: deleteStateUser_Tasks
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
export default {
|
|
148
|
+
// Export all GET, POST, PUT, DELETE functions for each table
|
|
149
|
+
Get,
|
|
150
|
+
Post,
|
|
151
|
+
Put,
|
|
152
|
+
Delete,
|
|
153
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {xdescribe, expect, test} from '@jest/globals';
|
|
2
|
+
import {CarbonReact} from "@carbonorm/carbonreact";
|
|
3
|
+
import {checkAllRequestsComplete} from "@carbonorm/carbonnode";
|
|
4
|
+
import {act, waitFor} from '@testing-library/react';
|
|
5
|
+
import {C6, iRestfulObjectArrayTypes, iUsers, users } from "api/rest/C6";
|
|
6
|
+
import Users from "./Users";
|
|
7
|
+
|
|
8
|
+
const randomString = Math.random().toString(36).substring(7);
|
|
9
|
+
const randomInt = Math.floor(Math.random() * 1000000);
|
|
10
|
+
const fillString = 'string' + randomString + randomInt;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
CREATE TABLE `carbon_users` (
|
|
14
|
+
`user_username` varchar(100) NOT NULL,
|
|
15
|
+
`user_password` varchar(225) NOT NULL,
|
|
16
|
+
`user_id` binary(16) NOT NULL,
|
|
17
|
+
`user_type` varchar(20) NOT NULL DEFAULT 'Athlete',
|
|
18
|
+
`user_sport` varchar(20) DEFAULT 'GOLF',
|
|
19
|
+
`user_session_id` varchar(225) DEFAULT NULL,
|
|
20
|
+
`user_facebook_id` varchar(225) DEFAULT NULL,
|
|
21
|
+
`user_first_name` varchar(25) NOT NULL,
|
|
22
|
+
`user_last_name` varchar(25) NOT NULL,
|
|
23
|
+
`user_profile_pic` longblob,
|
|
24
|
+
`user_profile_uri` varchar(225) DEFAULT NULL,
|
|
25
|
+
`user_cover_photo` longblob,
|
|
26
|
+
`user_birthday` varchar(9) DEFAULT NULL,
|
|
27
|
+
`user_gender` varchar(25) DEFAULT NULL,
|
|
28
|
+
`user_about_me` varchar(225) DEFAULT NULL,
|
|
29
|
+
`user_rank` int DEFAULT '0',
|
|
30
|
+
`user_email` varchar(50) NOT NULL,
|
|
31
|
+
`user_email_code` varchar(225) DEFAULT NULL,
|
|
32
|
+
`user_email_confirmed` tinyint DEFAULT '0' COMMENT 'need to change to enums, but no support in rest yet',
|
|
33
|
+
`user_generated_string` varchar(200) DEFAULT NULL,
|
|
34
|
+
`user_membership` int DEFAULT '0',
|
|
35
|
+
`user_deactivated` tinyint DEFAULT '0',
|
|
36
|
+
`user_last_login` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
37
|
+
`user_ip` varchar(20) NOT NULL,
|
|
38
|
+
`user_education_history` varchar(200) DEFAULT NULL,
|
|
39
|
+
`user_creation_date` datetime DEFAULT CURRENT_TIMESTAMP,
|
|
40
|
+
`user_education` varchar(255) DEFAULT NULL,
|
|
41
|
+
`user_notes` text,
|
|
42
|
+
`user_skills` varchar(255) DEFAULT NULL,
|
|
43
|
+
`user_is_moderator` tinyint(1) NOT NULL DEFAULT '0',
|
|
44
|
+
`user_is_administrator` tinyint(1) NOT NULL DEFAULT '0',
|
|
45
|
+
`user_is_caller` tinyint(1) NOT NULL DEFAULT '0',
|
|
46
|
+
PRIMARY KEY (`user_id`),
|
|
47
|
+
UNIQUE KEY `carbon_users_user_username_uindex` (`user_username`),
|
|
48
|
+
UNIQUE KEY `user_user_profile_uri_uindex` (`user_profile_uri`),
|
|
49
|
+
UNIQUE KEY `carbon_users_user_facebook_id_uindex` (`user_facebook_id`),
|
|
50
|
+
CONSTRAINT `user_entity_entity_pk_fk` FOREIGN KEY (`user_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
51
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
52
|
+
**/
|
|
53
|
+
|
|
54
|
+
const Test_Data: iUsers = {
|
|
55
|
+
|
|
56
|
+
user_profile_pic: fillString.substring(0, ),
|
|
57
|
+
|
|
58
|
+
user_cover_photo: fillString.substring(0, ),
|
|
59
|
+
|
|
60
|
+
user_notes: fillString.substring(0, ),
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default Test_Data;
|
|
65
|
+
|
|
66
|
+
xdescribe('REST Users api', () => {
|
|
67
|
+
|
|
68
|
+
let testData = Test_Data;
|
|
69
|
+
|
|
70
|
+
test('GET POST PUT DELETE', async () => {
|
|
71
|
+
|
|
72
|
+
await act(async () => {
|
|
73
|
+
|
|
74
|
+
let selectAllResponse = await Users.Get({})
|
|
75
|
+
|
|
76
|
+
if ('function' === typeof selectAllResponse) {
|
|
77
|
+
throw Error('selectAllResponse is a promise, this typically means this specific get request has already run during test setup.');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// We don't care if it is filled or not, just that the request can be made.
|
|
81
|
+
expect(selectAllResponse?.data?.rest).not.toBeUndefined();
|
|
82
|
+
|
|
83
|
+
const postResponse = await Users.Post(testData);
|
|
84
|
+
|
|
85
|
+
console.log('postResponse', postResponse?.data)
|
|
86
|
+
|
|
87
|
+
expect(postResponse?.data?.created).not.toBeUndefined();
|
|
88
|
+
|
|
89
|
+
const primaryKey = users.PRIMARY_SHORT[0];
|
|
90
|
+
|
|
91
|
+
const postID = postResponse?.data?.created
|
|
92
|
+
|
|
93
|
+
const singleRowSelect = await Users.Get({
|
|
94
|
+
[C6.WHERE]: {
|
|
95
|
+
[users[primaryKey.toUpperCase()]]: postID,
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
if ('function' === typeof singleRowSelect) {
|
|
100
|
+
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
console.log('singleRowSelect', singleRowSelect?.data)
|
|
104
|
+
|
|
105
|
+
// Ensure the expected response datastructure is returned
|
|
106
|
+
expect(singleRowSelect?.data?.rest).not.toBeUndefined();
|
|
107
|
+
|
|
108
|
+
// Make sure the previously created post is now returned
|
|
109
|
+
expect(typeof singleRowSelect?.data?.rest).toEqual('object');
|
|
110
|
+
|
|
111
|
+
// todo - make this work correctly with multiple primary keys
|
|
112
|
+
const selectedPostId = singleRowSelect?.data?.rest[0][primaryKey]
|
|
113
|
+
|
|
114
|
+
expect(selectedPostId).toEqual(postID);
|
|
115
|
+
|
|
116
|
+
const multipleRowSelect = await Users.Get({
|
|
117
|
+
[C6.WHERE]: {
|
|
118
|
+
[users[primaryKey.toUpperCase()]]: [C6.IN, [0, postID]],
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
if ('function' === typeof multipleRowSelect) {
|
|
123
|
+
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
console.log('singleRowSelect', multipleRowSelect?.data)
|
|
127
|
+
|
|
128
|
+
// Ensure the expected response datastructure is returned
|
|
129
|
+
expect(multipleRowSelect?.data?.rest).not.toBeUndefined();
|
|
130
|
+
|
|
131
|
+
// Make sure the previously created post is now returned
|
|
132
|
+
expect(typeof multipleRowSelect?.data?.rest).toEqual('object');
|
|
133
|
+
|
|
134
|
+
testData[primaryKey] = postID
|
|
135
|
+
|
|
136
|
+
testData.user_username = fillString.substring(0, 100);
|
|
137
|
+
testData.user_password = fillString.substring(0, 225);
|
|
138
|
+
testData.user_id = fillString.substring(0, 16);
|
|
139
|
+
testData.user_type = fillString.substring(0, 20);
|
|
140
|
+
testData.user_sport = fillString.substring(0, 20);
|
|
141
|
+
testData.user_session_id = fillString.substring(0, 225);
|
|
142
|
+
testData.user_facebook_id = fillString.substring(0, 225);
|
|
143
|
+
testData.user_first_name = fillString.substring(0, 25);
|
|
144
|
+
testData.user_last_name = fillString.substring(0, 25);
|
|
145
|
+
testData.user_profile_pic = fillString.substring(0, );
|
|
146
|
+
testData.user_profile_uri = fillString.substring(0, 225);
|
|
147
|
+
testData.user_cover_photo = fillString.substring(0, );
|
|
148
|
+
testData.user_birthday = fillString.substring(0, 9);
|
|
149
|
+
testData.user_gender = fillString.substring(0, 25);
|
|
150
|
+
testData.user_about_me = fillString.substring(0, 225);
|
|
151
|
+
testData.user_rank = randomInt;
|
|
152
|
+
testData.user_email = fillString.substring(0, 50);
|
|
153
|
+
testData.user_email_code = fillString.substring(0, 225);
|
|
154
|
+
testData.user_email_confirmed = fillString.substring(0, );
|
|
155
|
+
testData.user_generated_string = fillString.substring(0, 200);
|
|
156
|
+
testData.user_membership = randomInt;
|
|
157
|
+
testData.user_deactivated = fillString.substring(0, );
|
|
158
|
+
testData.user_last_login = fillString.substring(0, );
|
|
159
|
+
testData.user_ip = fillString.substring(0, 20);
|
|
160
|
+
testData.user_education_history = fillString.substring(0, 200);
|
|
161
|
+
testData.user_creation_date = fillString.substring(0, );
|
|
162
|
+
testData.user_education = fillString.substring(0, 255);
|
|
163
|
+
testData.user_notes = fillString.substring(0, );
|
|
164
|
+
testData.user_skills = fillString.substring(0, 255);
|
|
165
|
+
testData.user_is_moderator = fillString.substring(0, 1);
|
|
166
|
+
testData.user_is_administrator = fillString.substring(0, 1);
|
|
167
|
+
testData.user_is_caller = fillString.substring(0, 1);
|
|
168
|
+
|
|
169
|
+
// wait for the global state to be updated
|
|
170
|
+
expect(CarbonReact.getState<iRestfulObjectArrayTypes>().users).not.toBeUndefined();
|
|
171
|
+
|
|
172
|
+
const updateResponse = await Users.Put(testData)
|
|
173
|
+
|
|
174
|
+
expect(updateResponse?.data?.updated).not.toBeUndefined();
|
|
175
|
+
|
|
176
|
+
const deleteResponse = await Users.Delete({
|
|
177
|
+
[primaryKey]: postID
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
console.log('deleteResponse', deleteResponse?.data)
|
|
181
|
+
|
|
182
|
+
expect(deleteResponse?.data?.deleted).not.toBeUndefined();
|
|
183
|
+
|
|
184
|
+
await waitFor(async () => {
|
|
185
|
+
expect(checkAllRequestsComplete()).toEqual(true);
|
|
186
|
+
}, {timeout: 10000, interval: 1000});
|
|
187
|
+
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
}, 100000);
|
|
191
|
+
|
|
192
|
+
})
|
|
193
|
+
|