Google Maps Bug
This commit is contained in:
@@ -45,14 +45,37 @@ export class StationsRepository {
|
||||
return this.mapCacheRow(result.rows[0]);
|
||||
}
|
||||
|
||||
async saveStation(userId: string, placeId: string, data?: { nickname?: string; notes?: string; isFavorite?: boolean }): Promise<SavedStation> {
|
||||
async saveStation(
|
||||
userId: string,
|
||||
placeId: string,
|
||||
data?: {
|
||||
nickname?: string;
|
||||
notes?: string;
|
||||
isFavorite?: boolean;
|
||||
has93Octane?: boolean;
|
||||
has93OctaneEthanolFree?: boolean;
|
||||
}
|
||||
): Promise<SavedStation> {
|
||||
const query = `
|
||||
INSERT INTO saved_stations (user_id, place_id, nickname, notes, is_favorite)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
INSERT INTO saved_stations (
|
||||
user_id,
|
||||
place_id,
|
||||
nickname,
|
||||
notes,
|
||||
is_favorite,
|
||||
has_93_octane,
|
||||
has_93_octane_ethanol_free
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
ON CONFLICT (user_id, place_id) DO UPDATE
|
||||
SET nickname = COALESCE($3, saved_stations.nickname),
|
||||
notes = COALESCE($4, saved_stations.notes),
|
||||
is_favorite = COALESCE($5, saved_stations.is_favorite),
|
||||
has_93_octane = COALESCE($6, saved_stations.has_93_octane),
|
||||
has_93_octane_ethanol_free = CASE
|
||||
WHEN $6 IS NOT NULL AND $6 = false THEN false
|
||||
ELSE COALESCE($7, saved_stations.has_93_octane_ethanol_free)
|
||||
END,
|
||||
updated_at = NOW()
|
||||
RETURNING *
|
||||
`;
|
||||
@@ -62,12 +85,58 @@ export class StationsRepository {
|
||||
placeId,
|
||||
data?.nickname,
|
||||
data?.notes,
|
||||
data?.isFavorite || false
|
||||
data?.isFavorite ?? false,
|
||||
data?.has93Octane ?? false,
|
||||
data?.has93OctaneEthanolFree ?? false
|
||||
]);
|
||||
|
||||
return this.mapSavedRow(result.rows[0]);
|
||||
}
|
||||
|
||||
async updateSavedStation(
|
||||
userId: string,
|
||||
placeId: string,
|
||||
data: {
|
||||
nickname?: string;
|
||||
notes?: string;
|
||||
isFavorite?: boolean;
|
||||
has93Octane?: boolean;
|
||||
has93OctaneEthanolFree?: boolean;
|
||||
}
|
||||
): Promise<SavedStation | null> {
|
||||
const query = `
|
||||
UPDATE saved_stations
|
||||
SET
|
||||
nickname = COALESCE($3, nickname),
|
||||
notes = COALESCE($4, notes),
|
||||
is_favorite = COALESCE($5, is_favorite),
|
||||
has_93_octane = COALESCE($6, has_93_octane),
|
||||
has_93_octane_ethanol_free = CASE
|
||||
WHEN $6 IS NOT NULL AND $6 = false THEN false
|
||||
ELSE COALESCE($7, has_93_octane_ethanol_free)
|
||||
END,
|
||||
updated_at = NOW()
|
||||
WHERE user_id = $1 AND place_id = $2
|
||||
RETURNING *
|
||||
`;
|
||||
|
||||
const result = await this.pool.query(query, [
|
||||
userId,
|
||||
placeId,
|
||||
data.nickname,
|
||||
data.notes,
|
||||
data.isFavorite,
|
||||
data.has93Octane,
|
||||
data.has93OctaneEthanolFree
|
||||
]);
|
||||
|
||||
if (result.rows.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.mapSavedRow(result.rows[0]);
|
||||
}
|
||||
|
||||
async getUserSavedStations(userId: string): Promise<SavedStation[]> {
|
||||
const query = `
|
||||
SELECT * FROM saved_stations
|
||||
@@ -107,11 +176,14 @@ export class StationsRepository {
|
||||
id: row.id,
|
||||
userId: row.user_id,
|
||||
stationId: row.place_id,
|
||||
placeId: row.place_id,
|
||||
nickname: row.nickname,
|
||||
notes: row.notes,
|
||||
isFavorite: row.is_favorite,
|
||||
has93Octane: row.has_93_octane ?? false,
|
||||
has93OctaneEthanolFree: row.has_93_octane_ethanol_free ?? false,
|
||||
createdAt: row.created_at,
|
||||
updatedAt: row.updated_at
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user