79 lines
3.0 KiB
TypeScript
79 lines
3.0 KiB
TypeScript
|
|
import {
|
||
|
|
Body,
|
||
|
|
Controller,
|
||
|
|
Get,
|
||
|
|
Post,
|
||
|
|
Query,
|
||
|
|
Req,
|
||
|
|
UseGuards,
|
||
|
|
} from '@nestjs/common';
|
||
|
|
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||
|
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||
|
|
import { AcceptOrganizationInviteDto } from './dto/accept-organization-invite.dto';
|
||
|
|
import { CreateLinkRequestDto } from './dto/create-link-request.dto';
|
||
|
|
import { InviteOrganizationDto } from './dto/invite-organization.dto';
|
||
|
|
import { PreviewOrganizationInviteDto } from './dto/preview-organization-invite.dto';
|
||
|
|
import { OrganizationService } from './organization.service';
|
||
|
|
|
||
|
|
@ApiTags('organizations')
|
||
|
|
@ApiBearerAuth('JWT-auth')
|
||
|
|
@Controller('organizations')
|
||
|
|
export class OrganizationController {
|
||
|
|
constructor(private readonly organizationService: OrganizationService) {}
|
||
|
|
|
||
|
|
@Get('invitations/preview')
|
||
|
|
@ApiOperation({ summary: 'Preview organization invite by token (public)' })
|
||
|
|
previewInvite(@Query() query: PreviewOrganizationInviteDto) {
|
||
|
|
return this.organizationService.previewInvite(query.token);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Post('invitations/accept')
|
||
|
|
@ApiOperation({ summary: 'Accept organization invite and create/link counterpart org (public)' })
|
||
|
|
acceptInvite(@Body() dto: AcceptOrganizationInviteDto) {
|
||
|
|
return this.organizationService.acceptInvite(dto);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get('search')
|
||
|
|
@UseGuards(JwtAuthGuard)
|
||
|
|
@ApiOperation({
|
||
|
|
summary: 'Search counterpart organizations (active subscription only)',
|
||
|
|
})
|
||
|
|
search(
|
||
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
||
|
|
@Query('q') q = '',
|
||
|
|
) {
|
||
|
|
const organizationId = this.organizationService.getOrganizationIdFromUser(req.user);
|
||
|
|
return this.organizationService.searchCounterpartOrganizations(req.user.id, organizationId, q);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get('links')
|
||
|
|
@UseGuards(JwtAuthGuard)
|
||
|
|
@ApiOperation({ summary: 'List counterpart links and invitations for current org' })
|
||
|
|
list(@Req() req: { user: { id: string; organizationId?: string } }) {
|
||
|
|
const organizationId = this.organizationService.getOrganizationIdFromUser(req.user);
|
||
|
|
return this.organizationService.list(req.user.id, organizationId);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Post('links')
|
||
|
|
@UseGuards(JwtAuthGuard)
|
||
|
|
@ApiOperation({ summary: 'Create pending link request to an existing subscribed counterpart org' })
|
||
|
|
createLinkRequest(
|
||
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
||
|
|
@Body() dto: CreateLinkRequestDto,
|
||
|
|
) {
|
||
|
|
const organizationId = this.organizationService.getOrganizationIdFromUser(req.user);
|
||
|
|
return this.organizationService.createLinkRequest(req.user.id, organizationId, dto);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Post('invite')
|
||
|
|
@UseGuards(JwtAuthGuard)
|
||
|
|
@ApiOperation({ summary: 'Create invite link for owner of not-yet-subscribed counterpart org' })
|
||
|
|
inviteOrganization(
|
||
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
||
|
|
@Body() dto: InviteOrganizationDto,
|
||
|
|
) {
|
||
|
|
const organizationId = this.organizationService.getOrganizationIdFromUser(req.user);
|
||
|
|
return this.organizationService.inviteOrganization(req.user.id, organizationId, dto);
|
||
|
|
}
|
||
|
|
}
|