Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

2.3 KB
Raw Blame
import { Collection, EntityRepositoryType, type Opt, type Ref, defineEntity, p } from '@mikro-orm/core';
import { CollectionsRepository } from '../repositories/Collections.repository';
import { DbTimestampType } from '../types';
import { CollectionLabels } from './CollectionLabels.entity';
import { CollectionMembers } from './CollectionMembers.entity';
import { CollectionPlaces } from './CollectionPlaces.entity';
import { CollectionTours } from './CollectionTours.entity';
import { Users } from './Users.entity';

export class Collections {
  [EntityRepositoryType]?: CollectionsRepository;
  id!: number & Opt;
  owner!: Ref<Users>;
  owner_id!: number;
  name!: string;
  description?: string | null;
  color?: string | null = '#6366f1';
  icon?: string | null = 'Bookmark';
  cover_image?: string | null;
  links?: string | null;
  sort_order?: number | null = 0;
  created_at?: string | null;
  updated_at?: string | null;
  collection_labels_collection = new Collection<CollectionLabels>(this);
  collection_members_collection = new Collection<CollectionMembers>(this);
  collection_places_collection = new Collection<CollectionPlaces>(this);
  collection_tours_collection = new Collection<CollectionTours>(this);
}

export const CollectionsSchema = defineEntity({
  class: Collections,
  repository: () => CollectionsRepository,
  properties: {
    id: p.integer().primary(),
    owner: () => p.manyToOne(Users).ref().deleteRule('cascade').hidden().index('idx_collections_owner_id'),
    owner_id: p.integer().persist(false).index('idx_collections_owner_id'),
    name: p.text(),
    description: p.text().nullable(),
    color: p.text().nullable(),
    icon: p.text().nullable(),
    cover_image: p.text().nullable(),
    links: p.text().nullable(),
    sort_order: p.integer().nullable(),
    created_at: p.type(DbTimestampType).nullable().defaultRaw(`CURRENT_TIMESTAMP`),
    updated_at: p.type(DbTimestampType).nullable().defaultRaw(`CURRENT_TIMESTAMP`),
    collection_labels_collection: () => p.oneToMany(CollectionLabels).mappedBy('collection').hidden(),
    collection_members_collection: () => p.oneToMany(CollectionMembers).mappedBy('collection').hidden(),
    collection_places_collection: () => p.oneToMany(CollectionPlaces).mappedBy('collection').hidden(),
    collection_tours_collection: () => p.oneToMany(CollectionTours).mappedBy('collection').hidden(),
  },
});