mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
782e613506
- GPX files drop onto the map or a day; the import lands on that day - wanderer connection per user in Integrations; the workspace offers the user's own trails only, behind an admin switch under the Tours addon - wanderer difficulty is stored on the SAC scale (T1 to T3), backfilled - a GPX or wanderer import can be planned as an editable tour, either in place (the recorded track is kept and can be restored) or as a new tour that remembers the import it came from - rails, rows and detail dialog follow the plan sidebar's cards and badges - admin addon shelves with more than one row fold, collapsed by default - reverse-geocoded waypoint names are cached on the device
61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
import { ADDON_IDS } from '../../addons';
|
|
import type { User } from '../../types';
|
|
import { AddonGuard } from '../addons/addon.guard';
|
|
import { RequireAddon } from '../addons/require-addon.decorator';
|
|
import { getClientIp } from '../audit/client-ip';
|
|
import { CurrentUser } from '../auth-core/current-user.decorator';
|
|
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
|
|
import { ResponseContract } from '../common/response-contract';
|
|
import { WandererEnabledGuard } from './wanderer-enabled.guard';
|
|
import { WandererSettingsDto, WandererTestDto } from './wanderer.dto';
|
|
import { WandererService } from './wanderer.service';
|
|
import { Body, Controller, Delete, Get, HttpCode, Post, Put, Req, UseGuards } from '@nestjs/common';
|
|
import {
|
|
successResponseSchema,
|
|
wandererConnectionSchema,
|
|
wandererSaveResponseSchema,
|
|
wandererTestResponseSchema,
|
|
} from '@trek/shared';
|
|
|
|
import type { Request } from 'express';
|
|
|
|
/**
|
|
* `/api/integrations/wanderer`: the caller's own wanderer connection. It belongs
|
|
* to the Tours addon, which is what it feeds, and only ever touches the
|
|
* caller's own row. The test answers 200 with the reason in the body, since a
|
|
* form showing someone their own typo needs a field to render, not an error.
|
|
*/
|
|
@Controller('api/integrations/wanderer')
|
|
@UseGuards(AddonGuard, JwtAuthGuard, WandererEnabledGuard)
|
|
@RequireAddon(ADDON_IDS.TOURS, 'Tours')
|
|
export class WandererController {
|
|
constructor(private readonly wanderer: WandererService) {}
|
|
|
|
@Get('settings')
|
|
@ResponseContract(wandererConnectionSchema)
|
|
getSettings(@CurrentUser() user: User) {
|
|
return this.wanderer.getConnection(user.id);
|
|
}
|
|
|
|
@Put('settings')
|
|
@ResponseContract(wandererSaveResponseSchema)
|
|
saveSettings(@CurrentUser() user: User, @Body() body: WandererSettingsDto, @Req() req: Request) {
|
|
return this.wanderer.save(user.id, body, getClientIp(req));
|
|
}
|
|
|
|
@Delete('settings')
|
|
@HttpCode(200)
|
|
@ResponseContract(successResponseSchema)
|
|
async disconnect(@CurrentUser() user: User, @Req() req: Request) {
|
|
await this.wanderer.disconnect(user.id, getClientIp(req));
|
|
return { success: true as const };
|
|
}
|
|
|
|
@Post('test')
|
|
@HttpCode(200)
|
|
@ResponseContract(wandererTestResponseSchema)
|
|
test(@CurrentUser() user: User, @Body() body: WandererTestDto) {
|
|
return this.wanderer.test(user.id, body);
|
|
}
|
|
}
|