Git Product home page Git Product logo

boilerplate_v1_fastify's Introduction

Lưu ý:

  1. Chỉ sử dụng với mongodb.

Hướng dẫn sử dụng:

1. Config

  • Copy file .env-example vào file .env của bạn và chỉnh sửa lại theo cấu hình của bạn.
  • Chỉnh sửa file settings.json
{
    "EXCLUDED_ROUTE": ["auth", "me", "route"], //điền vào các route không muốn tạo ra permissions, auth, me và route là mặc định
    "TEXT_SEARCH": ["title", "name"], //điền vào các route muốn tìm kiếm bằng tiếng Việt
    "TIMESTAMP": true,
    "VERSION_KEY": false,
    "AUTH": {
        "BROWSER_ID_CHECK": false // true nếu muốn check cả browserId, bắt buộc phải truyền thêm browserId khi login và refreshToken
    },
    "REFERENCE_CHECK": false //Chức năng đang thử nghiệm
}

Lúc này bạn đã chạy được dự án lên

2. Sử dụng

I. Có thể sử dụng các param như fields, filter, sort, meta, limit, page để lấy được kết quả như ý.

Fields:

  • Ký tự * để lấy tất cả các trường mong muốn.
  • Ký tự - để loại bỏ trường không mong muốn
  1. Điền các trường muốn lấy, cách nhau bởi dấu phẩy ',' ví dụ như title,name,slug
  2. Tham chiếu đến collection được liên kết: Ví dụ chúng ta có được kết quả từ api
    {
     "_id": 1,
     "title": "abcd",
     "category": [
         12,
         17,
         35,
         3
     ],
     "author": 1,            
    },
    Muốn tham chiếu đến author chúng ta sẽ điền fields như sau
    author.*
    
    Được kết quả
    {
     "_id": 1,
     "title": "abcd",
     "category": [
         12,
         17,
         35,
         3
     ],
     "author": {
      "_id": 1,
      "name": "xyz",
      "createdAt": "2024-03-01T10:09:25.665Z",
      "updatedAt": "2024-03-01T10:09:25.665Z",
      },            
    }
    Tiếp tục chọn trường mong muốn bên trong author, thì đi vào trong 1 cấp nữa, cách nhau bởi dấu phẩy
    author.name,author.createdAt
    
    Được kết quả
    {
     "_id": 1,
     "title": "abcd",
     "category": [
         12,
         17,
         35,
         3
     ],
     "author": {
      "name": "xyz",
      "createdAt": "2024-03-01T10:09:25.665Z",
      },            
    }

Filter:

Viết dưới dạng filter[field][compareKey]=value, với compareKey trùng với các quy tắc của mongo, ví dụ như $eq $regex $gt...

Sort:

sort=field với field là trường được sort theo ascsort=-field được sort theo desc.

Meta:

meta được trả về với 2 field là total_count trả về số lượng document có trong collection, và filter_count trả về số lượng document thoả điều kiện của filter, hoặc đơn giản là dùng meta=* để lấy cả 2 kết quả này

Limit và page:

Chức năng để phân trang

boilerplate_v1_fastify's People

Contributors

dothinh115 avatar

Watchers

 avatar

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.