feat(api): add create and update functionality for charge points with registration status
This commit is contained in:
@@ -14,7 +14,7 @@ export async function handleBootNotification(
|
||||
): Promise<BootNotificationResponse> {
|
||||
const db = useDrizzle()
|
||||
|
||||
await db
|
||||
const [cp] = await db
|
||||
.insert(chargePoint)
|
||||
.values({
|
||||
id: crypto.randomUUID(),
|
||||
@@ -27,7 +27,8 @@ export async function handleBootNotification(
|
||||
imsi: payload.imsi ?? null,
|
||||
meterType: payload.meterType ?? null,
|
||||
meterSerialNumber: payload.meterSerialNumber ?? null,
|
||||
registrationStatus: 'Accepted',
|
||||
// New, unknown devices start as Pending — admin must manually accept them
|
||||
registrationStatus: 'Pending',
|
||||
heartbeatInterval: DEFAULT_HEARTBEAT_INTERVAL,
|
||||
lastBootNotificationAt: new Date(),
|
||||
})
|
||||
@@ -42,20 +43,22 @@ export async function handleBootNotification(
|
||||
imsi: payload.imsi ?? null,
|
||||
meterType: payload.meterType ?? null,
|
||||
meterSerialNumber: payload.meterSerialNumber ?? null,
|
||||
registrationStatus: 'Accepted',
|
||||
// Do NOT override registrationStatus — preserve whatever the admin set
|
||||
heartbeatInterval: DEFAULT_HEARTBEAT_INTERVAL,
|
||||
lastBootNotificationAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
})
|
||||
.returning()
|
||||
|
||||
ctx.isRegistered = true
|
||||
const status = cp.registrationStatus
|
||||
ctx.isRegistered = status === 'Accepted'
|
||||
|
||||
console.log(`[OCPP] BootNotification accepted: ${ctx.chargePointIdentifier}`)
|
||||
console.log(`[OCPP] BootNotification ${ctx.chargePointIdentifier} status=${status}`)
|
||||
|
||||
return {
|
||||
currentTime: new Date().toISOString(),
|
||||
interval: DEFAULT_HEARTBEAT_INTERVAL,
|
||||
status: 'Accepted',
|
||||
status,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user