Skip to content

Commit 1884cd2

Browse files
committed
fix: temp demo fixes
1 parent 59ec132 commit 1884cd2

6 files changed

Lines changed: 142 additions & 21 deletions

File tree

components/formComponents/CreateAlarmForm/CreateAlarmForm.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ const CreateAlarmForm = () => {
3131
setError(result.error);
3232
}
3333

34-
const now = new Date();
35-
const maxDate = now.toISOString().slice(0, 16);
36-
3734
return (
3835
<form action={handleSubmit} className="space-y-4">
3936
{error && <Alert variant="error">{error}</Alert>}
@@ -87,8 +84,6 @@ const CreateAlarmForm = () => {
8784
name="incidentTime"
8885
type="datetime-local"
8986
required
90-
max={maxDate}
91-
helperText="Cannot be in the future"
9287
/>
9388

9489
<div className="flex justify-end gap-2 pt-2">

components/formComponents/VerifyAlarmForm/actions.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import {
1111
import { createVerification } from "@/api/verification/verification.service";
1212
import { createEvidence } from "@/api/evidence/evidence.repository";
1313
import { createAlarmLog } from "@/api/alarm/alarm.repository";
14-
import {
15-
calculateDistanceMeters,
16-
isWithinGeoRadius,
17-
} from "@/lib/geo/calculate-distance";
14+
// Distance limit from alarm/verification lat-long (commented out for now)
15+
// import {
16+
// calculateDistanceMeters,
17+
// isWithinGeoRadius,
18+
// } from "@/lib/geo/calculate-distance";
1819
import { uploadEvidenceFile } from "@/api/evidence/upload-file";
1920
import { isAllowedEvidenceFile } from "@/lib/validation/evidence";
2021

@@ -72,11 +73,14 @@ export const submitVerification = async (
7273

7374
const remarks = (formData.get("remarks") as string) || null;
7475

75-
const distance = calculateDistanceMeters(
76-
{ latitude: alarm.latitude, longitude: alarm.longitude },
77-
{ latitude, longitude },
78-
);
79-
const geoMismatch = !isWithinGeoRadius(distance);
76+
// Distance limit calculation from alarm and verification lat/long (commented out)
77+
// const distance = calculateDistanceMeters(
78+
// { latitude: alarm.latitude, longitude: alarm.longitude },
79+
// { latitude, longitude },
80+
// );
81+
// const geoMismatch = !isWithinGeoRadius(distance);
82+
const distance = 0;
83+
const geoMismatch = false;
8084

8185
const verification = await createVerification({
8286
alarmId,

lib/validation/alarm-schema.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,5 @@ export const createAlarmSchema = z.object({
3333
chainageValue: chainageValueSchema,
3434
alarmType: alarmTypeSchema,
3535
criticality: criticalitySchema,
36-
incidentTime: z
37-
.date()
38-
.refine(
39-
(d) => d.getTime() <= Date.now(),
40-
"Incident time cannot be in the future",
41-
),
36+
incidentTime: z.date(),
4237
});

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"build": "prisma generate && next build",
88
"start": "next start",
99
"lint": "eslint",
10-
"seed": "npx prisma db seed"
10+
"seed": "npx prisma db seed",
11+
"delete-all-alarms": "npx tsx scripts/delete-all-alarms.ts",
12+
"replace-chainages": "npx tsx scripts/replace-chainages.ts"
1113
},
1214
"dependencies": {
1315
"@azure/storage-blob": "^12.31.0",

scripts/delete-all-alarms.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Delete all alarms and their related records (assignments, verifications,
3+
* evidence, logs) from the database. Safe to run against Azure DB.
4+
* Usage: npx tsx scripts/delete-all-alarms.ts
5+
*/
6+
import "dotenv/config";
7+
import { PrismaPg } from "@prisma/adapter-pg";
8+
import { PrismaClient } from "../lib/generated/prisma";
9+
10+
const connectionString = process.env.DATABASE_URL;
11+
if (!connectionString) {
12+
console.error("DATABASE_URL is not set.");
13+
process.exit(1);
14+
}
15+
16+
const adapter = new PrismaPg({ connectionString });
17+
const prisma = new PrismaClient({ adapter });
18+
19+
async function main() {
20+
// Delete child records first (they reference Alarm), then alarms
21+
const [assignments, verifications, evidences, logs] = await Promise.all([
22+
prisma.alarmAssignment.deleteMany({}),
23+
prisma.verification.deleteMany({}),
24+
prisma.evidence.deleteMany({}),
25+
prisma.alarmLog.deleteMany({}),
26+
]);
27+
const alarms = await prisma.alarm.deleteMany({});
28+
29+
console.log("Deleted:");
30+
console.log(" AlarmAssignment:", assignments.count);
31+
console.log(" Verification:", verifications.count);
32+
console.log(" Evidence:", evidences.count);
33+
console.log(" AlarmLog:", logs.count);
34+
console.log(" Alarm:", alarms.count);
35+
console.log("All alarms and related data have been removed.");
36+
}
37+
38+
main()
39+
.catch((e) => {
40+
console.error(e);
41+
process.exit(1);
42+
})
43+
.finally(() => prisma.$disconnect());

scripts/replace-chainages.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Remove all chainage ranges and user mappings, then insert new chainage ranges.
3+
* Usage: npx tsx scripts/replace-chainages.ts
4+
*/
5+
import "dotenv/config";
6+
import { PrismaPg } from "@prisma/adapter-pg";
7+
import { PrismaClient } from "../lib/generated/prisma";
8+
9+
const connectionString = process.env.DATABASE_URL;
10+
if (!connectionString) {
11+
console.error("DATABASE_URL is not set.");
12+
process.exit(1);
13+
}
14+
15+
/** New chainage ranges: From -> To (exact table; duplicates deduped on insert). */
16+
const RANGES: [number, number][] = [
17+
[118, 188],
18+
[188, 251],
19+
[252, 307],
20+
[118, 204],
21+
[204, 307],
22+
[118, 204],
23+
[204, 307],
24+
[118, 126],
25+
[126, 137],
26+
[137, 148],
27+
[148, 159],
28+
[159, 170],
29+
[170, 179],
30+
[179, 188],
31+
[188, 199],
32+
[199, 209],
33+
[209, 220],
34+
[220, 230],
35+
[230, 240],
36+
[240, 251],
37+
[188, 251],
38+
[252, 262],
39+
[262, 271],
40+
[271, 281],
41+
[281, 291],
42+
[291, 299],
43+
[299, 307],
44+
[252, 307],
45+
];
46+
47+
const adapter = new PrismaPg({ connectionString });
48+
const prisma = new PrismaClient({ adapter });
49+
50+
async function main() {
51+
const chainageUsers = await prisma.chainageUser.deleteMany({});
52+
const chainages = await prisma.chainage.deleteMany({});
53+
54+
console.log("Deleted:");
55+
console.log(" ChainageUser:", chainageUsers.count);
56+
console.log(" Chainage:", chainages.count);
57+
58+
const uniqueRanges = Array.from(
59+
new Map(RANGES.map(([s, e]) => [`${s}-${e}`, [s, e] as [number, number]])).values(),
60+
).sort((a, b) => a[0] - b[0] || a[1] - b[1]);
61+
62+
for (const [startKm, endKm] of uniqueRanges) {
63+
await prisma.chainage.create({
64+
data: {
65+
label: `${startKm}-${endKm}`,
66+
startKm,
67+
endKm,
68+
latitude: null,
69+
longitude: null,
70+
},
71+
});
72+
}
73+
74+
console.log("Inserted", uniqueRanges.length, "chainage ranges (no lat/long).");
75+
}
76+
77+
main()
78+
.catch((e) => {
79+
console.error(e);
80+
process.exit(1);
81+
})
82+
.finally(() => prisma.$disconnect());

0 commit comments

Comments
 (0)