@carbonorm/carbonreact 3.4.4 → 3.4.5
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 +3 -0
- package/dist/index.cjs.js +2133 -5049
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +0 -49
- package/dist/index.esm.js +2114 -4952
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/CarbonReact.tsx +3 -0
- package/src/index.ts +0 -49
- package/dist/api/rest/C6.d.ts +0 -579
- package/dist/api/rest/Carbons.d.ts +0 -88
- package/dist/api/rest/Carbons.test.d.ts +0 -14
- package/dist/api/rest/Chat_Messages.d.ts +0 -88
- package/dist/api/rest/Chat_Messages.test.d.ts +0 -20
- package/dist/api/rest/Documentation.d.ts +0 -88
- package/dist/api/rest/Documentation.test.d.ts +0 -11
- package/dist/api/rest/Feature_Group_References.d.ts +0 -88
- package/dist/api/rest/Feature_Group_References.test.d.ts +0 -13
- package/dist/api/rest/Features.d.ts +0 -88
- package/dist/api/rest/Features.test.d.ts +0 -14
- package/dist/api/rest/Group_References.d.ts +0 -88
- package/dist/api/rest/Group_References.test.d.ts +0 -13
- package/dist/api/rest/Groups.d.ts +0 -88
- package/dist/api/rest/Groups.test.d.ts +0 -15
- package/dist/api/rest/History_Logs.d.ts +0 -88
- package/dist/api/rest/History_Logs.test.d.ts +0 -13
- package/dist/api/rest/Likes.d.ts +0 -88
- package/dist/api/rest/Likes.test.d.ts +0 -13
- package/dist/api/rest/Location_References.d.ts +0 -88
- package/dist/api/rest/Location_References.test.d.ts +0 -14
- package/dist/api/rest/Locations.d.ts +0 -88
- package/dist/api/rest/Locations.test.d.ts +0 -18
- package/dist/api/rest/Photos.d.ts +0 -88
- package/dist/api/rest/Photos.test.d.ts +0 -20
- package/dist/api/rest/Posts.d.ts +0 -88
- package/dist/api/rest/Posts.test.d.ts +0 -22
- package/dist/api/rest/Projects.d.ts +0 -88
- package/dist/api/rest/Projects.test.d.ts +0 -21
- package/dist/api/rest/Reports.d.ts +0 -88
- package/dist/api/rest/Reports.test.d.ts +0 -11
- package/dist/api/rest/Sessions.d.ts +0 -88
- package/dist/api/rest/Sessions.test.d.ts +0 -14
- package/dist/api/rest/Subscription.d.ts +0 -88
- package/dist/api/rest/Subscription.test.d.ts +0 -20
- package/dist/api/rest/User_Followers.d.ts +0 -88
- package/dist/api/rest/User_Followers.test.d.ts +0 -16
- package/dist/api/rest/User_Groups.d.ts +0 -88
- package/dist/api/rest/User_Groups.test.d.ts +0 -13
- package/dist/api/rest/User_Messages.d.ts +0 -88
- package/dist/api/rest/User_Messages.test.d.ts +0 -20
- package/dist/api/rest/User_Sessions.d.ts +0 -88
- package/dist/api/rest/User_Sessions.test.d.ts +0 -14
- package/dist/api/rest/User_Tasks.d.ts +0 -88
- package/dist/api/rest/User_Tasks.test.d.ts +0 -22
- package/dist/api/rest/Users.d.ts +0 -88
- package/dist/api/rest/Users.test.d.ts +0 -44
- package/dist/api/rest/WsLiveUpdates.d.ts +0 -3
- package/src/api/rest/C6.tsx +0 -2687
- package/src/api/rest/Carbons.test.tsx +0 -128
- package/src/api/rest/Carbons.tsx +0 -145
- package/src/api/rest/Chat_Messages.test.tsx +0 -138
- package/src/api/rest/Chat_Messages.tsx +0 -151
- package/src/api/rest/Documentation.test.tsx +0 -128
- package/src/api/rest/Documentation.tsx +0 -142
- package/src/api/rest/Feature_Group_References.test.tsx +0 -126
- package/src/api/rest/Feature_Group_References.tsx +0 -144
- package/src/api/rest/Features.test.tsx +0 -128
- package/src/api/rest/Features.tsx +0 -145
- package/src/api/rest/Group_References.test.tsx +0 -126
- package/src/api/rest/Group_References.tsx +0 -144
- package/src/api/rest/Groups.test.tsx +0 -130
- package/src/api/rest/Groups.tsx +0 -146
- package/src/api/rest/History_Logs.test.tsx +0 -130
- package/src/api/rest/History_Logs.tsx +0 -144
- package/src/api/rest/Likes.test.tsx +0 -126
- package/src/api/rest/Likes.tsx +0 -144
- package/src/api/rest/Location_References.test.tsx +0 -128
- package/src/api/rest/Location_References.tsx +0 -145
- package/src/api/rest/Locations.test.tsx +0 -137
- package/src/api/rest/Locations.tsx +0 -149
- package/src/api/rest/Photos.test.tsx +0 -139
- package/src/api/rest/Photos.tsx +0 -151
- package/src/api/rest/Posts.test.tsx +0 -142
- package/src/api/rest/Posts.tsx +0 -153
- package/src/api/rest/Projects.test.tsx +0 -144
- package/src/api/rest/Projects.tsx +0 -152
- package/src/api/rest/Reports.test.tsx +0 -128
- package/src/api/rest/Reports.tsx +0 -142
- package/src/api/rest/Sessions.test.tsx +0 -133
- package/src/api/rest/Sessions.tsx +0 -145
- package/src/api/rest/Subscription.test.tsx +0 -138
- package/src/api/rest/Subscription.tsx +0 -151
- package/src/api/rest/User_Followers.test.tsx +0 -130
- package/src/api/rest/User_Followers.tsx +0 -147
- package/src/api/rest/User_Groups.test.tsx +0 -126
- package/src/api/rest/User_Groups.tsx +0 -144
- package/src/api/rest/User_Messages.test.tsx +0 -137
- package/src/api/rest/User_Messages.tsx +0 -151
- package/src/api/rest/User_Sessions.test.tsx +0 -133
- package/src/api/rest/User_Sessions.tsx +0 -145
- package/src/api/rest/User_Tasks.test.tsx +0 -141
- package/src/api/rest/User_Tasks.tsx +0 -153
- package/src/api/rest/Users.test.tsx +0 -193
- package/src/api/rest/Users.tsx +0 -175
- package/src/api/rest/WsLiveUpdates.tsx +0 -150
|
@@ -1,151 +0,0 @@
|
|
|
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, iSubscription, subscription, RestTableNames} from "./C6";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
CREATE TABLE `carbon_subscription` (
|
|
20
|
-
`subscription_id` binary(16) NOT NULL,
|
|
21
|
-
`subscription_to_entity_id` binary(16) DEFAULT NULL,
|
|
22
|
-
`subscription_for_entity_id` binary(16) DEFAULT NULL,
|
|
23
|
-
`subscription_price` varchar(16) DEFAULT NULL,
|
|
24
|
-
`subscription_start_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
25
|
-
`subscription_end_date` datetime DEFAULT NULL,
|
|
26
|
-
`subscription_transaction_id` varchar(255) DEFAULT NULL,
|
|
27
|
-
PRIMARY KEY (`subscription_id`),
|
|
28
|
-
KEY `carbon_subscription_carbon_carbons_entity_pk_fk2` (`subscription_to_entity_id`),
|
|
29
|
-
KEY `carbon_subscription_carbon_carbons_entity_pk_fk3` (`subscription_for_entity_id`),
|
|
30
|
-
CONSTRAINT `carbon_subscription_carbon_carbons_entity_pk_fk` FOREIGN KEY (`subscription_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
31
|
-
CONSTRAINT `carbon_subscription_carbon_carbons_entity_pk_fk2` FOREIGN KEY (`subscription_to_entity_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
32
|
-
CONSTRAINT `carbon_subscription_carbon_carbons_entity_pk_fk3` FOREIGN KEY (`subscription_for_entity_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
33
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
34
|
-
**/
|
|
35
|
-
|
|
36
|
-
type GetCustomAndRequiredFields = {}
|
|
37
|
-
|
|
38
|
-
type GetRequestTableOverrides = {}
|
|
39
|
-
|
|
40
|
-
// required parameters, optional parameters, parameter type overrides, response, and table names
|
|
41
|
-
export const Get = restRequest<GetCustomAndRequiredFields, iSubscription, GetRequestTableOverrides, iGetC6RestResponse<iSubscription>, RestTableNames>({
|
|
42
|
-
C6: C6,
|
|
43
|
-
tableName: subscription.TABLE_NAME,
|
|
44
|
-
requestMethod: GET,
|
|
45
|
-
queryCallback: (request) => {
|
|
46
|
-
request.success ??= 'Successfully received subscription!'
|
|
47
|
-
request.error ??= 'An unknown issue occurred creating the subscription!'
|
|
48
|
-
return request
|
|
49
|
-
},
|
|
50
|
-
responseCallback: (response, _request) => {
|
|
51
|
-
updateRestfulObjectArrays<iSubscription>(response?.data?.rest, "subscription", C6.subscription.PRIMARY_SHORT as (keyof iSubscription)[])
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
type PutCustomAndRequiredFields = {}
|
|
56
|
-
|
|
57
|
-
type PutRequestTableOverrides = {}
|
|
58
|
-
|
|
59
|
-
export function putStateSubscription(response : AxiosResponse<iPutC6RestResponse<iSubscription>>, request : iAPI<Modify<iSubscription, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
|
|
60
|
-
updateRestfulObjectArrays<iSubscription>([
|
|
61
|
-
removeInvalidKeys<iSubscription>({
|
|
62
|
-
...request,
|
|
63
|
-
...response?.data?.rest,
|
|
64
|
-
}, C6.TABLES)
|
|
65
|
-
], "subscription", subscription.PRIMARY_SHORT as (keyof iSubscription)[])
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const Put = restRequest<PutCustomAndRequiredFields, iSubscription, PutRequestTableOverrides, iPutC6RestResponse<iSubscription>, RestTableNames>({
|
|
69
|
-
C6: C6,
|
|
70
|
-
tableName: subscription.TABLE_NAME,
|
|
71
|
-
requestMethod: PUT,
|
|
72
|
-
queryCallback: (request) => {
|
|
73
|
-
request.success ??= 'Successfully updated subscription data!'
|
|
74
|
-
request.error ??= 'An unknown issue occurred updating the subscription data!'
|
|
75
|
-
return request
|
|
76
|
-
},
|
|
77
|
-
responseCallback: putStateSubscription
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
type PostCustomAndRequiredFields = {}
|
|
81
|
-
|
|
82
|
-
type PostRequestTableOverrides = {}
|
|
83
|
-
|
|
84
|
-
export function postStateSubscription(response : AxiosResponse<iPostC6RestResponse<iSubscription>>, request : iAPI<Modify<iSubscription, PostRequestTableOverrides>> & PostCustomAndRequiredFields, id: string | number | boolean) {
|
|
85
|
-
if ('number' === typeof id || 'string' === typeof id) {
|
|
86
|
-
if (1 !== subscription.PRIMARY_SHORT.length) {
|
|
87
|
-
console.error("C6 received unexpected result's given the primary key length");
|
|
88
|
-
} else {
|
|
89
|
-
request[subscription.PRIMARY_SHORT[0]] = id
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
updateRestfulObjectArrays<iSubscription>(
|
|
93
|
-
undefined !== request.dataInsertMultipleRows
|
|
94
|
-
? request.dataInsertMultipleRows.map((request, index) => {
|
|
95
|
-
return removeInvalidKeys<iSubscription>({
|
|
96
|
-
...request,
|
|
97
|
-
...(index === 0 ? response?.data?.rest : {}),
|
|
98
|
-
}, C6.TABLES)
|
|
99
|
-
})
|
|
100
|
-
: [
|
|
101
|
-
removeInvalidKeys<iSubscription>({
|
|
102
|
-
...request,
|
|
103
|
-
...response?.data?.rest,
|
|
104
|
-
}, C6.TABLES)
|
|
105
|
-
],
|
|
106
|
-
"subscription",
|
|
107
|
-
subscription.PRIMARY_SHORT as (keyof iSubscription)[]
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export const Post = restRequest<PostCustomAndRequiredFields, iSubscription, PostRequestTableOverrides, iPostC6RestResponse<iSubscription>, RestTableNames>({
|
|
112
|
-
C6: C6,
|
|
113
|
-
tableName: subscription.TABLE_NAME,
|
|
114
|
-
requestMethod: POST,
|
|
115
|
-
queryCallback: (request) => {
|
|
116
|
-
request.success ??= 'Successfully created the subscription data!'
|
|
117
|
-
request.error ??= 'An unknown issue occurred creating the subscription data!'
|
|
118
|
-
return request
|
|
119
|
-
},
|
|
120
|
-
responseCallback: postStateSubscription
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
type DeleteCustomAndRequiredFields = {}
|
|
124
|
-
|
|
125
|
-
type DeleteRequestTableOverrides = {}
|
|
126
|
-
|
|
127
|
-
export function deleteStateSubscription(_response : AxiosResponse<iDeleteC6RestResponse<iSubscription>>, request : iAPI<Modify<iSubscription, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
|
|
128
|
-
deleteRestfulObjectArrays<iSubscription>([
|
|
129
|
-
request
|
|
130
|
-
], "subscription", subscription.PRIMARY_SHORT as (keyof iSubscription)[])
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export const Delete = restRequest<DeleteCustomAndRequiredFields, iSubscription, DeleteRequestTableOverrides, iDeleteC6RestResponse<iSubscription>, RestTableNames>({
|
|
134
|
-
C6: C6,
|
|
135
|
-
tableName: subscription.TABLE_NAME,
|
|
136
|
-
requestMethod: DELETE,
|
|
137
|
-
queryCallback: (request) => {
|
|
138
|
-
request.success ??= 'Successfully removed the subscription data!'
|
|
139
|
-
request.error ??= 'An unknown issue occurred removing the subscription data!'
|
|
140
|
-
return request
|
|
141
|
-
},
|
|
142
|
-
responseCallback: deleteStateSubscription
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
export default {
|
|
146
|
-
// Export all GET, POST, PUT, DELETE functions for each table
|
|
147
|
-
Get,
|
|
148
|
-
Post,
|
|
149
|
-
Put,
|
|
150
|
-
Delete,
|
|
151
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
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_Followers, user_followers } from "api/rest/C6";
|
|
6
|
-
import User_Followers from "./User_Followers";
|
|
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_followers` (
|
|
14
|
-
`follower_table_id` binary(16) NOT NULL,
|
|
15
|
-
`follows_user_id` binary(16) NOT NULL,
|
|
16
|
-
`user_id` binary(16) NOT NULL,
|
|
17
|
-
PRIMARY KEY (`follower_table_id`),
|
|
18
|
-
KEY `followers_entity_entity_pk_fk` (`follows_user_id`),
|
|
19
|
-
KEY `followers_entity_entity_followers_pk_fk` (`user_id`),
|
|
20
|
-
CONSTRAINT `carbon_user_followers_carbons_entity_pk_fk` FOREIGN KEY (`follower_table_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
21
|
-
CONSTRAINT `followers_entity_entity_follows_pk_fk` FOREIGN KEY (`follows_user_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
22
|
-
CONSTRAINT `followers_entity_followers_pk_fk` FOREIGN KEY (`user_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
23
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
24
|
-
**/
|
|
25
|
-
|
|
26
|
-
const Test_Data: iUser_Followers = {
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default Test_Data;
|
|
31
|
-
|
|
32
|
-
xdescribe('REST User_Followers api', () => {
|
|
33
|
-
|
|
34
|
-
let testData = Test_Data;
|
|
35
|
-
|
|
36
|
-
test('GET POST PUT DELETE', async () => {
|
|
37
|
-
|
|
38
|
-
await act(async () => {
|
|
39
|
-
|
|
40
|
-
let selectAllResponse = await User_Followers.Get({})
|
|
41
|
-
|
|
42
|
-
if ('function' === typeof selectAllResponse) {
|
|
43
|
-
throw Error('selectAllResponse is a promise, this typically means this specific get request has already run during test setup.');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// We don't care if it is filled or not, just that the request can be made.
|
|
47
|
-
expect(selectAllResponse?.data?.rest).not.toBeUndefined();
|
|
48
|
-
|
|
49
|
-
const postResponse = await User_Followers.Post(testData);
|
|
50
|
-
|
|
51
|
-
console.log('postResponse', postResponse?.data)
|
|
52
|
-
|
|
53
|
-
expect(postResponse?.data?.created).not.toBeUndefined();
|
|
54
|
-
|
|
55
|
-
const primaryKey = user_followers.PRIMARY_SHORT[0];
|
|
56
|
-
|
|
57
|
-
const postID = postResponse?.data?.created
|
|
58
|
-
|
|
59
|
-
const singleRowSelect = await User_Followers.Get({
|
|
60
|
-
[C6.WHERE]: {
|
|
61
|
-
[user_followers[primaryKey.toUpperCase()]]: postID,
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
if ('function' === typeof singleRowSelect) {
|
|
66
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
console.log('singleRowSelect', singleRowSelect?.data)
|
|
70
|
-
|
|
71
|
-
// Ensure the expected response datastructure is returned
|
|
72
|
-
expect(singleRowSelect?.data?.rest).not.toBeUndefined();
|
|
73
|
-
|
|
74
|
-
// Make sure the previously created post is now returned
|
|
75
|
-
expect(typeof singleRowSelect?.data?.rest).toEqual('object');
|
|
76
|
-
|
|
77
|
-
// todo - make this work correctly with multiple primary keys
|
|
78
|
-
const selectedPostId = singleRowSelect?.data?.rest[0][primaryKey]
|
|
79
|
-
|
|
80
|
-
expect(selectedPostId).toEqual(postID);
|
|
81
|
-
|
|
82
|
-
const multipleRowSelect = await User_Followers.Get({
|
|
83
|
-
[C6.WHERE]: {
|
|
84
|
-
[user_followers[primaryKey.toUpperCase()]]: [C6.IN, [0, postID]],
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
if ('function' === typeof multipleRowSelect) {
|
|
89
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
console.log('singleRowSelect', multipleRowSelect?.data)
|
|
93
|
-
|
|
94
|
-
// Ensure the expected response datastructure is returned
|
|
95
|
-
expect(multipleRowSelect?.data?.rest).not.toBeUndefined();
|
|
96
|
-
|
|
97
|
-
// Make sure the previously created post is now returned
|
|
98
|
-
expect(typeof multipleRowSelect?.data?.rest).toEqual('object');
|
|
99
|
-
|
|
100
|
-
testData[primaryKey] = postID
|
|
101
|
-
|
|
102
|
-
testData.follower_table_id = fillString.substring(0, 16);
|
|
103
|
-
testData.follows_user_id = fillString.substring(0, 16);
|
|
104
|
-
testData.user_id = fillString.substring(0, 16);
|
|
105
|
-
|
|
106
|
-
// wait for the global state to be updated
|
|
107
|
-
expect(CarbonReact.getState<iRestfulObjectArrayTypes>().user_followers).not.toBeUndefined();
|
|
108
|
-
|
|
109
|
-
const updateResponse = await User_Followers.Put(testData)
|
|
110
|
-
|
|
111
|
-
expect(updateResponse?.data?.updated).not.toBeUndefined();
|
|
112
|
-
|
|
113
|
-
const deleteResponse = await User_Followers.Delete({
|
|
114
|
-
[primaryKey]: postID
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
console.log('deleteResponse', deleteResponse?.data)
|
|
118
|
-
|
|
119
|
-
expect(deleteResponse?.data?.deleted).not.toBeUndefined();
|
|
120
|
-
|
|
121
|
-
await waitFor(async () => {
|
|
122
|
-
expect(checkAllRequestsComplete()).toEqual(true);
|
|
123
|
-
}, {timeout: 10000, interval: 1000});
|
|
124
|
-
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
}, 100000);
|
|
128
|
-
|
|
129
|
-
})
|
|
130
|
-
|
|
@@ -1,147 +0,0 @@
|
|
|
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_Followers, user_followers, RestTableNames} from "./C6";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
CREATE TABLE `carbon_user_followers` (
|
|
20
|
-
`follower_table_id` binary(16) NOT NULL,
|
|
21
|
-
`follows_user_id` binary(16) NOT NULL,
|
|
22
|
-
`user_id` binary(16) NOT NULL,
|
|
23
|
-
PRIMARY KEY (`follower_table_id`),
|
|
24
|
-
KEY `followers_entity_entity_pk_fk` (`follows_user_id`),
|
|
25
|
-
KEY `followers_entity_entity_followers_pk_fk` (`user_id`),
|
|
26
|
-
CONSTRAINT `carbon_user_followers_carbons_entity_pk_fk` FOREIGN KEY (`follower_table_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
27
|
-
CONSTRAINT `followers_entity_entity_follows_pk_fk` FOREIGN KEY (`follows_user_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
28
|
-
CONSTRAINT `followers_entity_followers_pk_fk` FOREIGN KEY (`user_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
|
-
type GetCustomAndRequiredFields = {}
|
|
33
|
-
|
|
34
|
-
type GetRequestTableOverrides = {}
|
|
35
|
-
|
|
36
|
-
// required parameters, optional parameters, parameter type overrides, response, and table names
|
|
37
|
-
export const Get = restRequest<GetCustomAndRequiredFields, iUser_Followers, GetRequestTableOverrides, iGetC6RestResponse<iUser_Followers>, RestTableNames>({
|
|
38
|
-
C6: C6,
|
|
39
|
-
tableName: user_followers.TABLE_NAME,
|
|
40
|
-
requestMethod: GET,
|
|
41
|
-
queryCallback: (request) => {
|
|
42
|
-
request.success ??= 'Successfully received user_followers!'
|
|
43
|
-
request.error ??= 'An unknown issue occurred creating the user_followers!'
|
|
44
|
-
return request
|
|
45
|
-
},
|
|
46
|
-
responseCallback: (response, _request) => {
|
|
47
|
-
updateRestfulObjectArrays<iUser_Followers>(response?.data?.rest, "user_followers", C6.user_followers.PRIMARY_SHORT as (keyof iUser_Followers)[])
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
type PutCustomAndRequiredFields = {}
|
|
52
|
-
|
|
53
|
-
type PutRequestTableOverrides = {}
|
|
54
|
-
|
|
55
|
-
export function putStateUser_Followers(response : AxiosResponse<iPutC6RestResponse<iUser_Followers>>, request : iAPI<Modify<iUser_Followers, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
|
|
56
|
-
updateRestfulObjectArrays<iUser_Followers>([
|
|
57
|
-
removeInvalidKeys<iUser_Followers>({
|
|
58
|
-
...request,
|
|
59
|
-
...response?.data?.rest,
|
|
60
|
-
}, C6.TABLES)
|
|
61
|
-
], "user_followers", user_followers.PRIMARY_SHORT as (keyof iUser_Followers)[])
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const Put = restRequest<PutCustomAndRequiredFields, iUser_Followers, PutRequestTableOverrides, iPutC6RestResponse<iUser_Followers>, RestTableNames>({
|
|
65
|
-
C6: C6,
|
|
66
|
-
tableName: user_followers.TABLE_NAME,
|
|
67
|
-
requestMethod: PUT,
|
|
68
|
-
queryCallback: (request) => {
|
|
69
|
-
request.success ??= 'Successfully updated user_followers data!'
|
|
70
|
-
request.error ??= 'An unknown issue occurred updating the user_followers data!'
|
|
71
|
-
return request
|
|
72
|
-
},
|
|
73
|
-
responseCallback: putStateUser_Followers
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
type PostCustomAndRequiredFields = {}
|
|
77
|
-
|
|
78
|
-
type PostRequestTableOverrides = {}
|
|
79
|
-
|
|
80
|
-
export function postStateUser_Followers(response : AxiosResponse<iPostC6RestResponse<iUser_Followers>>, request : iAPI<Modify<iUser_Followers, PostRequestTableOverrides>> & PostCustomAndRequiredFields, id: string | number | boolean) {
|
|
81
|
-
if ('number' === typeof id || 'string' === typeof id) {
|
|
82
|
-
if (1 !== user_followers.PRIMARY_SHORT.length) {
|
|
83
|
-
console.error("C6 received unexpected result's given the primary key length");
|
|
84
|
-
} else {
|
|
85
|
-
request[user_followers.PRIMARY_SHORT[0]] = id
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
updateRestfulObjectArrays<iUser_Followers>(
|
|
89
|
-
undefined !== request.dataInsertMultipleRows
|
|
90
|
-
? request.dataInsertMultipleRows.map((request, index) => {
|
|
91
|
-
return removeInvalidKeys<iUser_Followers>({
|
|
92
|
-
...request,
|
|
93
|
-
...(index === 0 ? response?.data?.rest : {}),
|
|
94
|
-
}, C6.TABLES)
|
|
95
|
-
})
|
|
96
|
-
: [
|
|
97
|
-
removeInvalidKeys<iUser_Followers>({
|
|
98
|
-
...request,
|
|
99
|
-
...response?.data?.rest,
|
|
100
|
-
}, C6.TABLES)
|
|
101
|
-
],
|
|
102
|
-
"user_followers",
|
|
103
|
-
user_followers.PRIMARY_SHORT as (keyof iUser_Followers)[]
|
|
104
|
-
)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export const Post = restRequest<PostCustomAndRequiredFields, iUser_Followers, PostRequestTableOverrides, iPostC6RestResponse<iUser_Followers>, RestTableNames>({
|
|
108
|
-
C6: C6,
|
|
109
|
-
tableName: user_followers.TABLE_NAME,
|
|
110
|
-
requestMethod: POST,
|
|
111
|
-
queryCallback: (request) => {
|
|
112
|
-
request.success ??= 'Successfully created the user_followers data!'
|
|
113
|
-
request.error ??= 'An unknown issue occurred creating the user_followers data!'
|
|
114
|
-
return request
|
|
115
|
-
},
|
|
116
|
-
responseCallback: postStateUser_Followers
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
type DeleteCustomAndRequiredFields = {}
|
|
120
|
-
|
|
121
|
-
type DeleteRequestTableOverrides = {}
|
|
122
|
-
|
|
123
|
-
export function deleteStateUser_Followers(_response : AxiosResponse<iDeleteC6RestResponse<iUser_Followers>>, request : iAPI<Modify<iUser_Followers, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
|
|
124
|
-
deleteRestfulObjectArrays<iUser_Followers>([
|
|
125
|
-
request
|
|
126
|
-
], "user_followers", user_followers.PRIMARY_SHORT as (keyof iUser_Followers)[])
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export const Delete = restRequest<DeleteCustomAndRequiredFields, iUser_Followers, DeleteRequestTableOverrides, iDeleteC6RestResponse<iUser_Followers>, RestTableNames>({
|
|
130
|
-
C6: C6,
|
|
131
|
-
tableName: user_followers.TABLE_NAME,
|
|
132
|
-
requestMethod: DELETE,
|
|
133
|
-
queryCallback: (request) => {
|
|
134
|
-
request.success ??= 'Successfully removed the user_followers data!'
|
|
135
|
-
request.error ??= 'An unknown issue occurred removing the user_followers data!'
|
|
136
|
-
return request
|
|
137
|
-
},
|
|
138
|
-
responseCallback: deleteStateUser_Followers
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
export default {
|
|
142
|
-
// Export all GET, POST, PUT, DELETE functions for each table
|
|
143
|
-
Get,
|
|
144
|
-
Post,
|
|
145
|
-
Put,
|
|
146
|
-
Delete,
|
|
147
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
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_Groups, user_groups } from "api/rest/C6";
|
|
6
|
-
import User_Groups from "./User_Groups";
|
|
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_groups` (
|
|
14
|
-
`group_id` binary(16) DEFAULT NULL,
|
|
15
|
-
`user_id` binary(16) DEFAULT NULL,
|
|
16
|
-
KEY `carbon_user_groups_carbons_entity_pk_fk` (`group_id`),
|
|
17
|
-
KEY `carbon_user_groups_carbons_entity_pk_fk_2` (`user_id`),
|
|
18
|
-
CONSTRAINT `carbon_user_groups_carbons_entity_pk_fk` FOREIGN KEY (`group_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
19
|
-
CONSTRAINT `carbon_user_groups_carbons_entity_pk_fk_2` FOREIGN KEY (`user_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
20
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
21
|
-
**/
|
|
22
|
-
|
|
23
|
-
const Test_Data: iUser_Groups = {
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default Test_Data;
|
|
28
|
-
|
|
29
|
-
xdescribe('REST User_Groups api', () => {
|
|
30
|
-
|
|
31
|
-
let testData = Test_Data;
|
|
32
|
-
|
|
33
|
-
test('GET POST PUT DELETE', async () => {
|
|
34
|
-
|
|
35
|
-
await act(async () => {
|
|
36
|
-
|
|
37
|
-
let selectAllResponse = await User_Groups.Get({})
|
|
38
|
-
|
|
39
|
-
if ('function' === typeof selectAllResponse) {
|
|
40
|
-
throw Error('selectAllResponse is a promise, this typically means this specific get request has already run during test setup.');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// We don't care if it is filled or not, just that the request can be made.
|
|
44
|
-
expect(selectAllResponse?.data?.rest).not.toBeUndefined();
|
|
45
|
-
|
|
46
|
-
const postResponse = await User_Groups.Post(testData);
|
|
47
|
-
|
|
48
|
-
console.log('postResponse', postResponse?.data)
|
|
49
|
-
|
|
50
|
-
expect(postResponse?.data?.created).not.toBeUndefined();
|
|
51
|
-
|
|
52
|
-
const primaryKey = user_groups.PRIMARY_SHORT[0];
|
|
53
|
-
|
|
54
|
-
const postID = postResponse?.data?.created
|
|
55
|
-
|
|
56
|
-
const singleRowSelect = await User_Groups.Get({
|
|
57
|
-
[C6.WHERE]: {
|
|
58
|
-
[user_groups[primaryKey.toUpperCase()]]: postID,
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
if ('function' === typeof singleRowSelect) {
|
|
63
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.log('singleRowSelect', singleRowSelect?.data)
|
|
67
|
-
|
|
68
|
-
// Ensure the expected response datastructure is returned
|
|
69
|
-
expect(singleRowSelect?.data?.rest).not.toBeUndefined();
|
|
70
|
-
|
|
71
|
-
// Make sure the previously created post is now returned
|
|
72
|
-
expect(typeof singleRowSelect?.data?.rest).toEqual('object');
|
|
73
|
-
|
|
74
|
-
// todo - make this work correctly with multiple primary keys
|
|
75
|
-
const selectedPostId = singleRowSelect?.data?.rest[0][primaryKey]
|
|
76
|
-
|
|
77
|
-
expect(selectedPostId).toEqual(postID);
|
|
78
|
-
|
|
79
|
-
const multipleRowSelect = await User_Groups.Get({
|
|
80
|
-
[C6.WHERE]: {
|
|
81
|
-
[user_groups[primaryKey.toUpperCase()]]: [C6.IN, [0, postID]],
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
if ('function' === typeof multipleRowSelect) {
|
|
86
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
console.log('singleRowSelect', multipleRowSelect?.data)
|
|
90
|
-
|
|
91
|
-
// Ensure the expected response datastructure is returned
|
|
92
|
-
expect(multipleRowSelect?.data?.rest).not.toBeUndefined();
|
|
93
|
-
|
|
94
|
-
// Make sure the previously created post is now returned
|
|
95
|
-
expect(typeof multipleRowSelect?.data?.rest).toEqual('object');
|
|
96
|
-
|
|
97
|
-
testData[primaryKey] = postID
|
|
98
|
-
|
|
99
|
-
testData.group_id = fillString.substring(0, 16);
|
|
100
|
-
testData.user_id = fillString.substring(0, 16);
|
|
101
|
-
|
|
102
|
-
// wait for the global state to be updated
|
|
103
|
-
expect(CarbonReact.getState<iRestfulObjectArrayTypes>().user_groups).not.toBeUndefined();
|
|
104
|
-
|
|
105
|
-
const updateResponse = await User_Groups.Put(testData)
|
|
106
|
-
|
|
107
|
-
expect(updateResponse?.data?.updated).not.toBeUndefined();
|
|
108
|
-
|
|
109
|
-
const deleteResponse = await User_Groups.Delete({
|
|
110
|
-
[primaryKey]: postID
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
console.log('deleteResponse', deleteResponse?.data)
|
|
114
|
-
|
|
115
|
-
expect(deleteResponse?.data?.deleted).not.toBeUndefined();
|
|
116
|
-
|
|
117
|
-
await waitFor(async () => {
|
|
118
|
-
expect(checkAllRequestsComplete()).toEqual(true);
|
|
119
|
-
}, {timeout: 10000, interval: 1000});
|
|
120
|
-
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
}, 100000);
|
|
124
|
-
|
|
125
|
-
})
|
|
126
|
-
|