feat: add domains, ideas, layouts, widgets API modules
- Add DomainsModule with full CRUD, search, and activity logging - Add IdeasModule with quick capture endpoint - Add LayoutsModule for user dashboard layouts - Add WidgetsModule for widget definitions (read-only) - Update ActivityService with domain/idea logging methods - Register all new modules in AppModule
This commit is contained in:
39
apps/api/src/widgets/widgets.controller.ts
Normal file
39
apps/api/src/widgets/widgets.controller.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
UseGuards,
|
||||
} from "@nestjs/common";
|
||||
import { WidgetsService } from "./widgets.service";
|
||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
||||
|
||||
/**
|
||||
* Controller for widget definition endpoints
|
||||
* All endpoints require authentication
|
||||
* Provides read-only access to available widget definitions
|
||||
*/
|
||||
@Controller("widgets")
|
||||
@UseGuards(AuthGuard)
|
||||
export class WidgetsController {
|
||||
constructor(private readonly widgetsService: WidgetsService) {}
|
||||
|
||||
/**
|
||||
* GET /api/widgets
|
||||
* List all available widget definitions
|
||||
* Returns only active widgets
|
||||
*/
|
||||
@Get()
|
||||
async findAll() {
|
||||
return this.widgetsService.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/widgets/:name
|
||||
* Get a widget definition by name
|
||||
* Useful for fetching widget configuration schemas
|
||||
*/
|
||||
@Get(":name")
|
||||
async findByName(@Param("name") name: string) {
|
||||
return this.widgetsService.findByName(name);
|
||||
}
|
||||
}
|
||||
13
apps/api/src/widgets/widgets.module.ts
Normal file
13
apps/api/src/widgets/widgets.module.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { WidgetsController } from "./widgets.controller";
|
||||
import { WidgetsService } from "./widgets.service";
|
||||
import { PrismaModule } from "../prisma/prisma.module";
|
||||
import { AuthModule } from "../auth/auth.module";
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule, AuthModule],
|
||||
controllers: [WidgetsController],
|
||||
providers: [WidgetsService],
|
||||
exports: [WidgetsService],
|
||||
})
|
||||
export class WidgetsModule {}
|
||||
59
apps/api/src/widgets/widgets.service.ts
Normal file
59
apps/api/src/widgets/widgets.service.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { PrismaService } from "../prisma/prisma.service";
|
||||
|
||||
/**
|
||||
* Service for managing widget definitions
|
||||
* Provides read-only access to available widget definitions
|
||||
*/
|
||||
@Injectable()
|
||||
export class WidgetsService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
/**
|
||||
* Get all active widget definitions
|
||||
*/
|
||||
async findAll() {
|
||||
return this.prisma.widgetDefinition.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
orderBy: {
|
||||
name: "asc",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a widget definition by name
|
||||
*/
|
||||
async findByName(name: string) {
|
||||
const widget = await this.prisma.widgetDefinition.findUnique({
|
||||
where: {
|
||||
name,
|
||||
},
|
||||
});
|
||||
|
||||
if (!widget) {
|
||||
throw new NotFoundException(`Widget definition with name '${name}' not found`);
|
||||
}
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a widget definition by ID
|
||||
*/
|
||||
async findOne(id: string) {
|
||||
const widget = await this.prisma.widgetDefinition.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!widget) {
|
||||
throw new NotFoundException(`Widget definition with ID ${id} not found`);
|
||||
}
|
||||
|
||||
return widget;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user