AGENT SKILL

nestjs-api

Create NestJS API endpoints with controllers, services, and modules. Use when adding API routes, backend features, validation, or any backend code change. This is the backend framework — every API change should follow NestJS patterns.

适用职业开发工程师
使用场景后端与接口
License 许可
AGPL-3.0
最近更新
2026-11-05
Stars
★ 42
Forks
9

01 前言 Front Matter

name
nestjs-api
description
Create NestJS API endpoints with controllers, services, and modules. Use when adding API routes, backend features, validation, or any backend code change. This is the backend framework — every API change should follow NestJS patterns.

03 SKILL.md 正文

NestJS API Development

The backend uses NestJS with the Fastify adapter. All routes are prefixed with /api (set in main.ts). For real-time features (live updates, chat, server push) see the websockets skill.

Module pattern — every feature needs 3 files

1. Module

import { Module } from "@nestjs/common"
import { TasksController } from "./tasks.controller"
import { TasksService } from "./tasks.service"

@Module({
  controllers: [TasksController],
  providers: [TasksService],
})
export class TasksModule {}

2. Controller (handles HTTP)

import { Controller, Get, Post, Put, Delete, Param, Body, Query, ParseIntPipe, BadRequestException } from "@nestjs/common"
import { TasksService } from "./tasks.service"

@Controller("tasks")
export class TasksController {
  constructor(private readonly tasksService: TasksService) {}

  @Get()
  findAll(@Query("status") status?: string) {
    return this.tasksService.findAll(status)
  }

  @Get(":id")
  findOne(@Param("id", ParseIntPipe) id: number) {
    return this.tasksService.findOne(id)
  }

  @Post()
  create(@Body() body: { title: string; description?: string }) {
    if (!body.title) throw new BadRequestException("Title is required")
    return this.tasksService.create(body.title, body.description)
  }

  @Put(":id")
  update(@Param("id", ParseIntPipe) id: number, @Body() body: { title?: string; description?: string; status?: string }) {
    return this.tasksService.update(id, body)
  }

  @Delete(":id")
  remove(@Param("id", ParseIntPipe) id: number) {
    this.tasksService.remove(id)
    return { ok: true }
  }
}

3. Service (business logic + database)

import { Injectable, NotFoundException } from "@nestjs/common"
import { DatabaseService } from "../database/database.service"

@Injectable()
export class TasksService {
  constructor(private readonly db: DatabaseService) {}

  findAll(status?: string) {
    if (status) {
      return this.db.queryAll("SELECT * FROM tasks WHERE status = ? ORDER BY created_at DESC", [status])
    }
    return this.db.queryAll("SELECT * FROM tasks ORDER BY created_at DESC")
  }

  findOne(id: number) {
    const task = this.db.queryOne("SELECT * FROM tasks WHERE id = ?", [id])
    if (!task) throw new NotFoundException(`Task ${id} not found`)
    return task
  }

  create(title: string, description?: string) {
    const result = this.db.run("INSERT INTO tasks (title, description) VALUES (?, ?)", [title, description ?? null])
    return this.findOne(result.lastInsertRowid as number)
  }

  update(id: number, data: { title?: string; description?: string; status?: string }) {
    this.findOne(id)
    this.db.run(
      "UPDATE tasks SET title = COALESCE(?, title), description = COALESCE(?, description), status = COALESCE(?, status), updated_at = datetime('now') WHERE id = ?",
      [data.title ?? null, data.description ?? null, data.status ?? null, id],
    )
    return this.findOne(id)
  }

  remove(id: number) {
    this.findOne(id)
    this.db.run("DELETE FROM tasks WHERE id = ?", [id])
  }
}

Name every column an update may touch — never build SQL from the request body's keys, which lets a client write any column. Register the module in app.module.ts (web-app).

DatabaseService methods

queryAll, queryOne, run and exec are the whole API — the sqlite skill has their signatures and transactions.

Key decorators

  • @Controller("path") — route prefix
  • @Get(), @Post(), @Put(), @Delete() — HTTP methods
  • @Param("name", ParseIntPipe) — URL params with type coercion
  • @Body() — request body
  • @Query("name") — query string params

Exceptions

  • NotFoundException → 404
  • BadRequestException → 400
  • UnauthorizedException → 401
  • ForbiddenException → 403
  • ConflictException → 409

04 同仓库更多 Skills

SimaDevelopment
SimaDevelopment/opsiforce

figma-use

**MANDATORY prerequisite** — you MUST invoke this skill BEFORE every `use_figma` tool call. NEVER call `use_figma` directly without loading this skill first. Skipping it causes common, hard-to-debug failures. Trigger whenever the user wants to perform a write action or a unique read action that requires JavaScript execution in the Figma file context — e.g. create/edit/delete nodes, set up variables or tokens, build components and variants, modify auto-layout or fills, bind variables to properties, or inspect file structure programmatically.

开发工程师设计师Skill与智能体开发
★ 42
SimaDevelopment
SimaDevelopment/opsiforce

figma-use-slides

This skill helps agents use Figma's use_figma MCP tool in the Slides context. Can be used alongside figma-use which has foundational context for using the use_figma tool.

设计师演示文稿Skill与智能体开发
★ 42
SimaDevelopment
SimaDevelopment/opsiforce

figma-use-motion

Motion / animation context for the `use_figma` MCP tool — animating Figma nodes via manual keyframes, animation styles, easing, and timeline duration. Load alongside figma-use whenever a task involves adding, editing, or inspecting animation on a node.

设计师Skill与智能体开发
★ 42
SimaDevelopment
SimaDevelopment/opsiforce

figma-use-figjam

This skill helps agents use Figma's use_figma MCP tool in the FigJam context. Can be used alongside figma-use which has foundational context for using the use_figma tool.

设计师Skill与智能体开发
★ 42
SimaDevelopment
SimaDevelopment/opsiforce

figma-swiftui

SwiftUI ↔ Figma translation. Use whenever the user mentions Swift, SwiftUI, iOS, iPhone, or iPad — in EITHER direction — translating a Figma design into SwiftUI (design → code), or pushing SwiftUI views / screens / tokens back into a Figma file (code → design). Triggers on phrases like 'implement this Figma design in SwiftUI', 'build this screen in Swift', 'push this SwiftUI view to Figma', 'mirror my Swift code in a Figma file', or whenever a Figma URL appears alongside `.swift` files / an `.xcodeproj`. Routes to a direction-specific reference doc; loads alongside `figma-use` for the code → design path.

设计师
★ 42
SimaDevelopment
SimaDevelopment/opsiforce

figma-shaders

**MANDATORY prerequisite** — load this skill before calling `create_shader` or `update_shader`. Use when the user asks to create, author, change, fix, or iterate on a shader effect, shader fill, custom effect, custom fill, or procedural shader in Figma.

设计师
★ 42