mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 18:54:17 +00:00
feat(journey): create draft entries from gallery photos
Groups the gallery photos on no entry by local day, then by time gap and distance, names each group through the geocoder (capped per preview, with the country or the day as fallback) and writes the groups the traveller keeps as draft entries with their photos in one transaction. Photos put on an entry meanwhile or named twice are left out and reported; existing entries are never touched. REST routes under /api/journeys/:id/entries/from-photos and the MCP tools preview_journey_entries_from_photos and create_journey_entries_from_photos share one service and the journey edit right (#1920).
This commit is contained in:
@@ -43,6 +43,18 @@ export interface JourneyPublicAssetValidationRow {
|
||||
journey_owner_id: number;
|
||||
}
|
||||
|
||||
/** A gallery photo on no entry, as {@link JourneyPhotosRepository.listOffEntries} reads it. */
|
||||
export interface JourneyPhotoOffEntryRow {
|
||||
/** The gallery row (journey photo id). */
|
||||
id: number;
|
||||
photo_id: number;
|
||||
/** ISO capture instant; null when the photo does not know it (an empty value reads as null). */
|
||||
taken_at: string | null;
|
||||
lat: number | null;
|
||||
lng: number | null;
|
||||
media_type: string;
|
||||
}
|
||||
|
||||
/** `GALLERY_SELECT`'s exact column list (`journey-domain.service.ts`'s module const), aliased `gp`/`tp` — shared by every gallery-shaped read below. */
|
||||
const GALLERY_COLUMNS = [
|
||||
'gp.id',
|
||||
@@ -420,6 +432,41 @@ export class JourneyPhotosRepository extends TrekRepository<JourneyPhotos> {
|
||||
return row as GalleryPhoto | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* The gallery photos of a journey that sit on no entry (of any kind, a
|
||||
* suggestion included), with when and where they were taken: what the
|
||||
* journal can still make entries of (#1920). A photo without a capture
|
||||
* time comes back too, with `taken_at` null, so the caller can count it.
|
||||
* In gallery-row order, which the caller re-sorts by capture time.
|
||||
*/
|
||||
async listOffEntries(journeyId: number): Promise<JourneyPhotoOffEntryRow[]> {
|
||||
const rows = await this.kysely<GalleryKyselyDB>()
|
||||
.selectFrom('journey_photos as gp')
|
||||
.innerJoin('trek_photos as tp', 'tp.id', 'gp.photo_id')
|
||||
.select(['gp.id', 'gp.photo_id', 'tp.taken_at', 'tp.lat', 'tp.lng', 'tp.media_type'])
|
||||
.where('gp.journey_id', '=', journeyId)
|
||||
.where((eb) =>
|
||||
eb.not(
|
||||
eb.exists(
|
||||
eb
|
||||
.selectFrom('journey_entry_photos as jep')
|
||||
.select('jep.entry_id')
|
||||
.whereRef('jep.journey_photo_id', '=', 'gp.id'),
|
||||
),
|
||||
),
|
||||
)
|
||||
.orderBy('gp.id', 'asc')
|
||||
.execute();
|
||||
return rows.map((row) => ({
|
||||
id: row.id,
|
||||
photo_id: row.photo_id,
|
||||
taken_at: row.taken_at || null,
|
||||
lat: row.lat ?? null,
|
||||
lng: row.lng ?? null,
|
||||
media_type: row.media_type,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* JG19 — `getJourneyFull`'s gallery read, folding in `GALLERY_CHRONOLOGICAL_ORDER`
|
||||
* (R1). Task 1's report left this raw for this task to finish (its own
|
||||
|
||||
Reference in New Issue
Block a user