mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add methods to generate an ID based on address
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { ParkingRepositoryLoader } from "./ParkingRepositoryLoader";
|
||||
import { ParkingGetterSetterRepository } from "../../repositories/ParkingGetterSetterRepository";
|
||||
import { createHash } from "node:crypto";
|
||||
|
||||
export class ChapmanTimedApiBasedParkingRepositoryLoader implements ParkingRepositoryLoader {
|
||||
public static readonly id = "chapman-parking-loader";
|
||||
@@ -11,4 +12,21 @@ export class ChapmanTimedApiBasedParkingRepositoryLoader implements ParkingRepos
|
||||
async fetchAndUpdateParkingStructures(): Promise<void> {
|
||||
// TODO
|
||||
}
|
||||
|
||||
private normalizeAddress(address: string): string {
|
||||
return address
|
||||
.toLowerCase()
|
||||
.split(/\s+/)
|
||||
.filter(part => part.length > 0)
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
private generateId(address: string): string {
|
||||
const normalized = this.normalizeAddress(address);
|
||||
const hash = createHash('sha256')
|
||||
.update(normalized)
|
||||
.digest('hex');
|
||||
|
||||
return hash.substring(0, 12);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user