用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/UitbreidenOS/UitKit --skill nestjs命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
Guidelines and instructions for Agent execution state rollback rules
Guidelines and instructions for Agent execution step counters limits
Guidelines and instructions for Agent execution timeout limits setups
基于 SOC 职业分类
| name | nestjs |
| description | NestJS modules, controllers, services, guards, interceptors, TypeORM, CQRS, microservices, Jest testing |
@nestjs/swaggersrc/
├── app.module.ts # Root module
├── main.ts # Bootstrap
├── common/
│ ├── decorators/
│ ├── filters/
│ ├── guards/
│ ├── interceptors/
│ └── pipes/
├── config/
│ └── configuration.ts # ConfigService setup
└── modules/
└── users/
├── users.module.ts
├── users.controller.ts
├── users.service.ts
├── dto/
│ ├── create-user.dto.ts
│ └── update-user.dto.ts
├── entities/
│ └── user.entity.ts
└── users.service.spec.ts
// main.ts
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
import { ValidationPipe } from '@nestjs/common'
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
async function bootstrap() {
const app = await NestFactory.create(AppModule)
app.useGlobalPipes(new ValidationPipe({
whitelist: true, // strip unknown fields
forbidNonWhitelisted: true,
transform: true, // auto-transform payloads to DTO classes
}))
const config = new DocumentBuilder()
.setTitle('API')
.setVersion('1.0')
.addBearerAuth()
.build()
SwaggerModule.setup('docs', app, SwaggerModule.createDocument(app, config))
await app.listen(3000)
}
bootstrap()
// users.module.ts
@Module({
imports: [TypeOrmModule.forFeature([User]), JwtModule.register({})],
controllers: [UsersController],
providers: [UsersService],
exports: [UsersService],
})
export class UsersModule {}
// users.controller.ts
@ApiTags('users')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('users')
export class UsersController {
constructor(private readonly usersService: UsersService) {}
@Post()
@HttpCode(HttpStatus.CREATED)
create(@Body() dto: CreateUserDto): Promise<UserResponseDto> {
return this.usersService.create(dto)
}
@Get(':id')
findOne(@Param(, ) : ): <> {
..(id)
}
}
()
{
() {}
(: ): <> {
exists = ..({ : dto. })
(exists) ()
user = ..({
...dto,
: bcrypt.(dto., ),
})
..(user)
}
(: ): <> {
user = ..({ id })
(!user) ()
user
}
}
// dto/create-user.dto.ts
import { IsEmail, IsString, MinLength, IsOptional } from 'class-validator'
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
export class CreateUserDto {
@ApiProperty({ example: 'user@example.com' })
@IsEmail()
email: string
@ApiProperty({ minLength: 8 })
@IsString()
@MinLength(8)
password: string
@ApiPropertyOptional()
@IsOptional()
@IsString()
name?: string
}
// common/guards/jwt-auth.guard.ts
@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {
handleRequest<T>(err: Error, user: T, info: Error): T {
if (err || !user) {
throw err || new UnauthorizedException(info?.message)
}
return user
}
}
// common/guards/roles.guard.ts
@Injectable()
export class RolesGuard implements CanActivate {
constructor(private reflector: Reflector) {}
canActivate(context: ExecutionContext): boolean {
const roles = this.reflector.getAllAndOverride<Role[]>('roles', [
context.getHandler(),
context.getClass(),
])
if (!roles) return true
const { user } = context.switchToHttp().getRequest()
return roles.( user.?.(role))
}
}
// common/interceptors/transform.interceptor.ts
@Injectable()
export class TransformInterceptor<T>
implements NestInterceptor<T, { data: T; timestamp: string }>
{
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
return next.handle().pipe(
map(data => ({ data, timestamp: new Date().toISOString() }))
)
}
}
// Install: @nestjs/cqrs
// commands/create-user.command.ts
export class CreateUserCommand {
constructor(public readonly dto: CreateUserDto) {}
}
// commands/create-user.handler.ts
@CommandHandler(CreateUserCommand)
export class CreateUserHandler implements ICommandHandler<CreateUserCommand> {
constructor(private readonly userRepo: UserRepository) {}
async execute(command: CreateUserCommand): Promise<User> {
const user = User.create(command.dto)
await this.userRepo.save(user)
return user
}
}
// In service/controller:
const user = await this.commandBus.execute(new CreateUserCommand(dto))
// Unit test
describe('UsersService', () => {
let service: UsersService
let repo: jest.Mocked<Repository<User>>
beforeEach(async () => {
const module = await Test.createTestingModule({
providers: [
UsersService,
{ provide: getRepositoryToken(User), useValue: createMockRepository() },
],
}).compile()
service = module.get(UsersService)
repo = module.get(getRepositoryToken(User))
})
it('throws ConflictException for duplicate email', async () => {
repo.findOneBy.mockResolvedValue(existingUser)
await expect(service.create(dto)).rejects.toThrow(ConflictException)
})
})
// E2E test
describe('POST /users', {
(, {
(app.())
.()
.({ : , : })
.()
})
})
User: Add a Products module to a NestJS app with TypeORM, including CRUD endpoints, admin-only delete protected by a RolesGuard, and OpenAPI docs.
Expected output:
products.entity.ts — TypeORM entity with id (UUID), name, price (decimal), stock, createdAtdto/create-product.dto.ts — class-validator DTO with @ApiProperty decoratorsproducts.service.ts — CRUD methods using Repository<Product>, throwing NotFoundException on missingproducts.controller.ts — all CRUD endpoints, @UseGuards(JwtAuthGuard, RolesGuard) + @Roles(Role.Admin) on DELETEproducts.module.ts — imports TypeOrmModule.forFeature([Product])