@7365admin1/layer-common 1.11.54 → 3.0.0

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.
@@ -34,20 +34,25 @@
34
34
 
35
35
  <v-col v-if="shouldShowField('block')" cols="12">
36
36
  <InputLabel class="text-capitalize" title="Block" required />
37
- <v-autocomplete v-model="vehicle.block" :items="blocksArray" item-value="value" item-title="title"
38
- @update:model-value="handleChangeBlock" density="comfortable" :rules="[requiredRule]" />
37
+ <v-autocomplete v-model="vehicle.block" :items="blocksArray" autocomplete="off"
38
+ :key="blockListDataPending ? 'block-list-pending' : 'block-list-ready'" :loading="blockListDataPending"
39
+ item-value="value" item-title="title" @update:model-value="handleChangeBlock" density="comfortable"
40
+ :rules="[requiredRule]" />
39
41
  </v-col>
40
42
 
41
43
  <v-col v-if="shouldShowField('level')" cols="12">
42
44
  <InputLabel class="text-capitalize" title="Level" required />
43
- <v-autocomplete v-model="vehicle.level" :items="levelsArray" density="comfortable" :disabled="!vehicle.block"
44
- @update:model-value="handleChangeLevel" :rules="[requiredRule]" />
45
+ <v-autocomplete v-model="vehicle.level" :items="levelsArray" autocomplete="off"
46
+ :key="levelListDataPending ? 'level-list-pending' : 'level-list-ready'" :loading="levelListDataPending"
47
+ density="comfortable" :disabled="!vehicle.block" @update:model-value="handleChangeLevel"
48
+ :rules="[requiredRule]" />
45
49
  </v-col>
46
50
 
47
51
  <v-col v-if="shouldShowField('unit')" cols="12">
48
52
  <InputLabel class="text-capitalize" title="Unit" required />
49
- <v-autocomplete v-model="vehicle.unit" :items="unitsArray" density="comfortable" :disabled="!vehicle.level"
50
- :rules="[requiredRule]" />
53
+ <v-autocomplete v-model="vehicle.unit" :items="unitsArray" autocomplete="off"
54
+ :key="unitListDataPending ? 'unit-list-pending' : 'unit-list-ready'" :loading="unitListDataPending"
55
+ density="comfortable" :disabled="!vehicle.level" :rules="[requiredRule]" />
51
56
  </v-col>
52
57
 
53
58
  <v-col v-if="shouldShowField('nric')" cols="12">
@@ -278,6 +283,7 @@ const { requiredRule, formatDateISO8601, debounce } = useUtils();
278
283
  const { addVehicle, getCustomSeasonPassTypes, updateVehicle, formatVehicleStatus } = useVehicle();
279
284
  const { getSiteById, getSiteLevels, getSiteUnits } = useSiteSettings();
280
285
  const { findPersonByNRICMultipleResult, getPeopleByUnit } = usePeople();
286
+ const { getBlocksSelection, getLevelsSelection, getUnitSelection } = useBuilding();
281
287
 
282
288
  const emit = defineEmits(['back', 'select', 'done', 'error', 'close', 'close:all']);
283
289
 
@@ -313,6 +319,7 @@ const seasonPassTypeArray = ref<{ title: string, value: string }[]>([]);
313
319
 
314
320
  const matchingPeople = ref<Partial<TPeople>[]>([]);
315
321
  const showMatchingPeopleDialog = ref(false);
322
+ const prefillingRecords = ref(false);
316
323
  const checkingNRIC = ref(false);
317
324
  const checkingUnit = ref(false);
318
325
 
@@ -367,62 +374,80 @@ if (prop.vehicleData) {
367
374
  }
368
375
 
369
376
 
370
- const { data: siteData, refresh: refreshSiteData } = useLazyAsyncData(
371
- `fetch-site-data-${prop.site}`,
372
- async () => await getSiteById(prop.site));
373
377
 
