/dsc-api

RMIT Developer Student Club Platform API - Using MongoDB

Primary LanguageJavaScript

RMIT Developer Student Club Website API

Package

Encode and decode password

For application to use body of request in POST - PUT method

To set cookie and get cookie from request

To authorize specific IP

To define secure variable that will not available on public

Core package to use express

To validate input of body

To create and verify token from request header

To recognize and converting corresponding timezone of user

Core package to use MongoDB

To check - verify - upload image file to server

To get static path

Transform string to slug

Automatically generate slug from title when insert new data to MongoDB

To read file input

To read markdown from description of database if have any

Unit Testing Package

To run unit test

To assert status and response

To use http request via chai

To fake the data

Structure

Router -> Middleware -> Controller -> Service

Router

Define which url to use and routing to corresponding controller

Middleware

Checking and verify: token, roles and file input mime type if have

Controller

Controller with .frontend does not require authentication token Controller with .backend requires authentication token

Fetching data from router params if have any

Pass data to service to execute

Service

Execute Create - Read - Update - Delete

Format data to return back to controller

Return in service object that has status code and message Read & Edit: Include in the object that it will return (with key named data)

Other folders

Containers

Get, Set and Convert data to desire type

Utilities

Usage: Converting and checking array or object Condition Alway return only true or false

Validations

Validate from body inside controller before sending it to service

Models

Define Schema

Seeder

Seeding dummy data to database

Config

Configuration

Api

Authentication

Api name Description Input needed Method
/api/auth/signin Login email password POST
/api/auth/signup Register username email password POST
Api name Description Return data Required logged in Method
/api/users/:username Get user username email posts x GET
/api/users/profile Get profile of logged in user username email roles Yes GET
Api name Description Role needed Method
/api/categories Get all categories x GET
/api/categories/:category_name Get category based on name (slug format) x GET
/api/categories Create new category Admin POST
/api/categories/edit/:category_id Get specific category to prepare updating Admin GET
/api/categories/update/:category_id Update existing category Admin PATCH
/api/categories/delete/:category_id Delete existing category Admin DELETE
Api name Query Params Description Role needed Method
/api/posts latest (default = false) limit ( defaul = 10 ), page ( defaul = 1 ) column (default = createdAt) asc (default = true) x Get all posts with pagination x GET
/api/posts/top-author limit ( defaul = 5 ) x Get top authors x GET
/api/posts/:slug x slug Get single post based on slug x GET
/api/posts x x Create new post Author POST
/api/posts/read x x Display all posts that owned Author GET
/api/posts/edit/:id x id Show logged in user existing post Author GET
/api/posts/update/:id x id Update existing post Author PATCH
/api/posts/delete/:id x id Delete existing post Author DELETE

Api Domain:

https://rmit-dsc-api.herokuapp.com

Development

Field Current Future change
image String `{data: Buffer, contentType: string, mimeType: 'image/jpg