@7365admin1/layer-common 3.1.0 → 3.1.2-staging.29

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.
@@ -2,6 +2,8 @@ import type {
2
2
  NFCPatrolReportFilters,
3
3
  NFCPatrolSummaryReport,
4
4
  NFCPatrolReportSummaryRow,
5
+ NFCPatrolMonthlyReportRow,
6
+ NFCPatrolMonthlyReport,
5
7
  } from "../types/nfc-patrol-report";
6
8
  import useNFCPatrolLog from "./useNFCPatrolLog";
7
9
  import useSite from "./useSite";
@@ -12,6 +14,55 @@ interface NFCPatrolLogListResponse {
12
14
  pageRange?: string;
13
15
  }
14
16
 
17
+ const MONTHS = [
18
+ "January",
19
+ "February",
20
+ "March",
21
+ "April",
22
+ "May",
23
+ "June",
24
+ "July",
25
+ "August",
26
+ "September",
27
+ "October",
28
+ "November",
29
+ "December",
30
+ ];
31
+ function mapLogsToMonthlyRows(
32
+ logs: Record<string, any>[],
33
+ ): NFCPatrolMonthlyReportRow[] {
34
+ const rows = MONTHS.map((month) => ({
35
+ month,
36
+ checked: 0,
37
+ checkedPercentage: 0,
38
+ missed: 0,
39
+ missedPercentage: 0,
40
+ }));
41
+
42
+ logs.forEach((log) => {
43
+ const monthIndex = new Date(log.date).getMonth();
44
+
45
+ for (const checkpoint of log.checkPoints ?? []) {
46
+ if (checkpoint.status === "Completed") {
47
+ rows[monthIndex].checked++;
48
+ } else if (checkpoint.status === "Skipped") {
49
+ rows[monthIndex].missed++;
50
+ }
51
+ }
52
+ });
53
+
54
+ rows.forEach((row) => {
55
+ const total = row.checked + row.missed;
56
+
57
+ if (total > 0) {
58
+ row.checkedPercentage = Math.round((row.checked / total) * 100);
59
+ row.missedPercentage = Math.round((row.missed / total) * 100);
60
+ }
61
+ });
62
+
63
+ return rows;
64
+ }
65
+
15
66
  function buildAddress(address?: Record<string, string>) {
16
67
  if (!address) return undefined;
17
68
 
@@ -27,23 +78,7 @@ function buildAddress(address?: Record<string, string>) {
27
78
  return parts.length ? parts.join(", ") : undefined;
28
79
  }
29
80
 
30
- function mapLogToSummaryRow(
31
- log: Record<string, any>,
32
- index: number,
33
- ): NFCPatrolReportSummaryRow {
34
- const checkpoints: Record<string, any>[] = log.checkPoints ?? [];
35
- const checked = checkpoints.filter((cp) => cp.status === "Completed").length;
36
- const missed = checkpoints.filter((cp) => cp.status === "Skipped").length;
37
81
 
38
- return {
39
- id: log._id,
40
- routeName: `${index + 1}. ${log.route?.name ?? "-"}`,
41
- securityCheckSchedule: log.route?.startTime ?? "-",
42
- checked,
43
- missed,
44
- status: missed === 0 ? "Completed" : "Incomplete",
45
- };
46
- }
47
82
 
48
83
  export function useNFCPatrolMonthlyReport(
49
84
  filters: NFCPatrolReportFilters,
@@ -52,12 +87,12 @@ export function useNFCPatrolMonthlyReport(
52
87
  const { getAll: getPatrolLogs } = useNFCPatrolLog();
53
88
  const { getSiteById } = useSite();
54
89
 
55
- const report = ref<NFCPatrolSummaryReport | null>(null);
90
+ const report = ref<NFCPatrolMonthlyReport | null>(null);
56
91
  const loading = ref(false);
57
92
  const notFound = ref(false);
58
93
 
59
94
  async function fetchReport() {
60
- if (!site || !filters.date || !filters.route) {
95
+ if (!site || !filters.route) {
61
96
  report.value = null;
62
97
  notFound.value = false;
63
98
  return;
@@ -65,19 +100,16 @@ export function useNFCPatrolMonthlyReport(
65
100
 
66
101
  loading.value = true;
67
102
  notFound.value = false;
68
-
103
+ const currentYear = new Date().getFullYear().toString();
69
104
  try {
70
105
  const [logsRes, siteInfo] = await Promise.all([
71
- getPatrolLogs<NFCPatrolLogListResponse>({
72
- page: 1,
73
- limit: 100,
74
- site,
75
- date: filters.date,
76
- routeId: filters.route,
77
- routeStartTime: filters.timeRange
78
- ? filters.timeRange.split(" - ")[0]
79
- : undefined,
80
- type: "month",
106
+ getPatrolLogs({
107
+ page: 1,
108
+ limit: 100,
109
+ site,
110
+ routeId: filters.route,
111
+ date: currentYear,
112
+ type: "month",
81
113
  }),
82
114
  getSiteById(site),
83
115
  ]);
@@ -93,7 +125,7 @@ export function useNFCPatrolMonthlyReport(
93
125
  address: buildAddress(siteInfo.address),
94
126
  },
95
127
  title: `Patrol Route Summary: ${routeName}`,
96
- rows: logs.map(mapLogToSummaryRow),
128
+ rows: mapLogsToMonthlyRows(logs),
97
129
  };
98
130
  } else {
99
131
  report.value = null;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "3.1.0",
5
+ "version": "3.1.2-staging.29",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "publishConfig": {
@@ -41,4 +41,5 @@ type TSiteCategory =
41
41
  | "shopping_mall"
42
42
  | "mix_development"
43
43
  | "industrial"
44
- | "co_working_co_living";
44
+ | "co_working"
45
+ | "co_living";
@@ -6,6 +6,10 @@ declare type TEquipment = {
6
6
  unitOfMeasurement: string;
7
7
  createdAt: string;
8
8
  updatedAt: string;
9
+ attachment?: string;
9
10
  };
10
11
 
11
- declare type TEquipmentCreate = Pick<TEquipment, "name" | "unitOfMeasurement">;
12
+ declare type TEquipmentCreate = Pick<
13
+ TEquipment,
14
+ "name" | "unitOfMeasurement" | "attachment"
15
+ >;
@@ -26,7 +26,7 @@ export interface NFCPatrolReportFilterOptions {
26
26
 
27
27
  export interface NFCPatrolReportLocation {
28
28
  name?: string;
29
- address?: string;
29
+ address?: string;
30
30
  }
31
31
 
32
32
  export interface NFCPatrolRouteSummary {
@@ -77,3 +77,17 @@ export interface NFCPatrolSummaryReport {
77
77
  title: string;
78
78
  rows: NFCPatrolReportSummaryRow[];
79
79
  }
80
+
81
+ export interface NFCPatrolMonthlyReportRow {
82
+ month: string;
83
+ checked: number;
84
+ checkedPercentage: number;
85
+ missed: number;
86
+ missedPercentage: number;
87
+ }
88
+
89
+ export interface NFCPatrolMonthlyReport {
90
+ location: NFCPatrolReportLocation;
91
+ title: string;
92
+ rows: NFCPatrolMonthlyReportRow[];
93
+ }