374
- const { data: levelsData, refresh: refreshLevelsData } = useLazyAsyncData(
375
- `fetch-levels-data-${prop.site}-${vehicle.block}`,
378
+ const {
379
+ data: blocksListData,
380
+ refresh: refreshBlockListData,
381
+ status: blocksListStatus,
382
+ pending: blockListDataPending,
383
+ } = useAsyncData(`vehicle-fetch-block-list-data-${prop.site}`, () =>
384
+ getBlocksSelection({ siteId: prop.site }), { watch: [() => prop.site], deep: true }
385
+ );
386
+
387
+
388
+ const {
389
+ data: levelsData,
390
+ refresh: refreshLevelsData,
391
+ status: levelsStatus,
392
+ pending: levelListDataPending,
393
+ } = useAsyncData(
394
+ `vehicle-fetch-levels-data-${prop.site}-${vehicle.block}`,
376
395
  async () => {
377
- if (!vehicle.block) return Promise.resolve(null);;
378
- return await getSiteLevels(prop.site, { block: Number(vehicle.block) })
379
- });
396
+ if (!vehicle.block) return Promise.resolve(null);
397
+ // return await getSiteWithLevels(prop.site, { block: Number(vehicle.block) });
398
+ return await getLevelsSelection({ siteId: prop.site, blockId: vehicle.block._id ? vehicle.block._id : vehicle.block });
399
+ }, { watch: [() => vehicle.block], deep: true }
400
+ );
380
401
 
381
- const { data: unitsData, refresh: refreshUnitsData } = useLazyAsyncData(
382
- `fetch-units-data-${prop.site}-${vehicle.level}`,
402
+ const {
403
+ data: unitsData,
404
+ refresh: refreshUnitsData,
405
+ status: unitsStatus,
406
+ pending: unitListDataPending,
407
+ } = useAsyncData(
408
+ `vehicle-fetch-units-data-${prop.site}-${vehicle.level}`,
383
409
  async () => {
384
- if (!vehicle.level) return Promise.resolve(null);;
385
- return await getSiteUnits(prop.site, Number(vehicle.block), vehicle.level)
386
- });
410
+ if (!vehicle.level) return Promise.resolve(null);
411
+ return await getUnitSelection({ siteId: prop.site, block: vehicle.block._id ? vehicle.block._id : vehicle.block, level: vehicle.level._id ? vehicle.level._id : vehicle.level });
412
+ }, { watch: [() => vehicle.level], deep: true }
413
+ );
387
414
 
388
415
 
389
416
  const { data: seasonPassTypeData, refresh: refreshSeasonPassTypeData } = useLazyAsyncData(
390
- `fetch-season-pass-type-data-${prop.site}`,
417
+ `vehicle-fetch-season-pass-type-data-${prop.site}`,
391
418
  async () => await getCustomSeasonPassTypes(prop.site));
392
419
 
393
420
 
394
421
  watch(
395
- siteData,
396
- (newVal) => {
397
- const siteDataValue = newVal as any;
398
- if (siteDataValue) {
399
- const numberOfBlocks = siteDataValue.metadata?.block || 0;
400
- for (let i = 1; i <= numberOfBlocks; i++) {
401
- blocksArray.value.push({
402
- title: `Block ${i}`,
403
- value: i
404
- });
405
- }
406
-
407
- } else {
422
+ [blocksListData],
423
+ () => {
424
+ if (blocksListStatus.value === 'pending') {
408
425
  blocksArray.value = [];
426
+ return;
409
427
  }
410
- }, { immediate: true });
411
428
 
429
+ const arr = Array.isArray(blocksListData.value?.data) ? blocksListData.value?.data : [];
430
+ blocksArray.value = arr.map((block: any) => ({
431
+ title: block.name,
432
+ value: block._id,
433
+ }));
434
+ },
435
+ { immediate: true, deep: true }
436
+ )
412
437
 
413
- watch(
414
- levelsData,
415
- (newVal: any) => {
416
- if (newVal) {
417
- const arr = newVal.levels || [];
418
- levelsArray.value = arr?.map((level: any) => ({
419
- title: level,
420
- value: level
421
- }));
422
- } else {
423
- levelsArray.value = [];
424
- }
425
- }, { immediate: true });
438
+ watch([levelsData], () => {
439
+ if (levelsStatus.value === 'pending') {
440
+ levelsArray.value = [];
441
+ return;
442
+ }
443
+
444
+ const arr = Array.isArray(levelsData.value?.data) ? levelsData.value?.data : [];
445
+ const mappedLevels = arr.map((level: any) => ({
446
+ title: level.name,
447
+ value: level._id,
448
+ }));
449
+ levelsArray.value = mappedLevels;
450
+ }, { immediate: true, deep: true })
426
451
 
