---
# System prepended metadata

title: Kirirom Dormitory API
tags: [API, GoogleS, Slack]

---

# Kirirom Dormitory API

###### tags: `Slack` `API` `GoogleS`

## **Purpose:**
I. Getting dormitary data of student from spreadsheet
II. Create API to request for dorm info using `slackid` for future development usage

### I. Dorm_sheet_system
1. Kirirom manager input dorm data
2. Get the data from dorm spreadsheet

### II. Dorm_API
1. Getting the data from `dorm_sheet_system`
2. place data to database
3. Web_API

### **API sample usage**:

**Precondition**
* TOKEN

### APIS:
*    www.domain.com/dorm-api/users/all?token=abc => all users
*    www.domain.com/dorm-api/users?token=abc&slack_id=aaa,bbb,ccc => get users detail with aaa,bbb or ccc `slack_id` 
*    www.domain.com/dorm-api/users?token=abc&slack_id=aaaa => get user detail with 'aaaa' `slack_id`
*    www.domain.com/dorm-api/custom?token=abc => for custom query object
        *    **Property**:
                *    slack_id
                *    dorm_type_id (1,2 or 3)
                *    dorm_number
                *    dorm_room_number
                *    now_using (1,0)

***note***: when using `users` we can use many `slack_id` but when using `custom` it only support single values.

#### request
```javascript
'use strict';

const request = require ('request');

let slack_id = 'aaa'
let slack_ids = ['aaa', 'bbb', 'ccc']
let token = process.env.TOKEN;

// one user
request.get('https://sample.com/dorm-api/users?slack_id=${slack_id}&token=${token}', (err, res, req)=> {
    // use
});

// multiple user
request.get('https://sample.com/dorm-api/users?slack_id=${slack_ids}&token=${token}', (err, res, req)=> {
    // use
});
// customize query
request.get('https://sample.com/dorm-api/custom?now_using=1&dorm_type_id=1&token=${token}', (err, res, req)=> {
    // use
});

```

### response
```
[
  {
        "id": 2,
        "slack_id": "KKK",
        "dorm_type_id": 1,
        "dorm_number": 1,
        "dorm_room_num": 1,
        "now_using": 1,
        "createdAt": "2019-12-19T10:01:19.000Z",
        "updatedAt": "2019-12-19T10:01:19.000Z",
        "dorm": {
            "dorm_type_id": 2,
            "dorm_type": "R",
            "createdAt": "2019-12-19T10:00:41.660Z",
            "updatedAt": "2019-12-19T10:00:41.660Z"
        }
    }
]
```

### About Database (sqlite3):
#### User schema:
```sql
    CREATE TABLE user (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      slack_id TEXT NOT NULL,
      dorm_type_id INTEGER NOT NULL,
      dorm_num INTEGER NOT NULL,
      dorm_room_num INTEGER,
      createdAt TIMESTAMP NOT NULL DEFAULT (datetime (CURRENT_TIMESTAMP, 'localtime')),
      updatedAt TIMESTAMP NOT NULL DEFAULT (datetime (CURRENT_TIMESTAMP, 'localtime')),
      now_using INTEGER DEFAULT 0
    )
```

#### Dorm schema:
```sql
    CREATE TABLE dorm (
      dorm_type_id INTEGER PRIMARY KEY AUTOINCREMENT,
      dorm_type TEXT NOT NULL,
      createdAt TIMESTAMP NOT NULL DEFAULT (datetime (CURRENT_TIMESTAMP, 'localtime')),
      updatedAt TIMESTAMP NOT NULL DEFAULT (datetime (CURRENT_TIMESTAMP, 'localtime'))
    )
```