JSPM

@uecsio/pages-api

1.2.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q42807F
  • License MIT

A reusable NestJS API Pages module for content management

Package Exports

  • @uecsio/pages-api
  • @uecsio/pages-api/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@uecsio/pages-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@uecsio/pages-api

A reusable NestJS Pages module for content management with full CRUD operations, validation, and Swagger documentation.

๐Ÿš€ Features

  • Full CRUD Operations: Create, Read, Update, Delete pages
  • TypeORM Integration: Built-in database support
  • Validation: Class-validator integration for DTOs
  • Swagger Documentation: Auto-generated API documentation
  • Flexible Configuration: Easy to customize and extend
  • TypeScript Support: Full type safety

๐Ÿ“ฆ Installation

npm install @uecsio/pages-api

๐Ÿ”ง Dependencies

This package requires the following peer dependencies in your NestJS application:

npm install @nestjs/common @nestjs/typeorm typeorm class-validator class-transformer @nestjs-library/crud

๐Ÿ“– Usage

1. Import the Module

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PagesModule } from '@uecsio/pages-api';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      username: 'postgres',
      password: 'password',
      database: 'your_database',
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: true, // Only in development
    }),
    PagesModule,
  ],
})
export class AppModule {}

2. Use the Service

import { Injectable } from '@nestjs/common';
import { PagesService, CreatePageDto, Page } from '@uecsio/pages-api';

@Injectable()
export class YourService {
  constructor(private readonly pagesService: PagesService) {}

  async createPage(data: CreatePageDto): Promise<Page> {
    return this.pagesService.create(data);
  }

  async getAllPages(): Promise<Page[]> {
    return this.pagesService.findAll();
  }

  async getPageById(id: number): Promise<Page> {
    return this.pagesService.findOne(id);
  }
}

3. Use the Controller

The package automatically provides a REST API with the following endpoints:

  • POST /pages - Create a new page
  • GET /pages - Get all pages
  • GET /pages/:id - Get a specific page
  • PUT /pages/:id - Update a page
  • DELETE /pages/:id - Delete a page

4. Customize the Page Entity

You can extend the Page entity for your specific needs:

import { Entity } from 'typeorm';
import { Page } from '@uecsio/pages-api';

@Entity()
export class CustomPage extends Page {
  // Add your custom fields here
  @Column()
  customField: string;
}

๐Ÿ—๏ธ Architecture

src/
โ”œโ”€โ”€ entities/
โ”‚   โ””โ”€โ”€ page.entity.ts      # Page database entity
โ”œโ”€โ”€ dto/
โ”‚   โ”œโ”€โ”€ create-page.dto.ts  # Create page DTO
โ”‚   โ””โ”€โ”€ update-page.dto.ts  # Update page DTO
โ”œโ”€โ”€ services/
โ”‚   โ””โ”€โ”€ pages.service.ts    # Business logic service
โ”œโ”€โ”€ controllers/
โ”‚   โ””โ”€โ”€ pages.controller.ts # REST API controller
โ”œโ”€โ”€ pages.module.ts         # NestJS module
โ””โ”€โ”€ index.ts               # Package exports

๐Ÿ” API Documentation

Once the module is imported, you can access the Swagger documentation at:

http://localhost:3000/api

๐Ÿงช Testing

# Run tests
npm test

# Run tests with coverage
npm run test:cov

# Run tests in watch mode
npm run test:watch

๐Ÿ“ Configuration

Environment Variables

The module uses the following environment variables (with defaults):

DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=password
DB_NAME=your_database

Custom Database Configuration

You can override the database configuration:

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PagesModule } from '@uecsio/pages-api';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      // Your custom database configuration
      type: 'mysql',
      host: 'your-host',
      // ... other options
    }),
    PagesModule,
  ],
})
export class AppModule {}

๐Ÿ”Œ Extending the Module

Custom Service Methods

import { Injectable } from '@nestjs/common';
import { PagesService } from '@uecsio/pages-api';

@Injectable()
export class CustomPagesService extends PagesService {
  async findByStatus(status: number) {
    return this.repository.find({ where: { status } });
  }
}

Custom Controller Methods

import { Controller } from '@nestjs/common';
import { PagesController } from '@uecsio/pages-api';

@Controller('custom-pages')
export class CustomPagesController extends PagesController {
  // Add your custom endpoints here
}

๐Ÿค Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support

If you encounter any problems or have questions, please:

  1. Check the documentation
  2. Search existing issues
  3. Create a new issue

๐Ÿ”„ Changelog

v1.0.0

  • Initial release
  • Full CRUD operations
  • TypeORM integration
  • Swagger documentation
  • Validation support