427
452
  watch(
428
453
  unitsData,
@@ -710,7 +735,7 @@ function selectPeopleRecord(record: TPeople) {
710
735
 
711
736
 
712
737
  async function checkPeopleById() {
713
- if (!vehicle.unit || prop.mode === 'edit') return;
738
+ if (!vehicle.unit || prop.mode === 'edit' || prefillingRecords.value) return;
714
739
 
715
740
  checkingUnit.value = true;
716
741
  showMatchingPeopleDialog.value = true;
@@ -743,6 +768,8 @@ const debounceedCheckUnit = debounce(checkPeopleById, 500);
743
768
  watch(
744
769
  () => vehicle.unit,
745
770
  async (newUnit) => {
771
+ if (prefillingRecords.value) return;
772
+
746
773
  resetVehicleDetails();
747
774
  matchingPeople.value = [];
748
775
  if (!newUnit) return;
@@ -778,13 +805,25 @@ onMounted(() => {
778
805
  vehicle.start = prop.vehicleData.start || '';
779
806
  vehicle.plateNumber = prop.vehicleData.plateNumber
780
807
  vehicle.peopleId = prop.vehicleData.peopleId || '';
781
- vehicle.block = prop.vehicleData.block === 0 ? null : prop.vehicleData.block || null;
808
+ vehicle.block = prop.vehicleData.block || null;
782
809
 
783
- if(prop.type === "seasonpass"){
810
+ if (prop.type === "seasonpass") {
784
811
  showSubscriptionDateOptions.value = true;
785
812
  }
786
813
  }
787
814
  }, 300);
815
+
816
+ if (prop.mode === 'add' && prop.type !== 'blocklist') {
817
+ // For add mode, we want to check for matching people records if the type is not blocklist, as blocklist records are typically not linked to people records.
818
+ prefillingRecords.value = true;
819
+ vehicle.block = prop.vehicleData?.block?._id ? prop.vehicleData?.block?._id : '';
820
+ vehicle.level = prop.vehicleData?.level?._id ? prop.vehicleData?.level?._id : '';
821
+ vehicle.unit = prop.vehicleData?.unit?._id ? prop.vehicleData?.unit?._id : '';
822
+ }
823
+
824
+ nextTick(() => {
825
+ prefillingRecords.value = false;
826
+ })
788
827
  })
789
828
 
790
829
 
@@ -170,9 +170,9 @@ const headers = [
170
170
  { title: "Name", value: "name" },
171
171
  { title: "Vehicle Numbers", value: "plates" },
172
172
  { title: "NRIC", value: "nric" },
173
- { title: "Block", value: "block" },
174
- { title: "Floor", value: "level" },
175
- { title: "Unit", value: "unitName" },
173
+ { title: "Block", value: "block.name" },
174
+ { title: "Floor", value: "level.name" },
175
+ { title: "Unit", value: "unit.name" },
176
176
  { title: "Category", value: "category" },
177
177
  // { title: "Type", value: "type" },
178
178
  // { title: "Status", value: "status" },
@@ -247,7 +247,7 @@ const formattedFields: Partial<Record<keyof TVehicle, string>> = {
247
247
  nric: "NRIC",
248
248
  block: "Block",
249
249
  level: "Level",
250
- unitName: "Unit",
250
+ unit: "Unit",
251
251
  start: "Start",
252
252
  end: "End",
253
253
  category: "Category",
@@ -259,6 +259,12 @@ const formattedFields: Partial<Record<keyof TVehicle, string>> = {
259
259
  function formatValues(key: string, value: any) {
260
260
  if (!value) return ""
261
261
  switch (key) {
262
+ case "unit":
263
+ return value.name || "";
264
+ case "level":
265
+ return value.name || "";
266
+ case "block":
267
+ return value.name || "";
262
268
  case "start":
263
269
  return formatDate(value)
264
270
  case "end":
@@ -152,27 +152,27 @@
152
152
 
153
153
  <v-col v-if="shouldShowField('block')" cols="12">
154
154
  <InputLabel class="text-capitalize" title="Block" required />
155
- <v-autocomplete v-model="visitor.block" :items="blocksArray" item-value="value" item-title="title"
156
- :loading="blockStatus === 'pending'" @update:model-value="handleChangeBlock" density="comfortable"
155
+ <v-autocomplete v-model="visitor.block" :items="blocksArray" item-value="value" autocomplete="off" item-title="title" :key="blockListDataPending ? 'block-list-pending' : 'block-list-ready'"
156
+ :loading="blockListDataPending" @update:model-value="handleChangeBlock" density="comfortable"
157
157
  :rules="[requiredRule]" />
158
158
  </v-col>
159
159
 
160
160
  <v-col v-if="shouldShowField('level')" cols="12">
161
161
  <InputLabel class="text-capitalize" title="Level" required />
162
- <v-autocomplete v-model="visitor.level" :items="levelsArray" density="comfortable" :disabled="!visitor.block"
163
- :loading="levelsStatus === 'pending'" @update:model-value="handleChangeLevel" :rules="[requiredRule]" />
162
+ <v-autocomplete v-model="visitor.level" :items="levelsArray" density="comfortable" autocomplete="off"
163
+ :disabled="!visitor.block" :key="levelListDataPending ? 'level-list-pending' : 'level-list-ready'" :loading="levelsDataPending" @update:model-value="handleChangeLevel"
164
+ :rules="[requiredRule]" />
164
165
  </v-col>
165
-
166
-
167
166
  <v-col v-if="shouldShowField('unit')" cols="12">
168
167
  <InputLabel class="text-capitalize" title="Unit" required />
169
- <v-autocomplete v-model="visitor.unit" :items="unitsArray" density="comfortable" item-title="title"
170
- item-value="value" :disabled="!visitor.level" :loading="unitsStatus === 'pending'" :rules="[requiredRule]"
168
+ <v-autocomplete v-model="visitor.unit" :items="unitsArray" density="comfortable" autocomplete="off" item-title="title"
169
+ item-value="value" :disabled="!visitor.level" :key="unitListDataPending ? 'unit-list-pending' : 'unit-list-ready'" :loading="unitsDataPending" :rules="[requiredRule]"
171
170
  @update:model-value="handleUpdateUnit" />
172
171
  </v-col>
173
172
 
174
173
  <v-col v-if="shouldShowField('unit')" cols="12">
175
- <InputLabel class="text-capitalize" title="Registered Unit Company Name" required :key="'unit-key' + visitor.level" />
174
+ <InputLabel class="text-capitalize" title="Registered Unit Company Name" required
175
+ :key="'unit-key' + visitor.level" />
176
176
  <v-text-field v-model.trim="registeredUnitCompanyName" density="comfortable"
177
177
  :loading="buildingUnitDataPending" readonly class="no-pointer" />
178
178
  </v-col>
@@ -315,7 +315,8 @@ const currentAutofillSource = ref<AutofillSource>(null);
315
315
 
316
316
 
317
317
  const { requiredRule, debounce, UTCToLocalTIme } = useUtils();
318
- const { getSiteById, getSiteLevels, getSiteUnits } = useSiteSettings();
318
+ const { getSiteById } = useSiteSettings();
319
+ const { getBlocksSelection, getLevelsSelection, getUnitSelection } = useBuilding();
319
320
  const { createVisitor, typeFieldMap, contractorTypes, getVisitors, updateVisitor } = useVisitor();
320
321
  const { getBySiteId: getEntryPassSettingsBySiteId } = useSiteEntryPassSettings();
321
322
  const { createVisitorPass, signQr } = useAccessManagement();
@@ -683,78 +684,101 @@ const {
683
684
  const {
684
685
  data: siteData,
685
686
  refresh: refreshSiteData,
686
- status: blockStatus,
687
+ status: siteStatus,
687
688
  pending: siteDataPending,
688
- } = useLazyAsyncData(`fetch-site-data-${prop.site}`, () =>
689
+ } = useLazyAsyncData(`visitor-fetch-site-data-${prop.site}`, () =>
689
690
  getSiteById(prop.site)
690
691
  );
691
692
 
693
+
694
+ const {
695
+ data: blocksListData,
696
+ refresh: refreshBlockListData,
697
+ status: blocksListStatus,
698
+ pending: blockListDataPending,
699
+ } = useLazyAsyncData(`visitor-fetch-block-list-data-${prop.site}`, () =>
700
+ getBlocksSelection({ siteId: prop.site }), {watch: [() => prop.site], deep: true }
701
+ );
702
+
703
+
704
+
692
705
  const {
693
706
  data: levelsData,
694
707
  refresh: refreshLevelsData,
695
708
  status: levelsStatus,
709
+ pending: levelsDataPending,
696
710
  } = useLazyAsyncData(
697
- `fetch-levels-data-${prop.site}-${visitor.block}`,
711
+ `visitor-fetch-levels-data-${prop.site}-${visitor.block}`,
698
712
  async () => {
699
713
  if (!visitor.block) return Promise.resolve(null);
700
- return await getSiteLevels(prop.site, { block: Number(visitor.block) });
701
- }, { watch: [() => visitor.block] }
714
+ // return await getSiteWithLevels(prop.site, { block: Number(visitor.block) });
715
+ return await getLevelsSelection({ siteId: prop.site, blockId: visitor.block });
716
+ }, { watch: [() => visitor.block], deep: true }
702
717
  );
703
718
 
704
719
  const {
705
720
  data: unitsData,
706
721
  refresh: refreshUnitsData,
707
722
  status: unitsStatus,
723
+ pending: unitsDataPending,
708
724
  } = useLazyAsyncData(
709
- `fetch-units-data-${prop.site}-${visitor.level}`,
725
+ `visitor-fetch-units-data-${prop.site}-${visitor.level}`,
710
726
  async () => {
711
727
  if (!visitor.level) return Promise.resolve(null);
712
- return await getSiteUnits(prop.site, Number(visitor.block), visitor.level);
713
- }, { watch: [() => visitor.level] }
728
+ return await getUnitSelection({ siteId: prop.site, block: visitor.block, level: visitor.level });
729
+ },{ watch: [() => visitor.level], deep: true }
714
730
  );
715
731
 
732
+
716
733
  watch(
717
734
  siteData,
718
735
  (newVal) => {
719
736
  const siteDataValue = newVal as TSite;
720
737
  if (siteDataValue) {
721
- const numberOfBlocks = siteDataValue.metadata?.block || 0;
722
- for (let i = 1; i <= numberOfBlocks; i++) {
723
- blocksArray.value.push({
724
- title: `Block ${i}`,
725
- value: i,
726
- });
727
- }
728
738
 
729
739
  deliveryCompanyList.value = Array.isArray(siteDataValue?.deliveryCompanyList) ? siteDataValue.deliveryCompanyList : [];
730
740
 
731
- } else {
732
- blocksArray.value = [];
733
- }
741
+ }
734
742
  },
735
743
  { immediate: true }
736
744
  );
737
745
 
738
746
  watch(
739
- levelsData,
740
- (newVal: any) => {
741
- if (newVal) {
742
- const arr = newVal.levels || [];
743
- levelsArray.value = arr?.map((level: any) => ({
744
- title: level,
745
- value: level,
746
- }));
747
- } else {
748
- levelsArray.value = [];
747
+ [blocksListData],
748
+ () => {
749
+ if (blocksListStatus.value === 'pending') {
750
+ blocksArray.value = [];
751
+ return;
749
752
  }
753
+
754
+ const arr = Array.isArray(blocksListData.value?.data) ? blocksListData.value?.data : [];
755
+ blocksArray.value = arr.map((block: any) => ({
756
+ title: block.name,
757
+ value: block._id,
758
+ }));
750
759
  },
751
- { immediate: true }
752
- );
760
+ { immediate: true, deep: true }
761
+ )
762
+
763
+
764
+ watch([levelsData], () => {
765
+ if (levelsStatus.value === 'pending') {
766
+ levelsArray.value = [];
767
+ return;
768
+ }
769
+
770
+ const arr = Array.isArray(levelsData.value?.data) ? levelsData.value?.data : [];
771
+ const mappedLevels = arr.map((level: any) => ({
772
+ title: level.name,
773
+ value: level._id,
774
+ }));
775
+ levelsArray.value = mappedLevels;
776
+ }, { immediate: true, deep: true})
753
777
 
754
778
  watch(
755
779
  unitsData,
756
780
  (newVal: any) => {
757
- if (!newVal) {
781
+ if (!newVal || !Array.isArray(newVal)) {
758
782
  unitsArray.value = []
759
783
  return
760
784
  }
@@ -777,7 +801,7 @@ watch(
777
801
 
778
802
  unitsArray.value = mapped
779
803
  },
780
- { immediate: true }
804
+ { immediate: true, deep: true }
781
805
  )
782
806
 
783
807
 
@@ -925,7 +949,7 @@ async function submit() {
925
949
  }
926
950
 
927
951
  // add register status when registering unregistered visitor
928
- if (prop.mode === 'register'){
952
+ if (prop.mode === 'register') {
929
953
  payload.status = "registered"
930
954
  }
931
955
 
@@ -96,7 +96,7 @@
96
96
  formatLocation({
97
97
  block: item.block,
98
98
  level: item.level,
99
- unit: item.unitName,
99
+ unit: item.unit,
100
100
  })
101
101
  }}</span>
102
102
  </span>
@@ -852,7 +852,7 @@ const formattedFields = {
852
852
  company: "Company",
853
853
  block: "Block",
854
854
  level: "Level",
855
- unitName: "Unit",
855
+ unit: "Unit",
856
856
  checkIn: "Check In",
857
857
  snapshotEntryImage: "Entry Image",
858
858
  checkOut: "Check Out",
@@ -973,10 +973,10 @@ const selectedVisitorObject = computed<Record<string, any>>(() => {
973
973
 
974
974
  let locationString = "N/A";
975
975
 
976
- if (obj?.block || obj?.level || obj?.unitName) {
977
- locationString = `${obj.block} / ${obj.level} / ${obj.unitName}`;
978
- } else if (obj?.block) {
979
- locationString = obj.block;
976
+ if (obj?.block?.name || obj?.level?.name || obj?.unitName) {
977
+ locationString = `${obj.block?.name} / ${obj.level?.name} / ${obj.unitName}`;
978
+ } else if (obj?.block?.name) {
979
+ locationString = obj.block?.name;
980
980
  } else {
981
981
  locationString = "N/A";
982
982
  }
@@ -994,6 +994,10 @@ function formatValues(key: string, value: any) {
994
994
  switch (key) {
995
995
  case "unit":
996
996
  return value?.name;
997
+ case "block":
998
+ return value?.name;
999
+ case "level":
1000
+ return value?.name;
997
1001
  case "checkIn":
998
1002
  return formatDate(value);
999
1003
  case "checkOut":
@@ -206,7 +206,7 @@ export default function useBuilding() {
206
206
  });
207
207
  }
208
208
 
209
- function createBuilding(data: TBuilding) {
209
+ function createBuilding(data: TBuildingPayload) {
210
210
  return useNuxtApp().$api("/api/buildings", {
211
211
  method: "POST",
212
212
  body: data,
@@ -222,7 +222,7 @@ export default function useBuilding() {
222
222
 
223
223
  function updateById(
224
224
  id: string,
225
- data: Pick<TBuilding, "name" | "block" | "levels" | "buildingFloorPlan">
225
+ data: TBuildingUpdatePayload
226
226
  ) {
227
227
  return useNuxtApp().$api(`/api/buildings/id/${id}`, {
228
228
  method: "PATCH",
@@ -236,6 +236,32 @@ export default function useBuilding() {
236
236
  });
237
237
  }
238
238
 
239
+
240
+ function getBlocksSelection({siteId} : { siteId: string; }) {
241
+ return useNuxtApp().$api(`/api/buildings/list/site/${siteId}`, {
242
+ method: "GET",
243
+ });
244
+ }
245
+
246
+ function getLevelsSelection({siteId, blockId} : { siteId: string; blockId: string }) {
247
+ return useNuxtApp().$api(`/api/building-levels/list/site/${siteId}`, {
248
+ method: "GET",
249
+ query: {
250
+ block: blockId
251
+ }
252
+ });
253
+ }
254
+
255
+ async function getUnitSelection({siteId, block, level} : { siteId: string; block: string; level: string }) {
256
+ return await useNuxtApp().$api<Record<string, any>>(
257
+ `/api/building-units/site/${siteId}/block/${block}/level/${level}`,
258
+ {
259
+ method: "GET",
260
+ }
261
+ );
262
+ }
263
+
264
+
239
265
  return {
240
266
  categories,
241
267
  types,
@@ -246,5 +272,8 @@ export default function useBuilding() {
246
272
  updateBuildingField,
247
273
  deleteById,
248
274
  updateById,
249
- };
275
+ getBlocksSelection,
276
+ getLevelsSelection,
277
+ getUnitSelection
278
+ }
250
279
  }
@@ -0,0 +1,31 @@
1
+ export default function useBuildingLevel() {
2
+
3
+
4
+ function batchUpdateLevels(levels: { _id: string; name: string }[]) {
5
+
6
+ const formattedPayloadLevels = levels.map(level => ({
7
+ _id: level._id,
8
+ value: {
9
+ name: level.name
10
+ }
11
+ }));
12
+
13
+ return useNuxtApp().$api(`/api/building-levels/batch`, {
14
+ method: "PATCH",
15
+ body:
16
+ [...formattedPayloadLevels]
17
+ });
18
+ }
19
+
20
+ function deleteById(id: string) {
21
+ return useNuxtApp().$api(`/api/building-levels/${id}`, {
22
+ method: "PUT",
23
+ });
24
+ }
25
+
26
+
27
+ return {
28
+ deleteById,
29
+ batchUpdateLevels
30
+ };
31
+ }
@@ -3,9 +3,9 @@ export default function(){
3
3
  const formatLocation = ({block, level, unit}: {block: number, level: string, unit: string | TBuildingUnit}) => {
4
4
  const parts = [];
5
5
 
6
- if (block) parts.push(`Block ${block}`);
7
- if (level) parts.push(level);
8
- if (unit) parts.push(unit);
6
+ if (block?.name) parts.push(`${block.name}`);
7
+ if (level?.name) parts.push(`${level.name}`);
8
+ if (unit?.name) parts.push(unit?.name);
9
9
 
10
10
  return parts.join(" / ");
11
11
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "1.11.54",
5
+ "version": "3.0.0",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "publishConfig": {
@@ -3,7 +3,7 @@ declare type TBuilding = {
3
3
  site: string;
4
4
  name: string;
5
5
  block: number | null;
6
- levels: string[];
6
+ levels: { _id: string; name: string }[];
7
7
  buildingFiles: { id: string, name: string }[] | string[];
8
8
  };
9
9
 
@@ -16,7 +16,7 @@ declare type TBuildingUnit = {
16
16
  building: string;
17
17
  buildingName?: string;
18
18
  block: number | null;
19
- level: string | null;
19
+ level: { _id: string; name: string } | null;
20
20
  category: string;
21
21
  status: string;
22
22
  buildingUnitFiles: string[];
@@ -25,3 +25,15 @@ declare type TBuildingUnit = {
25
25
  leaseStart: string;
26
26
  leaseEnd: string;
27
27
  };
28
+
29
+
30
+ declare type TBuildingPayload = Pick<TBuilding, "site" | "name" | "block" | "buildingFiles"> & {
31
+ levels: string[];
32
+ };
33
+
34
+
35
+ declare type TBuildingUpdatePayload = Pick<TBuilding, "name" | "buildingFiles"> & {
36
+ levels: string[];
37
+ };
38
+
39
+ declare type TBuildingUnitPayload = Pick<TBuildingUnit, "site" | "name" | "building" | "buildingName" | "block" | "category" | "status" | "buildingUnitFiles" | "companyName" | "companyRegistrationNumber" | "leaseStart" | "leaseEnd"> & { level?: string}
@@ -6,8 +6,14 @@ declare type TVehicle = {
6
6
  direction: "entry" | "exit" | "both" | "none";
7
7
  name: string;
8
8
  phoneNumber?: string;
9
- block: number | "";
10
- level: string;
9
+ block: {
10
+ _id: string;
11
+ name: string;
12
+ }
13
+ level: {
14
+ _id: string;
15
+ name: string;
16
+ }
11
17
  unit: string;
12
18
  unitName?: string; // For display purposes, the API will return the unit name if available
13
19
  nric?: string | null;
@@ -33,8 +39,6 @@ declare type TVehiclePayload = Pick<
33
39
  | "direction"
34
40
  | "name"
35
41
  | "phoneNumber"
36
- | "block"
37
- | "level"
38
42
  | "unit"
39
43
  | "nric"
40
44
  | "remarks"
@@ -44,4 +48,4 @@ declare type TVehiclePayload = Pick<
44
48
  | "site"
45
49
  | "org"
46
50
  | "peopleId"
47
- > & { plateNumber?: string | string[] };
51
+ > & { plateNumber?: string | string[], block?: string, level?: string };