@thzero/library_client_vue3_store_pinia 0.18.39 → 0.19.2

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.
@@ -1,63 +1,67 @@
1
- import LibraryClientConstants from '@thzero/library_client/constants';
2
-
3
- import LibraryClientUtility from '@thzero/library_client/utility/index';
4
- import LibraryCommonUtility from '@thzero/library_common/utility';
5
-
6
- import Response from '@thzero/library_common/response';
7
-
8
- const store = {
9
- state: {
10
- users: null
11
- },
12
- actions: {
13
- async deleteAdminUser(correlationId, id) {
14
- const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_ADMIN_USERS);
15
- const response = await service.delete(correlationId, id);
16
- this.$logger.debug('store.admin.users', 'deleteAdminUser', 'response', response);
17
- if (Response.hasSucceeded(response)) {
18
- commit('deleteAdminUser', { correlationId: correlationId, id: id });
19
- this.users = LibraryCommonUtility.deleteArrayById(this.users, id);
20
- LibraryClientUtility.$store.dispatcher.users.delete(correlationId, id);
21
- }
22
- return response;
23
- },
24
- async searchAdminUsers(correlationId, params) {
25
- const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_ADMIN_USERS);
26
- const response = await service.search(correlationId, params);
27
- this.$logger.debug('store.admin.users', 'searchAdminUsers', 'response', response);
28
- if (Response.hasSucceeded(response)) {
29
- const list = response.success && response.results ? response.results.data : null;
30
- this.$logger.debug('store.admin.users', 'setAdminUsersListing', 'list.a', list, correlationId);
31
- this.$logger.debug('store.admin.users', 'setAdminUsersListing', 'list.b', this.users, correlationId);
32
- this.users = list;
33
- this.$logger.debug('store.admin.users', 'setAdminUsersListing', 'list.c', this.users, correlationId);
34
- }
35
- },
36
- async updateAdminUser(correlationId, item) {
37
- const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_ADMIN_USERS);
38
- const response = await service.update(correlationId, item);
39
- this.$logger.debug('store.admin.users', 'updateAdminUser', 'response', response);
40
- if (Response.hasSucceeded(response)) {
41
- const item = response.results;
42
- this.$logger.debug('store.admin.users', 'setAdminUsers', 'items.a', item, correlationId);
43
- this.$logger.debug('store.admin.users', 'setAdminUsers', 'items.b', this.users, correlationId);
44
- this.users = LibraryCommonUtility.updateArrayById(this.users, item);
45
- this.$logger.debug('store.admin.users', 'setAdminUsers', 'items.c', this.users, correlationId);
46
- }
47
- return response;
48
- }
49
- },
50
- dispatcher: {
51
- async deleteAdminUser(correlationId, id) {
52
- return await LibraryClientUtility.$store.deleteAdminUser(correlationId, id);
53
- },
54
- async searchAdminUsers(correlationId, params) {
55
- await LibraryClientUtility.$store.searchAdminUsers(correlationId, params);
56
- },
57
- async updateAdminUser(correlationId, item) {
58
- return await LibraryClientUtility.$store.updateAdminUser(correlationId, item);
59
- }
60
- }
61
- };
62
-
63
- export default store;
1
+ import LibraryClientConstants from '@thzero/library_client/constants';
2
+
3
+ import LibraryClientUtility from '@thzero/library_client/utility/index';
4
+ import LibraryCommonUtility from '@thzero/library_common/utility';
5
+
6
+ import Response from '@thzero/library_common/response';
7
+
8
+ // An optional module: an app registers it from its store's _initModules as
9
+ // addModule('adminUsers', adminUsers)
10
+ // The dispatchers below and the admin components both expect that key.
11
+ const store = {
12
+ state: () => ({
13
+ users: null
14
+ }),
15
+ actions: {
16
+ async deleteAdminUser(correlationId, id) {
17
+ const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_ADMIN_USERS);
18
+ const response = await service.delete(correlationId, id);
19
+ this.$logger.debug('store.admin.users', 'deleteAdminUser', 'response', response, correlationId);
20
+ // deleteArrayById removes in place and returns nothing; assigning its
21
+ // result is what emptied the list
22
+ if (Response.hasSucceeded(response))
23
+ LibraryCommonUtility.deleteArrayById(this.users, id);
24
+ return response;
25
+ },
26
+ async searchAdminUsers(correlationId, params) {
27
+ const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_ADMIN_USERS);
28
+ const response = await service.search(correlationId, params);
29
+ this.$logger.debug('store.admin.users', 'searchAdminUsers', 'response', response, correlationId);
30
+ if (Response.hasSucceeded(response)) {
31
+ const list = response.success && response.results ? response.results.data : null;
32
+ this.$logger.debug('store.admin.users', 'searchAdminUsers', 'list.a', list, correlationId);
33
+ this.$logger.debug('store.admin.users', 'searchAdminUsers', 'list.b', this.users, correlationId);
34
+ this.users = list;
35
+ this.$logger.debug('store.admin.users', 'searchAdminUsers', 'list.c', this.users, correlationId);
36
+ }
37
+ },
38
+ async updateAdminUser(correlationId, item) {
39
+ const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_ADMIN_USERS);
40
+ const response = await service.update(correlationId, item);
41
+ this.$logger.debug('store.admin.users', 'updateAdminUser', 'response', response, correlationId);
42
+ if (Response.hasSucceeded(response) && response.results) {
43
+ this.$logger.debug('store.admin.users', 'updateAdminUser', 'items.a', response.results, correlationId);
44
+ this.$logger.debug('store.admin.users', 'updateAdminUser', 'items.b', this.users, correlationId);
45
+ // updateArrayById takes (array, id, object); called with two arguments
46
+ // it put the item in the id slot and appended undefined
47
+ this.users = LibraryCommonUtility.updateArrayByObject(this.users ?? [], response.results);
48
+ this.$logger.debug('store.admin.users', 'updateAdminUser', 'items.c', this.users, correlationId);
49
+ }
50
+ return response;
51
+ }
52
+ },
53
+ // module actions live on $store.adminUsers, not on the root $store
54
+ dispatcher: {
55
+ async deleteAdminUser(correlationId, id) {
56
+ return await LibraryClientUtility.$store.adminUsers.deleteAdminUser(correlationId, id);
57
+ },
58
+ async searchAdminUsers(correlationId, params) {
59
+ await LibraryClientUtility.$store.adminUsers.searchAdminUsers(correlationId, params);
60
+ },
61
+ async updateAdminUser(correlationId, item) {
62
+ return await LibraryClientUtility.$store.adminUsers.updateAdminUser(correlationId, item);
63
+ }
64
+ }
65
+ };
66
+
67
+ export default store;