---
# System prepended metadata

title: Water Meter API Documentation
tags: [' Water Meter', ' Ciputra', ' API', NBS]

---

---
title: Water Meter API Documentation
tags: NBS, API, Ciputra, Water Meter

---

API Documentations
===

## Table of Contents

[TOC]

## Diagram

### ER *backend

![](https://i.imgur.com/cCZlVts.jpg)
[preview](https://i.imgur.com/cCZlVts.jpg)

### ER *android

![](https://i.imgur.com/GWTAzqb.jpg)
[preview](https://i.imgur.com/GWTAzqb.jpg)

## Modules

### Auth

#### Notes

::: info
List Accounts

- NIP
  1. Surveryor Bot 1: **1571891571897761**
  1. Surveryor Bot 2: **1571891571897762**
  1. Surveryor Bot 3: **1571891571897763**
  1. Surveryor Bot 4: **1571891571897764**
  1. Surveryor Bot 5: **1571891571897765**
- Pass: *"surveyor123"*
  :::

***

### Report

:::danger
Every time surveyor scan QR code and submit the data, **DO NOT update the *REPORT* data. You must create new one.** Either, is the first time of create or revised the data.
:::

#### Normal

- Steps
  1.  **create** report data
      - ***id*** = UUID with timestamp
      - ***status*** = Submit
      - ***type*** = Normal (id)
  1.  **get** task data based on ***residence_id***
  1.  **update** task data:
      - ***report_id*** = latest report id
      - ***latest_value*** = latest value of water meter
      - ***status*** = Normal (id)
      - ***updated_at*** = current time
      - ***updated_by*** = surveyor id
      - ***version*** = increment latest version

#### Has Issue

- Steps
  1.  **create** report data
      - ***id*** = UUID with timestamp
      - ***status*** = Submit
      - ***type*** = Issue (id)
  1.  **create** report issue data
      - ***id*** = UUID with timestamp
  1.  **get** task data based on ***residence_id***
  1.  **update** task data:
      - ***report_id*** = latest report id
      - ***latest_value*** = latest value of water meter
      - ***status*** = Issue (id)
      - ***updated_at*** = current time
      - ***updated_by*** = surveyor id
      - ***version*** = increment latest version

### Sync

#### Push local to server

- Steps

  1. Convention

     - **zip** : `[UUID].zip`
       - UUID : using timestamp
         :::success
         282df75c-fade-11e9-8f0b-362b9e155667.zip
         :::
     - **metadata** : `[SURVEYOR ID]_[TIMESTAMP].json`
       :::success
       1571891571897761_1572416229.json
       :::
     - **image** : `[UUID]_[INCREMENT].jpeg`
       - UUID : report id and without **"--"**
       - Increment: index of image
         :::success
         cd4be8b0fae911e98f0b362b9e155667_1.jpeg
         cd4be8b0fae911e98f0b362b9e155667_2.jpeg
         :::
     - **folder name** : `images`

  2. Create **metadata**: 1571891571897761_1572416229.json

     - **Report**

     ```javascript
     {
         "metadata": "1571891571897761_1572416229.json",
         "file_name": "282df75c-fade-11e9-8f0b-362b9e155667",
         "total": 1,
         "files": {
             "folder_name": "images",
             "total": 2,
             "images": [
                 "cd4be8b0fae911e98f0b362b9e155667_1.jpeg",
                 "cd4be8b0fae911e98f0b362b9e155667_2.jpeg",
                 "63ef6735cec8484b9eb815f08aae58ef_1.jpeg"
             ]
         },
         "module": "report",
         "contents": {
             "contexts": ["units", "clusters"],
             "units": {
                 "tasks": [{
                 "id": 1571764824,
                 "report_id": "cd4be8b0-fae9-11e9-8f0b-362b9e155667",
                 "latest_value": 11212,
                 "status": 20,
                 "updated_at": "1568875373",
                 "updated_by": 1571891571897761,
                 "version": 1
             }],
                 "reports": [{
                     "id": "cd4be8b0-fae9-11e9-8f0b-362b9e155667",
                     "surveyor_id": 1571891571897761,
                     "task_id": 1571764824,
                     "residence_id": 1111,
                     "images_files": [
                         "cd4be8b0fae911e98f0b362b9e155667_1.jpeg",
                         "cd4be8b0fae911e98f0b362b9e155667_2.jpeg"
                     ],
                     "value": 11212,
                     "notes": "Lorem ipsum col de",
                     "period": "October",
                     "status": 10,
                     "type": 20,
                     "created_at": "1572416229",
                     "created_by": 1571891571897761
                 }],
                 "report_issues": [{
                     "id": "4195396e-0432-11ea-8d71-362b9e155667",
                     "report_id": "cd4be8b0-fae9-11e9-8f0b-362b9e155667",
                     "issue_id": 1,
                     "issue": "QR Code Rusak"
                     "notes": "Qr code tidak bisa di scan",
                     "created_at": "1572416229",
                     "created_by": 1571891571897761
                 }]
             },
             "clusters": {
                 "findings": [{
                     "id": "0a90d1e6-edae-48e8-b9d3-cfac20c1a61d",
                     "cluster_id": 1581346873,
                     "surveyor_id": 1571891571897761,
                     "area": "taman",
                     "issue_id": 6,
                     "issue": "Rusak",
                     "image_files": [
                       "63ef6735cec8484b9eb815f08aae58ef_1.jpeg"
                     ],
                     "notes": "tiang besi ayunan mulai berkarat",
                     "created_at": "1576829444101",
                     "created_by": 1571891571897761
                 }]
             }
         }
     }
     ```

     - **Residence**

     ```javascript
     {
        "metadata":"1571891571897761_1582088828372.json",
        "file_name":"282df75c-fade-11e9-8f0b-362b9e155667",
        "total":1,
        "files":{
           "folder_name":"images",
           "total":1,
           "images":[
              "1556668800.jpeg"
           ]
        },
        "module":"residence",
        "contents":{
           "contexts":[
              "residences"
           ],
           "residences":[
              {
                 "id":1556668800,
                 "qr_id":"604f55d2539d11eaa3c20242ac140003",
                 "image_files":"1556668800.jpeg",
                 "estate_id":1571755185,
                 "cluster_id":1582174597,
                 "block_id":1546300800,
                 "unit_id":1551398400,
                 "address":"Citra Gran Cibubur - Clarkia, A1/1",
                 "updated_at":"1575054672",
                 "updated_by":1571891571897761,
                 "version":1
              }
           ]
        }
     }
     ```

  3. Set **Authorization**: `Bearer {{access_token}}`

  4. Using ***Form Data**

     - ***file*** = attach file from `enctype="multipart/form-data"`
     - ***file_name*** = UUID with timestamp
     - ***file_type*** = type of file
     - ***file_size*** = file size in byte

  5. Payload data

     - Residence
       - only add payload 'qr_id' if you want to 'tambah rumah' or 'update qr to'

- Example

  - Body

  ```javascript
      {
          file: File,
          file_name: "282df75c-fade-11e9-8f0b-362b9e155667",
          file_type: "zip",
          file_size: 1024
      }
  ```

  - Response

  ```javascript
      {
          "data": {
              "metadata": "1571891571897761_1572416229.json",
              "file_name": "282df75c-fade-11e9-8f0b-362b9e155667",
              "file_size": 20,
              "file_type": "zip",
              "status_id": 10,
              "status": "Pending",
              "sync_at": "1572416229"
          }
      }
  ```

#### Update data 

- Steps

  1. Get notification

     - Context: "update_data"
     - Code:
       1. create
       2. update
     - Module: //changes @liandaraaa 
       1. surveyors
       2. projects
       3. estates
       4. clusters
       5. blocks
       6. units
       7. residences
       8. residents
       9. issues
       10. tasks
     - Notification Response

     ```javascript
         {
             "data": {
                 "context": "update_data",
                 "title": "Update existing data",
                 "body": "Please pull to get updated data",
                 "code": "update",
                 "content": {
                     "module": "blocks", //string
                     "content": [
                         {
                             "id": "7", //string
                             "version": 1 //integer
                         }
                     ]
                 }
             }
         }
     ```

  2. Request pull data

     - Body

     ```javascript
         {
             "module": "blocks",
             "id": [
                 "29540" //string
             ]
         }
     ```

     - Response
       *same as object in download data

     ```javascript
         {
             "data": {
                 "blocks": [
                     {
                         "id": 29540,
                         "name": "A",
                         "cluster_id": 7589,
                         "created_at": "1584004020",
                         "updated_at": "1584004656",
                         "version": 2
                     }
                 ]
             }
         }
     ```

### Notification

#### Payload
- Body
```javascript
     {
         "id": "77aee1420a8d11ea8d71362b9e155667",
         "context": "sync_data",
         "title": "Success Synchronize Local Data",
         "body": "Your data has been saved into server",
         "code": "success_sync",
         "status_code": 200 //changed
         "content":[{
             "file_name": "054ed3bc-f442-4f7c-9afd-1d802fa9e62c",
             "sync": {
                 "cluster": {
                  "id": 1574136755,
                  "name": "Clarkia"
                 },
                 "tasks": [1561939201],
                 "reports": ["17368eb7-3d1d-44cd-a428-fcb1a95463d2"],
                 "report_issues": ["d67eca7c-d344-4d47-b1a8-738d33cb2bbe"]
             }
         }]
     }
```
- Status Code

  | Status | Context     |
  | ------ | ----------- |
  | 200 | Success |
  | 400 | Bad Request |
  | ***1 | Metadata doesn't exist |
  | ***2 | Undefined module |
  | ***3 | There's no context |
  | ***4 | Images not found |
  | ***5 | Missed data |
  | ***6 | Duplicate data |
  | ***7 | Please update your data with the latest version |
  | ***8 | Qr Code was assign before |
  | 401 | Unauthorized |
  | 404 | Not found |
  | 405 | Method not allowed |
  | 422 | Given data not valid *validation |
  | ***1 | Corrupted files |
  | 1001 | Invalid username of password |
  | 1002 | Surveyor doesn't have any project |

## Response

### Master Data

Information about master data responses model structure.

#### - Surveyor

```java=
    class Surveyor {
        long id;
        String name;
        String msisdn;
        String email;
        String avatar_file;
        String avatar_url;
        String address;
        String position;
        int status;
        String created_at;
        long created_by;
        String updated_at;
        long updated_by;
        int version
    }
```

#### - Project

```java=
    class Project {
        long id;
        String name;
        long estate_id;
        Estate estate;
        String created_at;
        String updated_at;
        int version
    }
```

#### - Cluster Project

```java=
    class ClusterProject {
        long id;
        long project_id;
        Project project;
        long surveyor_id;
        long cluster_id;
        Cluster cluster
        String assigned_by;
        int total;
        String created_at;
        String updated_at;
        int version
    }
```

#### - Estate

```java=
    class Estate {
        long id;
        String name;
        long country_id;
        Country country;
        long province_id;
        Province province;
        long region_id;
        Region region;
        String address;
        String created_at;
        String updated_at;
        int version;
    }
```

#### - Cluster

```java=
    class Cluster {
        long id;
        String name;
        long estate_id;
        String created_at;
        String updated_at;
        int version;
    }
```

#### - Block

```java=
    class Block {
        long id;
        String name;
        long cluster_id;
        String created_at;
        String updated_at;
        int version;
    }
```

#### - Unit

```java=
    class Unit {
        long id;
        String number;
        long block_id
        String created_at;
        String updated_at;
        int version;
    }
```

#### - Residence
```java=
    class Residence {
        long id;
        String qr_id; //changed
        String image_files;
        long resident_id;
        Resident resident
        long estate_id;
        Estate estate;
        long cluster_id;
        Cluster cluster;
        long block_id;
        Block block;
        long unit_id;
        Unit unit;
        String address;
        String created_at;
        long created_by;
        String updated_at;
        long updated_by;
        int version;
    }
```

#### - Resident

```java=
    class Resident {
        long id;
        String full_name;
        String email;
        String msisdn
        String created_at;
        long created_by;
        String updated_at;
        long updated_by;
        int version;
    }
```

#### - Project

```java=
    class Project {
        long id;
        String name;
        long estate_id;
        Estate estate;
        String created_at;
        String updated_at;
        int version;
    }
```

#### - Task

```java=
    class Task {
        long id;
        String report_id;
        long project_id;
        Project project;
        long surveyor_id;
        Surveyor surveyor
        long cluster_id;
        Cluster cluster;
        long residence_id;
        Residence residence;
        long oldest_value;
        long latest_value
        int status;
        int period_id;
        String created_at;
        long created_by
        String updated_at;
        long updated_by
        int version;
    }
```

#### -  Period

```java=
    class Period {
        int id;
        String name;
        String updated_at;
    }
```

#### - Task Status

```java=
    class TaskStatus {
        int id;
        String name;
        String created_at;
    }
```

#### - Report

```java=
    class Report {
        String id;
        long project_id;
        long surveyor_id;
        long task_id;
        long residence_id;
        List<T> image_files;
        long value;
        String notes;
        String period;
        int status;
        int type;
        String created_at;
        long created_by;
        String updated_at;
        long updated_by;
        int version;
    }
```

#### - Report Status

```java=
    class ReportStatus {
        int id;
        String name;
        String updated_at;
    }
```

#### - Report Issue

```java=
    class ReportIssue {
        String id;
        String report_id;
        long issue_id;
        Issue issue;
        String notes;
        String created_at;
        long created_by;
        String updated_at;
        long updated_by;
    }
```

#### - Issue

```java=
    class Issue {
        int id;
        String name;
        bool has_value;
        bool scan_qr;
        bool is_option_value;
        String created_at;
        String updated_at;
        int version;
        int type *new
    }
```

#### - Surveyor Block

```java=
    class SurveyorBlock {
        long id;
        String name;
        long cluster_id;
    }
```

#### - Surveyor Unit

```java=
    class SurveyorUnit {
        long id;
        String number;
        long block_id
    }
```

