Files
TREK/server/src/db/entities/CollectionPlaceRatings.entity.ts
T
Maurice 783c98f41e feat(places): one vote per person across copies, copies stay in step
A vote belongs to its person: cast or taken back on one copy of a place, it
lands on every copy of that place in the lists and trips the person may vote
on, in one transaction. A pass on the first start carries the existing votes
over, and whoever joins a list or a trip brings their latest vote onto its
copies of the places they voted on elsewhere, as inserts that never
overwrite.

An edit of the general facts of a place (name, description, address,
position, category, picture, website, phone) on a trip place or a saved
place is made on every other copy of it the editor may edit, with a history
entry per copy and an announcement per trip and list. Notes, tags, status
and votes stay with each copy, and a copy the editor may not edit is
skipped. REST and MCP take the same path; a token reaches only the kinds of
copies it holds write scope for.

The entry rating names its voters, the library list filters by a lowest
average vote and sorts by rating, and the tab counts honour the filter.
2026-11-29 23:36:43 +00:00

34 lines
1.5 KiB
TypeScript

import { EntityRepositoryType, type Opt, type Ref, defineEntity, p } from '@mikro-orm/core';
import { CollectionPlaceRatingsRepository } from '../repositories/CollectionPlaceRatings.repository';
import { DbTimestampType } from '../types';
import { CollectionPlaces } from './CollectionPlaces.entity';
import { Users } from './Users.entity';
export class CollectionPlaceRatings {
[EntityRepositoryType]?: CollectionPlaceRatingsRepository;
id!: number & Opt;
collectionPlace!: Ref<CollectionPlaces>;
collection_place_id!: number;
user!: Ref<Users>;
user_id!: number;
rating!: number;
created_at?: string | null;
updated_at?: string | null;
}
export const CollectionPlaceRatingsSchema = defineEntity({
class: CollectionPlaceRatings,
repository: () => CollectionPlaceRatingsRepository,
uniques: [{ properties: ['collectionPlace', 'user'] }],
properties: {
id: p.integer().primary(),
collectionPlace: () => p.manyToOne(CollectionPlaces).ref().deleteRule('cascade').hidden().index('idx_collection_place_ratings_place'),
collection_place_id: p.integer().persist(false).index('idx_collection_place_ratings_place'),
user: () => p.manyToOne(Users).ref().deleteRule('cascade').hidden().index('idx_collection_place_ratings_user_id'),
user_id: p.integer().persist(false).index('idx_collection_place_ratings_user_id'),
rating: p.integer(),
created_at: p.type(DbTimestampType).nullable().defaultRaw(`CURRENT_TIMESTAMP`),
updated_at: p.type(DbTimestampType).nullable(),
},
});