mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
fix(tags): keep a trip's tags when the member who created them deletes their account
The trip tags a deleted user created now pass to each trip's owner before the user row goes, so the tag and its place assignments no longer cascade away for everyone else on the trip.
This commit is contained in:
@@ -49,6 +49,8 @@ type PlaceTagsKyselyDB = Pick<DB, 'place_tags'>;
|
||||
/** `tags` alone, for the reads that name their columns. */
|
||||
type TagsKyselyDB = Pick<DB, 'tags'>;
|
||||
|
||||
type TagsWithTripsKyselyDB = Pick<DB, 'tags' | 'trips'>;
|
||||
|
||||
/**
|
||||
* `place_tags` joined to `places` for TP46 (`trips.service.ts::copy`'s
|
||||
* place-tags read). The `trip_id` the caller passes stays `number | string`
|
||||
@@ -239,6 +241,22 @@ export class TagsRepository extends TrekRepository<Tags> {
|
||||
return tag ? (toRow(tag) as TagRow) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hands the trip tags a user created to each trip's owner, so deleting the
|
||||
* user does not take a tag the whole trip uses (and its place_tags) with it.
|
||||
* The user's personal tags are left alone.
|
||||
*/
|
||||
async handTripTagsToTripOwners(userId: number): Promise<void> {
|
||||
await this.kysely<TagsWithTripsKyselyDB>()
|
||||
.updateTable('tags')
|
||||
.set((eb) => ({
|
||||
user_id: eb.selectFrom('trips').select('trips.user_id').whereRef('trips.id', '=', 'tags.trip_id'),
|
||||
}))
|
||||
.where('user_id', '=', userId)
|
||||
.where('trip_id', 'is not', null)
|
||||
.execute();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Plan 3c Task 4 (`PlacesService.create`/`applyUpdate`, PL5/PL12/PL13) —
|
||||
// `place_tags` writes. `PlaceTagsKyselyDB` above documents why Kysely.
|
||||
|
||||
Reference in New Issue
Block a user