@htlkg/data 0.0.21 → 0.0.22
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/hooks/index.d.ts +601 -94
- package/dist/hooks/index.js +682 -73
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +691 -82
- package/dist/index.js.map +1 -1
- package/dist/mutations/index.js +4 -4
- package/dist/mutations/index.js.map +1 -1
- package/dist/queries/index.js +5 -5
- package/dist/queries/index.js.map +1 -1
- package/package.json +11 -12
- package/src/hooks/accounts/index.ts +2 -0
- package/src/hooks/{useAccounts.ts → accounts/useAccounts.ts} +48 -5
- package/src/hooks/accounts/usePaginatedAccounts.ts +166 -0
- package/src/hooks/brands/index.ts +2 -0
- package/src/hooks/{useBrands.ts → brands/useBrands.ts} +1 -1
- package/src/hooks/brands/usePaginatedBrands.ts +206 -0
- package/src/hooks/createPaginatedDataHook.ts +359 -0
- package/src/hooks/data-hook-errors.property.test.ts +4 -4
- package/src/hooks/data-hook-filters.property.test.ts +4 -4
- package/src/hooks/data-hooks.property.test.ts +4 -4
- package/src/hooks/index.ts +96 -8
- package/src/hooks/productInstances/index.ts +1 -0
- package/src/hooks/{useProductInstances.ts → productInstances/useProductInstances.ts} +9 -6
- package/src/hooks/products/index.ts +1 -0
- package/src/hooks/{useProducts.ts → products/useProducts.ts} +4 -5
- package/src/hooks/reservations/index.ts +2 -0
- package/src/hooks/reservations/usePaginatedReservations.ts +258 -0
- package/src/hooks/{useReservations.ts → reservations/useReservations.ts} +65 -10
- package/src/hooks/users/index.ts +2 -0
- package/src/hooks/users/usePaginatedUsers.ts +213 -0
- package/src/hooks/{useUsers.ts → users/useUsers.ts} +1 -1
- package/src/mutations/accounts/accounts.test.ts +287 -0
- package/src/mutations/{accounts.ts → accounts/accounts.ts} +2 -2
- package/src/mutations/accounts/index.ts +1 -0
- package/src/mutations/brands/brands.test.ts +292 -0
- package/src/mutations/{brands.ts → brands/brands.ts} +2 -2
- package/src/mutations/brands/index.ts +1 -0
- package/src/mutations/reservations/index.ts +1 -0
- package/src/mutations/{reservations.test.ts → reservations/reservations.test.ts} +1 -1
- package/src/mutations/{reservations.ts → reservations/reservations.ts} +2 -2
- package/src/mutations/users/index.ts +1 -0
- package/src/mutations/users/users.test.ts +289 -0
- package/src/mutations/{users.ts → users/users.ts} +2 -2
- package/src/queries/accounts/accounts.test.ts +228 -0
- package/src/queries/accounts/index.ts +1 -0
- package/src/queries/brands/brands.test.ts +288 -0
- package/src/queries/brands/index.ts +1 -0
- package/src/queries/products/index.ts +1 -0
- package/src/queries/products/products.test.ts +347 -0
- package/src/queries/reservations/index.ts +1 -0
- package/src/queries/users/index.ts +1 -0
- package/src/queries/users/users.test.ts +301 -0
- /package/src/queries/{accounts.ts → accounts/accounts.ts} +0 -0
- /package/src/queries/{brands.ts → brands/brands.ts} +0 -0
- /package/src/queries/{products.ts → products/products.ts} +0 -0
- /package/src/queries/{reservations.test.ts → reservations/reservations.test.ts} +0 -0
- /package/src/queries/{reservations.ts → reservations/reservations.ts} +0 -0
- /package/src/queries/{users.ts → users/users.ts} +0 -0
package/dist/hooks/index.js
CHANGED
|
@@ -55,7 +55,7 @@ function createDataHook(config) {
|
|
|
55
55
|
defaultLimit,
|
|
56
56
|
selectionSet,
|
|
57
57
|
transform,
|
|
58
|
-
buildFilter:
|
|
58
|
+
buildFilter: buildFilter10,
|
|
59
59
|
computedProperties,
|
|
60
60
|
dataPropertyName = "data"
|
|
61
61
|
} = config;
|
|
@@ -65,8 +65,8 @@ function createDataHook(config) {
|
|
|
65
65
|
const loading = ref(false);
|
|
66
66
|
const error = ref(null);
|
|
67
67
|
const getFilter = () => {
|
|
68
|
-
if (
|
|
69
|
-
return
|
|
68
|
+
if (buildFilter10) {
|
|
69
|
+
return buildFilter10(options);
|
|
70
70
|
}
|
|
71
71
|
return baseFilter && Object.keys(baseFilter).length > 0 ? baseFilter : void 0;
|
|
72
72
|
};
|
|
@@ -126,7 +126,171 @@ function createDataHook(config) {
|
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
// src/hooks/
|
|
129
|
+
// src/hooks/createPaginatedDataHook.ts
|
|
130
|
+
import { ref as ref2, computed as computed2, onMounted as onMounted2 } from "vue";
|
|
131
|
+
var ACTIVE_FILTER = {
|
|
132
|
+
or: [{ deletedAt: { attributeExists: false } }, { deletedAt: { eq: null } }]
|
|
133
|
+
};
|
|
134
|
+
var DELETED_FILTER = {
|
|
135
|
+
deletedAt: { gt: "" }
|
|
136
|
+
};
|
|
137
|
+
function createPaginatedDataHook(config) {
|
|
138
|
+
const {
|
|
139
|
+
model,
|
|
140
|
+
defaultPageSize = 25,
|
|
141
|
+
selectionSet,
|
|
142
|
+
transform,
|
|
143
|
+
buildFilter: buildFilter10,
|
|
144
|
+
dataPropertyName = "data",
|
|
145
|
+
baseFilter
|
|
146
|
+
} = config;
|
|
147
|
+
return function usePaginatedData(options = {}) {
|
|
148
|
+
const { filter: additionalFilter, pageSize = defaultPageSize, autoFetch = true } = options;
|
|
149
|
+
const data = ref2([]);
|
|
150
|
+
const loading = ref2(false);
|
|
151
|
+
const initialLoading = ref2(false);
|
|
152
|
+
const loadingMore = ref2(false);
|
|
153
|
+
const error = ref2(null);
|
|
154
|
+
const pagination = ref2({
|
|
155
|
+
nextToken: null,
|
|
156
|
+
hasMore: true,
|
|
157
|
+
loadedCount: 0
|
|
158
|
+
});
|
|
159
|
+
const searchFilter = ref2(null);
|
|
160
|
+
const hasMore = computed2(() => pagination.value.hasMore);
|
|
161
|
+
const getFilter = () => {
|
|
162
|
+
const filters = [];
|
|
163
|
+
if (baseFilter) {
|
|
164
|
+
filters.push(baseFilter);
|
|
165
|
+
}
|
|
166
|
+
if (buildFilter10) {
|
|
167
|
+
const customFilter = buildFilter10(options);
|
|
168
|
+
if (customFilter) {
|
|
169
|
+
filters.push(customFilter);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (additionalFilter && Object.keys(additionalFilter).length > 0) {
|
|
173
|
+
filters.push(additionalFilter);
|
|
174
|
+
}
|
|
175
|
+
if (searchFilter.value && Object.keys(searchFilter.value).length > 0) {
|
|
176
|
+
filters.push(searchFilter.value);
|
|
177
|
+
}
|
|
178
|
+
if (filters.length === 0) {
|
|
179
|
+
return void 0;
|
|
180
|
+
}
|
|
181
|
+
if (filters.length === 1) {
|
|
182
|
+
return filters[0];
|
|
183
|
+
}
|
|
184
|
+
return { and: filters };
|
|
185
|
+
};
|
|
186
|
+
async function fetchPage(nextToken, append = false) {
|
|
187
|
+
if (!append) {
|
|
188
|
+
initialLoading.value = true;
|
|
189
|
+
} else {
|
|
190
|
+
loadingMore.value = true;
|
|
191
|
+
}
|
|
192
|
+
loading.value = true;
|
|
193
|
+
error.value = null;
|
|
194
|
+
try {
|
|
195
|
+
const queryOptions = {
|
|
196
|
+
limit: pageSize
|
|
197
|
+
};
|
|
198
|
+
const filter = getFilter();
|
|
199
|
+
if (filter) {
|
|
200
|
+
queryOptions.filter = filter;
|
|
201
|
+
}
|
|
202
|
+
if (nextToken) {
|
|
203
|
+
queryOptions.nextToken = nextToken;
|
|
204
|
+
}
|
|
205
|
+
if (selectionSet) {
|
|
206
|
+
queryOptions.selectionSet = selectionSet;
|
|
207
|
+
}
|
|
208
|
+
const response = await query(model, "list", queryOptions);
|
|
209
|
+
if (hasErrors(response)) {
|
|
210
|
+
throw new Error(getErrorMessage(response) || `Failed to fetch ${model}`);
|
|
211
|
+
}
|
|
212
|
+
const items = response.data || [];
|
|
213
|
+
const transformedItems = transform ? items.map(transform) : items;
|
|
214
|
+
if (append) {
|
|
215
|
+
data.value = [...data.value, ...transformedItems];
|
|
216
|
+
} else {
|
|
217
|
+
data.value = transformedItems;
|
|
218
|
+
}
|
|
219
|
+
const responseNextToken = response.nextToken;
|
|
220
|
+
pagination.value = {
|
|
221
|
+
nextToken: responseNextToken || null,
|
|
222
|
+
hasMore: !!responseNextToken,
|
|
223
|
+
loadedCount: data.value.length
|
|
224
|
+
};
|
|
225
|
+
} catch (e) {
|
|
226
|
+
error.value = e;
|
|
227
|
+
console.error(`[use${model}] Error fetching ${model}:`, e);
|
|
228
|
+
} finally {
|
|
229
|
+
loading.value = false;
|
|
230
|
+
initialLoading.value = false;
|
|
231
|
+
loadingMore.value = false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
async function loadMore() {
|
|
235
|
+
if (loadingMore.value || !pagination.value.hasMore) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
await fetchPage(pagination.value.nextToken, true);
|
|
239
|
+
}
|
|
240
|
+
async function refetch() {
|
|
241
|
+
pagination.value = {
|
|
242
|
+
nextToken: null,
|
|
243
|
+
hasMore: true,
|
|
244
|
+
loadedCount: 0
|
|
245
|
+
};
|
|
246
|
+
await fetchPage(null, false);
|
|
247
|
+
}
|
|
248
|
+
function reset() {
|
|
249
|
+
data.value = [];
|
|
250
|
+
error.value = null;
|
|
251
|
+
searchFilter.value = null;
|
|
252
|
+
pagination.value = {
|
|
253
|
+
nextToken: null,
|
|
254
|
+
hasMore: true,
|
|
255
|
+
loadedCount: 0
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
async function setSearchFilter(filter) {
|
|
259
|
+
searchFilter.value = filter;
|
|
260
|
+
pagination.value = {
|
|
261
|
+
nextToken: null,
|
|
262
|
+
hasMore: true,
|
|
263
|
+
loadedCount: 0
|
|
264
|
+
};
|
|
265
|
+
await fetchPage(null, false);
|
|
266
|
+
}
|
|
267
|
+
if (autoFetch) {
|
|
268
|
+
onMounted2(() => {
|
|
269
|
+
fetchPage(null, false);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
const result = {
|
|
273
|
+
data,
|
|
274
|
+
loading,
|
|
275
|
+
initialLoading,
|
|
276
|
+
loadingMore,
|
|
277
|
+
error,
|
|
278
|
+
pagination,
|
|
279
|
+
hasMore,
|
|
280
|
+
loadMore,
|
|
281
|
+
refetch,
|
|
282
|
+
reset,
|
|
283
|
+
setSearchFilter,
|
|
284
|
+
searchFilter
|
|
285
|
+
};
|
|
286
|
+
if (dataPropertyName !== "data") {
|
|
287
|
+
result[dataPropertyName] = data;
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/hooks/brands/useBrands.ts
|
|
130
294
|
function buildFilter(options) {
|
|
131
295
|
let filter = options.filter || {};
|
|
132
296
|
if (options.accountId) {
|
|
@@ -156,23 +320,96 @@ function useBrands(options = {}) {
|
|
|
156
320
|
};
|
|
157
321
|
}
|
|
158
322
|
|
|
159
|
-
// src/hooks/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
323
|
+
// src/hooks/brands/usePaginatedBrands.ts
|
|
324
|
+
function buildFilter2(options) {
|
|
325
|
+
const conditions = [];
|
|
326
|
+
if (options.accountId) {
|
|
327
|
+
conditions.push({ accountId: { eq: options.accountId } });
|
|
328
|
+
}
|
|
329
|
+
if (options.filter && Object.keys(options.filter).length > 0) {
|
|
330
|
+
conditions.push(options.filter);
|
|
331
|
+
}
|
|
332
|
+
if (conditions.length === 0) {
|
|
333
|
+
return void 0;
|
|
334
|
+
}
|
|
335
|
+
if (conditions.length === 1) {
|
|
336
|
+
return conditions[0];
|
|
337
|
+
}
|
|
338
|
+
return { and: conditions };
|
|
339
|
+
}
|
|
340
|
+
function transformBrand(brand) {
|
|
341
|
+
return {
|
|
342
|
+
...brand,
|
|
343
|
+
accountName: brand.account?.name || ""
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
var BRAND_SELECTION_SET = [
|
|
347
|
+
"id",
|
|
348
|
+
"name",
|
|
349
|
+
"accountId",
|
|
350
|
+
"logo",
|
|
351
|
+
"timezone",
|
|
352
|
+
"status",
|
|
353
|
+
"settings",
|
|
354
|
+
"deletedAt",
|
|
355
|
+
"deletedBy",
|
|
356
|
+
"account.name"
|
|
357
|
+
];
|
|
358
|
+
var useActiveBrandsInternal = createPaginatedDataHook({
|
|
359
|
+
model: "Brand",
|
|
360
|
+
dataPropertyName: "brands",
|
|
361
|
+
defaultPageSize: 25,
|
|
362
|
+
selectionSet: BRAND_SELECTION_SET,
|
|
363
|
+
transform: transformBrand,
|
|
364
|
+
buildFilter: buildFilter2,
|
|
365
|
+
baseFilter: ACTIVE_FILTER
|
|
163
366
|
});
|
|
164
|
-
|
|
165
|
-
|
|
367
|
+
var useDeletedBrandsInternal = createPaginatedDataHook({
|
|
368
|
+
model: "Brand",
|
|
369
|
+
dataPropertyName: "brands",
|
|
370
|
+
defaultPageSize: 25,
|
|
371
|
+
selectionSet: BRAND_SELECTION_SET,
|
|
372
|
+
transform: transformBrand,
|
|
373
|
+
buildFilter: buildFilter2,
|
|
374
|
+
baseFilter: DELETED_FILTER
|
|
375
|
+
});
|
|
376
|
+
function useActiveBrands(options = {}) {
|
|
377
|
+
const result = useActiveBrandsInternal(options);
|
|
166
378
|
return {
|
|
167
|
-
|
|
379
|
+
brands: result.brands,
|
|
168
380
|
loading: result.loading,
|
|
381
|
+
initialLoading: result.initialLoading,
|
|
382
|
+
loadingMore: result.loadingMore,
|
|
169
383
|
error: result.error,
|
|
170
|
-
|
|
384
|
+
pagination: result.pagination,
|
|
385
|
+
hasMore: result.hasMore,
|
|
386
|
+
loadMore: result.loadMore,
|
|
387
|
+
refetch: result.refetch,
|
|
388
|
+
reset: result.reset,
|
|
389
|
+
setSearchFilter: result.setSearchFilter,
|
|
390
|
+
searchFilter: result.searchFilter
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function useDeletedBrands(options = {}) {
|
|
394
|
+
const result = useDeletedBrandsInternal(options);
|
|
395
|
+
return {
|
|
396
|
+
brands: result.brands,
|
|
397
|
+
loading: result.loading,
|
|
398
|
+
initialLoading: result.initialLoading,
|
|
399
|
+
loadingMore: result.loadingMore,
|
|
400
|
+
error: result.error,
|
|
401
|
+
pagination: result.pagination,
|
|
402
|
+
hasMore: result.hasMore,
|
|
403
|
+
loadMore: result.loadMore,
|
|
404
|
+
refetch: result.refetch,
|
|
405
|
+
reset: result.reset,
|
|
406
|
+
setSearchFilter: result.setSearchFilter,
|
|
407
|
+
searchFilter: result.searchFilter
|
|
171
408
|
};
|
|
172
409
|
}
|
|
173
410
|
|
|
174
|
-
// src/hooks/useUsers.ts
|
|
175
|
-
function
|
|
411
|
+
// src/hooks/users/useUsers.ts
|
|
412
|
+
function buildFilter3(options) {
|
|
176
413
|
let filter = options.filter || {};
|
|
177
414
|
if (options.brandId) {
|
|
178
415
|
filter = { ...filter, brandIds: { contains: options.brandId } };
|
|
@@ -185,7 +422,7 @@ function buildFilter2(options) {
|
|
|
185
422
|
var useUsersInternal = createDataHook({
|
|
186
423
|
model: "User",
|
|
187
424
|
dataPropertyName: "users",
|
|
188
|
-
buildFilter:
|
|
425
|
+
buildFilter: buildFilter3
|
|
189
426
|
});
|
|
190
427
|
function useUsers(options = {}) {
|
|
191
428
|
const result = useUsersInternal(options);
|
|
@@ -197,8 +434,419 @@ function useUsers(options = {}) {
|
|
|
197
434
|
};
|
|
198
435
|
}
|
|
199
436
|
|
|
200
|
-
// src/hooks/
|
|
201
|
-
function
|
|
437
|
+
// src/hooks/users/usePaginatedUsers.ts
|
|
438
|
+
function buildFilter4(options) {
|
|
439
|
+
const conditions = [];
|
|
440
|
+
if (options.brandId) {
|
|
441
|
+
conditions.push({ brandIds: { contains: options.brandId } });
|
|
442
|
+
}
|
|
443
|
+
if (options.accountId) {
|
|
444
|
+
conditions.push({ accountId: { eq: options.accountId } });
|
|
445
|
+
}
|
|
446
|
+
if (options.filter && Object.keys(options.filter).length > 0) {
|
|
447
|
+
conditions.push(options.filter);
|
|
448
|
+
}
|
|
449
|
+
if (conditions.length === 0) {
|
|
450
|
+
return void 0;
|
|
451
|
+
}
|
|
452
|
+
if (conditions.length === 1) {
|
|
453
|
+
return conditions[0];
|
|
454
|
+
}
|
|
455
|
+
return { and: conditions };
|
|
456
|
+
}
|
|
457
|
+
function transformUser(user) {
|
|
458
|
+
return {
|
|
459
|
+
...user,
|
|
460
|
+
accountName: user.account?.name || ""
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
var USER_SELECTION_SET = [
|
|
464
|
+
"id",
|
|
465
|
+
"email",
|
|
466
|
+
"accountId",
|
|
467
|
+
"brandIds",
|
|
468
|
+
"roles",
|
|
469
|
+
"status",
|
|
470
|
+
"lastLogin",
|
|
471
|
+
"createdAt",
|
|
472
|
+
"deletedAt",
|
|
473
|
+
"deletedBy",
|
|
474
|
+
"account.name"
|
|
475
|
+
];
|
|
476
|
+
var useActiveUsersInternal = createPaginatedDataHook({
|
|
477
|
+
model: "User",
|
|
478
|
+
dataPropertyName: "users",
|
|
479
|
+
defaultPageSize: 25,
|
|
480
|
+
selectionSet: USER_SELECTION_SET,
|
|
481
|
+
transform: transformUser,
|
|
482
|
+
buildFilter: buildFilter4,
|
|
483
|
+
baseFilter: ACTIVE_FILTER
|
|
484
|
+
});
|
|
485
|
+
var useDeletedUsersInternal = createPaginatedDataHook({
|
|
486
|
+
model: "User",
|
|
487
|
+
dataPropertyName: "users",
|
|
488
|
+
defaultPageSize: 25,
|
|
489
|
+
selectionSet: USER_SELECTION_SET,
|
|
490
|
+
transform: transformUser,
|
|
491
|
+
buildFilter: buildFilter4,
|
|
492
|
+
baseFilter: DELETED_FILTER
|
|
493
|
+
});
|
|
494
|
+
function useActiveUsers(options = {}) {
|
|
495
|
+
const result = useActiveUsersInternal(options);
|
|
496
|
+
return {
|
|
497
|
+
users: result.users,
|
|
498
|
+
loading: result.loading,
|
|
499
|
+
initialLoading: result.initialLoading,
|
|
500
|
+
loadingMore: result.loadingMore,
|
|
501
|
+
error: result.error,
|
|
502
|
+
pagination: result.pagination,
|
|
503
|
+
hasMore: result.hasMore,
|
|
504
|
+
loadMore: result.loadMore,
|
|
505
|
+
refetch: result.refetch,
|
|
506
|
+
reset: result.reset,
|
|
507
|
+
setSearchFilter: result.setSearchFilter,
|
|
508
|
+
searchFilter: result.searchFilter
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
function useDeletedUsers(options = {}) {
|
|
512
|
+
const result = useDeletedUsersInternal(options);
|
|
513
|
+
return {
|
|
514
|
+
users: result.users,
|
|
515
|
+
loading: result.loading,
|
|
516
|
+
initialLoading: result.initialLoading,
|
|
517
|
+
loadingMore: result.loadingMore,
|
|
518
|
+
error: result.error,
|
|
519
|
+
pagination: result.pagination,
|
|
520
|
+
hasMore: result.hasMore,
|
|
521
|
+
loadMore: result.loadMore,
|
|
522
|
+
refetch: result.refetch,
|
|
523
|
+
reset: result.reset,
|
|
524
|
+
setSearchFilter: result.setSearchFilter,
|
|
525
|
+
searchFilter: result.searchFilter
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// src/hooks/accounts/useAccounts.ts
|
|
530
|
+
function transformAccount(account) {
|
|
531
|
+
const brands = account.brands || [];
|
|
532
|
+
return {
|
|
533
|
+
...account,
|
|
534
|
+
brands,
|
|
535
|
+
brandCount: brands.length
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
var useAccountsInternal = createDataHook({
|
|
539
|
+
model: "Account",
|
|
540
|
+
dataPropertyName: "accounts",
|
|
541
|
+
// Include brands relationship for brand display
|
|
542
|
+
selectionSet: [
|
|
543
|
+
"id",
|
|
544
|
+
"name",
|
|
545
|
+
"logo",
|
|
546
|
+
"subscription",
|
|
547
|
+
"settings",
|
|
548
|
+
"status",
|
|
549
|
+
"deletedAt",
|
|
550
|
+
"deletedBy",
|
|
551
|
+
"brands.id",
|
|
552
|
+
"brands.name",
|
|
553
|
+
"brands.status"
|
|
554
|
+
],
|
|
555
|
+
transform: transformAccount
|
|
556
|
+
});
|
|
557
|
+
function useAccounts(options = {}) {
|
|
558
|
+
const result = useAccountsInternal(options);
|
|
559
|
+
return {
|
|
560
|
+
accounts: result.accounts,
|
|
561
|
+
loading: result.loading,
|
|
562
|
+
error: result.error,
|
|
563
|
+
refetch: result.refetch
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// src/hooks/accounts/usePaginatedAccounts.ts
|
|
568
|
+
function transformAccount2(account) {
|
|
569
|
+
const brands = account.brands || [];
|
|
570
|
+
return {
|
|
571
|
+
...account,
|
|
572
|
+
brands,
|
|
573
|
+
brandCount: brands.length
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
var ACCOUNT_SELECTION_SET = [
|
|
577
|
+
"id",
|
|
578
|
+
"name",
|
|
579
|
+
"logo",
|
|
580
|
+
"subscription",
|
|
581
|
+
"settings",
|
|
582
|
+
"status",
|
|
583
|
+
"deletedAt",
|
|
584
|
+
"deletedBy",
|
|
585
|
+
"brands.id",
|
|
586
|
+
"brands.name",
|
|
587
|
+
"brands.status"
|
|
588
|
+
];
|
|
589
|
+
var useActiveAccountsInternal = createPaginatedDataHook({
|
|
590
|
+
model: "Account",
|
|
591
|
+
dataPropertyName: "accounts",
|
|
592
|
+
defaultPageSize: 25,
|
|
593
|
+
selectionSet: ACCOUNT_SELECTION_SET,
|
|
594
|
+
transform: transformAccount2,
|
|
595
|
+
baseFilter: ACTIVE_FILTER
|
|
596
|
+
});
|
|
597
|
+
var useDeletedAccountsInternal = createPaginatedDataHook({
|
|
598
|
+
model: "Account",
|
|
599
|
+
dataPropertyName: "accounts",
|
|
600
|
+
defaultPageSize: 25,
|
|
601
|
+
selectionSet: ACCOUNT_SELECTION_SET,
|
|
602
|
+
transform: transformAccount2,
|
|
603
|
+
baseFilter: DELETED_FILTER
|
|
604
|
+
});
|
|
605
|
+
function useActiveAccounts(options = {}) {
|
|
606
|
+
const result = useActiveAccountsInternal(options);
|
|
607
|
+
return {
|
|
608
|
+
accounts: result.accounts,
|
|
609
|
+
loading: result.loading,
|
|
610
|
+
initialLoading: result.initialLoading,
|
|
611
|
+
loadingMore: result.loadingMore,
|
|
612
|
+
error: result.error,
|
|
613
|
+
pagination: result.pagination,
|
|
614
|
+
hasMore: result.hasMore,
|
|
615
|
+
loadMore: result.loadMore,
|
|
616
|
+
refetch: result.refetch,
|
|
617
|
+
reset: result.reset,
|
|
618
|
+
setSearchFilter: result.setSearchFilter,
|
|
619
|
+
searchFilter: result.searchFilter
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
function useDeletedAccounts(options = {}) {
|
|
623
|
+
const result = useDeletedAccountsInternal(options);
|
|
624
|
+
return {
|
|
625
|
+
accounts: result.accounts,
|
|
626
|
+
loading: result.loading,
|
|
627
|
+
initialLoading: result.initialLoading,
|
|
628
|
+
loadingMore: result.loadingMore,
|
|
629
|
+
error: result.error,
|
|
630
|
+
pagination: result.pagination,
|
|
631
|
+
hasMore: result.hasMore,
|
|
632
|
+
loadMore: result.loadMore,
|
|
633
|
+
refetch: result.refetch,
|
|
634
|
+
reset: result.reset,
|
|
635
|
+
setSearchFilter: result.setSearchFilter,
|
|
636
|
+
searchFilter: result.searchFilter
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// src/hooks/reservations/useReservations.ts
|
|
641
|
+
function buildFilter5(options) {
|
|
642
|
+
const conditions = [];
|
|
643
|
+
if (options.brandId) {
|
|
644
|
+
conditions.push({ brandId: { eq: options.brandId } });
|
|
645
|
+
}
|
|
646
|
+
if (options.status) {
|
|
647
|
+
conditions.push({ status: { eq: options.status } });
|
|
648
|
+
}
|
|
649
|
+
if (options.contactId) {
|
|
650
|
+
conditions.push({ visitId: { eq: options.contactId } });
|
|
651
|
+
}
|
|
652
|
+
if (options.startDate) {
|
|
653
|
+
conditions.push({ checkIn: { ge: options.startDate } });
|
|
654
|
+
}
|
|
655
|
+
if (options.endDate) {
|
|
656
|
+
conditions.push({ checkIn: { le: options.endDate } });
|
|
657
|
+
}
|
|
658
|
+
if (options.filter) {
|
|
659
|
+
conditions.push(options.filter);
|
|
660
|
+
}
|
|
661
|
+
if (conditions.length === 0) {
|
|
662
|
+
return void 0;
|
|
663
|
+
}
|
|
664
|
+
if (conditions.length === 1) {
|
|
665
|
+
return conditions[0];
|
|
666
|
+
}
|
|
667
|
+
return { and: conditions };
|
|
668
|
+
}
|
|
669
|
+
function transformReservation(r) {
|
|
670
|
+
let snapshot = r.visit?.snapshot;
|
|
671
|
+
if (typeof snapshot === "string") {
|
|
672
|
+
try {
|
|
673
|
+
snapshot = JSON.parse(snapshot);
|
|
674
|
+
} catch {
|
|
675
|
+
snapshot = null;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
return {
|
|
679
|
+
...r,
|
|
680
|
+
brandName: r.brand?.name || "Unknown Brand",
|
|
681
|
+
guestName: snapshot ? `${snapshot.firstName || ""} ${snapshot.lastName || ""}`.trim() || "Unknown Guest" : "Unknown Guest",
|
|
682
|
+
guestEmail: snapshot?.email || "",
|
|
683
|
+
guestPhone: snapshot?.phone || ""
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
var useReservationsInternal = createDataHook({
|
|
687
|
+
model: "Reservation",
|
|
688
|
+
dataPropertyName: "reservations",
|
|
689
|
+
buildFilter: buildFilter5,
|
|
690
|
+
// Include related data for brand name and guest info
|
|
691
|
+
selectionSet: [
|
|
692
|
+
"id",
|
|
693
|
+
"brandId",
|
|
694
|
+
"visitId",
|
|
695
|
+
"checkIn",
|
|
696
|
+
"checkOut",
|
|
697
|
+
"room",
|
|
698
|
+
"roomType",
|
|
699
|
+
"status",
|
|
700
|
+
"source",
|
|
701
|
+
"channel",
|
|
702
|
+
"confirmationCode",
|
|
703
|
+
"totalAmount",
|
|
704
|
+
"currency",
|
|
705
|
+
"nights",
|
|
706
|
+
"deletedAt",
|
|
707
|
+
"deletedBy",
|
|
708
|
+
"brand.name",
|
|
709
|
+
"visit.snapshot"
|
|
710
|
+
],
|
|
711
|
+
transform: transformReservation,
|
|
712
|
+
computedProperties: {
|
|
713
|
+
confirmedReservations: (reservations) => reservations.filter((r) => r.status === "confirmed"),
|
|
714
|
+
activeReservations: (reservations) => reservations.filter((r) => r.status === "confirmed" || r.status === "checked_in")
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
function useReservations(options = {}) {
|
|
718
|
+
const result = useReservationsInternal(options);
|
|
719
|
+
return {
|
|
720
|
+
reservations: result.reservations,
|
|
721
|
+
confirmedReservations: result.confirmedReservations,
|
|
722
|
+
activeReservations: result.activeReservations,
|
|
723
|
+
loading: result.loading,
|
|
724
|
+
error: result.error,
|
|
725
|
+
refetch: result.refetch
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// src/hooks/reservations/usePaginatedReservations.ts
|
|
730
|
+
function buildFilter6(options) {
|
|
731
|
+
const conditions = [];
|
|
732
|
+
if (options.brandId) {
|
|
733
|
+
conditions.push({ brandId: { eq: options.brandId } });
|
|
734
|
+
}
|
|
735
|
+
if (options.status) {
|
|
736
|
+
conditions.push({ status: { eq: options.status } });
|
|
737
|
+
}
|
|
738
|
+
if (options.contactId) {
|
|
739
|
+
conditions.push({ visitId: { eq: options.contactId } });
|
|
740
|
+
}
|
|
741
|
+
if (options.startDate) {
|
|
742
|
+
conditions.push({ checkIn: { ge: options.startDate } });
|
|
743
|
+
}
|
|
744
|
+
if (options.endDate) {
|
|
745
|
+
conditions.push({ checkIn: { le: options.endDate } });
|
|
746
|
+
}
|
|
747
|
+
if (options.filter && Object.keys(options.filter).length > 0) {
|
|
748
|
+
conditions.push(options.filter);
|
|
749
|
+
}
|
|
750
|
+
if (conditions.length === 0) {
|
|
751
|
+
return void 0;
|
|
752
|
+
}
|
|
753
|
+
if (conditions.length === 1) {
|
|
754
|
+
return conditions[0];
|
|
755
|
+
}
|
|
756
|
+
return { and: conditions };
|
|
757
|
+
}
|
|
758
|
+
function transformReservation2(r) {
|
|
759
|
+
let snapshot = r.visit?.snapshot;
|
|
760
|
+
if (typeof snapshot === "string") {
|
|
761
|
+
try {
|
|
762
|
+
snapshot = JSON.parse(snapshot);
|
|
763
|
+
} catch {
|
|
764
|
+
snapshot = null;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
return {
|
|
768
|
+
...r,
|
|
769
|
+
brandName: r.brand?.name || "Unknown Brand",
|
|
770
|
+
guestName: snapshot ? `${snapshot.firstName || ""} ${snapshot.lastName || ""}`.trim() || "Unknown Guest" : "Unknown Guest",
|
|
771
|
+
guestEmail: snapshot?.email || "",
|
|
772
|
+
guestPhone: snapshot?.phone || ""
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
var RESERVATION_SELECTION_SET = [
|
|
776
|
+
"id",
|
|
777
|
+
"brandId",
|
|
778
|
+
"visitId",
|
|
779
|
+
"checkIn",
|
|
780
|
+
"checkOut",
|
|
781
|
+
"room",
|
|
782
|
+
"roomType",
|
|
783
|
+
"status",
|
|
784
|
+
"source",
|
|
785
|
+
"channel",
|
|
786
|
+
"confirmationCode",
|
|
787
|
+
"totalAmount",
|
|
788
|
+
"currency",
|
|
789
|
+
"nights",
|
|
790
|
+
"deletedAt",
|
|
791
|
+
"deletedBy",
|
|
792
|
+
"brand.name",
|
|
793
|
+
"visit.snapshot"
|
|
794
|
+
];
|
|
795
|
+
var useActiveReservationsInternal = createPaginatedDataHook({
|
|
796
|
+
model: "Reservation",
|
|
797
|
+
dataPropertyName: "reservations",
|
|
798
|
+
defaultPageSize: 25,
|
|
799
|
+
selectionSet: RESERVATION_SELECTION_SET,
|
|
800
|
+
transform: transformReservation2,
|
|
801
|
+
buildFilter: buildFilter6,
|
|
802
|
+
baseFilter: ACTIVE_FILTER
|
|
803
|
+
});
|
|
804
|
+
var useDeletedReservationsInternal = createPaginatedDataHook({
|
|
805
|
+
model: "Reservation",
|
|
806
|
+
dataPropertyName: "reservations",
|
|
807
|
+
defaultPageSize: 25,
|
|
808
|
+
selectionSet: RESERVATION_SELECTION_SET,
|
|
809
|
+
transform: transformReservation2,
|
|
810
|
+
buildFilter: buildFilter6,
|
|
811
|
+
baseFilter: DELETED_FILTER
|
|
812
|
+
});
|
|
813
|
+
function useActiveReservations(options = {}) {
|
|
814
|
+
const result = useActiveReservationsInternal(options);
|
|
815
|
+
return {
|
|
816
|
+
reservations: result.reservations,
|
|
817
|
+
loading: result.loading,
|
|
818
|
+
initialLoading: result.initialLoading,
|
|
819
|
+
loadingMore: result.loadingMore,
|
|
820
|
+
error: result.error,
|
|
821
|
+
pagination: result.pagination,
|
|
822
|
+
hasMore: result.hasMore,
|
|
823
|
+
loadMore: result.loadMore,
|
|
824
|
+
refetch: result.refetch,
|
|
825
|
+
reset: result.reset,
|
|
826
|
+
setSearchFilter: result.setSearchFilter,
|
|
827
|
+
searchFilter: result.searchFilter
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
function useDeletedReservations(options = {}) {
|
|
831
|
+
const result = useDeletedReservationsInternal(options);
|
|
832
|
+
return {
|
|
833
|
+
reservations: result.reservations,
|
|
834
|
+
loading: result.loading,
|
|
835
|
+
initialLoading: result.initialLoading,
|
|
836
|
+
loadingMore: result.loadingMore,
|
|
837
|
+
error: result.error,
|
|
838
|
+
pagination: result.pagination,
|
|
839
|
+
hasMore: result.hasMore,
|
|
840
|
+
loadMore: result.loadMore,
|
|
841
|
+
refetch: result.refetch,
|
|
842
|
+
reset: result.reset,
|
|
843
|
+
setSearchFilter: result.setSearchFilter,
|
|
844
|
+
searchFilter: result.searchFilter
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// src/hooks/products/useProducts.ts
|
|
849
|
+
function buildFilter7(options) {
|
|
202
850
|
let filter = options.filter || {};
|
|
203
851
|
if (options.activeOnly) {
|
|
204
852
|
filter = { ...filter, isActive: { eq: true } };
|
|
@@ -208,7 +856,7 @@ function buildFilter3(options) {
|
|
|
208
856
|
var useProductsInternal = createDataHook({
|
|
209
857
|
model: "Product",
|
|
210
858
|
dataPropertyName: "products",
|
|
211
|
-
buildFilter:
|
|
859
|
+
buildFilter: buildFilter7,
|
|
212
860
|
computedProperties: {
|
|
213
861
|
activeProducts: (products) => products.filter((p) => p.isActive === true)
|
|
214
862
|
}
|
|
@@ -397,8 +1045,8 @@ async function toggleProductInstanceEnabled(client, id, enabled) {
|
|
|
397
1045
|
}
|
|
398
1046
|
}
|
|
399
1047
|
|
|
400
|
-
// src/hooks/useProductInstances.ts
|
|
401
|
-
function
|
|
1048
|
+
// src/hooks/productInstances/useProductInstances.ts
|
|
1049
|
+
function buildFilter8(options) {
|
|
402
1050
|
let filter = options.filter || {};
|
|
403
1051
|
if (options.brandId) {
|
|
404
1052
|
filter = { ...filter, brandId: { eq: options.brandId } };
|
|
@@ -417,7 +1065,7 @@ function buildFilter4(options) {
|
|
|
417
1065
|
var useProductInstancesInternal = createDataHook({
|
|
418
1066
|
model: "ProductInstance",
|
|
419
1067
|
dataPropertyName: "instances",
|
|
420
|
-
buildFilter:
|
|
1068
|
+
buildFilter: buildFilter8,
|
|
421
1069
|
computedProperties: {
|
|
422
1070
|
enabledInstances: (instances) => instances.filter((i) => i.enabled)
|
|
423
1071
|
}
|
|
@@ -465,58 +1113,8 @@ function useProductInstances(options = {}) {
|
|
|
465
1113
|
};
|
|
466
1114
|
}
|
|
467
1115
|
|
|
468
|
-
// src/hooks/useReservations.ts
|
|
469
|
-
function buildFilter5(options) {
|
|
470
|
-
const conditions = [];
|
|
471
|
-
if (options.brandId) {
|
|
472
|
-
conditions.push({ brandId: { eq: options.brandId } });
|
|
473
|
-
}
|
|
474
|
-
if (options.status) {
|
|
475
|
-
conditions.push({ status: { eq: options.status } });
|
|
476
|
-
}
|
|
477
|
-
if (options.contactId) {
|
|
478
|
-
conditions.push({ visitId: { eq: options.contactId } });
|
|
479
|
-
}
|
|
480
|
-
if (options.startDate) {
|
|
481
|
-
conditions.push({ checkIn: { ge: options.startDate } });
|
|
482
|
-
}
|
|
483
|
-
if (options.endDate) {
|
|
484
|
-
conditions.push({ checkIn: { le: options.endDate } });
|
|
485
|
-
}
|
|
486
|
-
if (options.filter) {
|
|
487
|
-
conditions.push(options.filter);
|
|
488
|
-
}
|
|
489
|
-
if (conditions.length === 0) {
|
|
490
|
-
return void 0;
|
|
491
|
-
}
|
|
492
|
-
if (conditions.length === 1) {
|
|
493
|
-
return conditions[0];
|
|
494
|
-
}
|
|
495
|
-
return { and: conditions };
|
|
496
|
-
}
|
|
497
|
-
var useReservationsInternal = createDataHook({
|
|
498
|
-
model: "Reservation",
|
|
499
|
-
dataPropertyName: "reservations",
|
|
500
|
-
buildFilter: buildFilter5,
|
|
501
|
-
computedProperties: {
|
|
502
|
-
confirmedReservations: (reservations) => reservations.filter((r) => r.status === "confirmed"),
|
|
503
|
-
activeReservations: (reservations) => reservations.filter((r) => r.status === "confirmed" || r.status === "checked_in")
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
function useReservations(options = {}) {
|
|
507
|
-
const result = useReservationsInternal(options);
|
|
508
|
-
return {
|
|
509
|
-
reservations: result.reservations,
|
|
510
|
-
confirmedReservations: result.confirmedReservations,
|
|
511
|
-
activeReservations: result.activeReservations,
|
|
512
|
-
loading: result.loading,
|
|
513
|
-
error: result.error,
|
|
514
|
-
refetch: result.refetch
|
|
515
|
-
};
|
|
516
|
-
}
|
|
517
|
-
|
|
518
1116
|
// src/hooks/useContacts.ts
|
|
519
|
-
function
|
|
1117
|
+
function buildFilter9(options) {
|
|
520
1118
|
const conditions = [];
|
|
521
1119
|
if (options.brandId) {
|
|
522
1120
|
conditions.push({ brandId: { eq: options.brandId } });
|
|
@@ -556,7 +1154,7 @@ function buildFilter6(options) {
|
|
|
556
1154
|
var useContactsInternal = createDataHook({
|
|
557
1155
|
model: "Contact",
|
|
558
1156
|
dataPropertyName: "contacts",
|
|
559
|
-
buildFilter:
|
|
1157
|
+
buildFilter: buildFilter9,
|
|
560
1158
|
computedProperties: {
|
|
561
1159
|
consentedContacts: (contacts) => contacts.filter((c) => c.gdprConsent === true),
|
|
562
1160
|
marketingContacts: (contacts) => contacts.filter((c) => c.marketingOptIn === true)
|
|
@@ -574,11 +1172,22 @@ function useContacts(options = {}) {
|
|
|
574
1172
|
};
|
|
575
1173
|
}
|
|
576
1174
|
export {
|
|
1175
|
+
ACTIVE_FILTER,
|
|
1176
|
+
DELETED_FILTER,
|
|
577
1177
|
createDataHook,
|
|
1178
|
+
createPaginatedDataHook,
|
|
578
1179
|
resetClientInstance,
|
|
579
1180
|
useAccounts,
|
|
1181
|
+
useActiveAccounts,
|
|
1182
|
+
useActiveBrands,
|
|
1183
|
+
useActiveReservations,
|
|
1184
|
+
useActiveUsers,
|
|
580
1185
|
useBrands,
|
|
581
1186
|
useContacts,
|
|
1187
|
+
useDeletedAccounts,
|
|
1188
|
+
useDeletedBrands,
|
|
1189
|
+
useDeletedReservations,
|
|
1190
|
+
useDeletedUsers,
|
|
582
1191
|
useProductInstances,
|
|
583
1192
|
useProducts,
|
|
584
1193
|
useReservations,
|