Giter Site home page Giter Site logo

finance.api.sonnm.com's Introduction

API

Overview Architecture

Overview

Stack

Database + ORM

  • Database: MongoDB
  • ORM: Mongoose

Client-Server

  • HTTP REST API
  • JWT Token

Background Jobs

Cron

Test

Log

Document

Monitoring tools

Devops

Third party tools

Setup

cp .env.sample .env
# replace with your environment's values
# start database
docker-compose up -d

Jest

How to run test

How to run a specific file ?

npx jest ./test/class-validator-with-schema.spec.ts

finance.api.sonnm.com's People

Contributors

misostack avatar

Watchers

 avatar  avatar  avatar

finance.api.sonnm.com's Issues

3rd: API Design

Includes:

  • Controller and Methods for CRUD
  • Input validation: DTOs, Pipes
  • Unify response: input validation errors, crud responses, processing error, server error - Interceptors
  • API Doc with Swagger
  • Transform Output: class transformer and response DTOs
  • Pagination : limit, offset
  • Search: filter
  • Authorization: Middleware, Auth Guard, Role base Access Control
  • Unit Tests: Mock, Spy & Stubs
  • Upload file: multipart form data
  • Multi media endpoints: display image, download file, html, streaming
  • Cache: header cache keys, redis cache, cache invalidation

2nd Create Schema and Model in NestJS with Mongoose

2nd Create Schema and Model in NestJS with Mongoose

Define Schema

import * as mongoose from 'mongoose';
export type Schema = mongoose.Schema;
export class SchemaFactory {
  static createSchema(options: any): Schema {
    return new mongoose.Schema({
      ...options,
      createdAt: { type: Date, default: Date.now },
      updatedAt: { type: Date, default: Date.now },
    });
  }
}

Create Provider to inject Model ( created from Schema )

const CompanySchema = SchemaFactory.createSchema({
  name: { type: String, required: true, maxLength: 75 },
});

const companyProvider = {
      provide: `EXAMPLE_MODEL`,
      useFactory: (connection: Connection) =>
        connection.model('Company', CompanySchema ),
      inject: ['DatabaseConnection'],
    };

export const databaseProviders = [
  {
    provide: 'DatabaseConnection',
    useFactory: (): Promise<typeof mongoose> =>
      mongoose.connect(MONGODB_URL, mongooseOptions),
  },
];


@Module({
  imports: [],
  providers: [...databaseProviders, companyProvider],
  exports: [...databaseProviders, companyProvider],
})

Usage

@Module({
  imports: [DatabaseModule],
  controllers: [HealthController],
})
export class HealthModule {}

@Controller('health')
export class HealthController {
  constructor(
    @Inject('COMPANY_MODEL')
    private companyModel: Model<Company>,
  ) {}

  @Get()
  async check() {
    await this.companyModel.create({ name: 'dasd' });
    const totalOfCompany = await this.companyModel.count();
    console.log({ totalOfCompany });

    return {totalOfCompany}
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.