Penghitung Sembako API v1.0

Comprehensive REST API Reference

https://sembako.sendiko.my.id/

User Endpoints

Endpoints for managing application user accounts.

Get User Details

GET /user/:id

Retrieves registered user details by unique user ID.

Path Parameters

id (integer, required) — User ID. Example: 3

Response (200 OK)

{
    "status": 200,
    "user": {
        "id": 3,
        "username": "Rizky Sendiko",
        "email": "example@gmail.com",
        "profileUrl": "https://example.com/profile.jpg",
        "createdAt": "2025-05-27T17:24:39.000Z",
        "updatedAt": "2025-05-27T17:24:39.000Z"
    }
}

Create User

POST /user

Creates a new user profile in the database.

Request Body (JSON)

{
    "username": "Sendiko",
    "email": "sendiko@example.com",
    "profileUrl": "https://example.com/profile.jpg"
}

Response (201 Created)

{
    "status": 201,
    "message": "User created successfully",
    "user": {
        "id": 8,
        "username": "Sendiko",
        "email": "sendiko@example.com",
        "profileUrl": "https://example.com/profile.jpg",
        "createdAt": "2025-06-08T15:37:54.199Z",
        "updatedAt": "2025-06-08T15:37:54.199Z"
    }
}

Store Endpoints

Endpoints for creating, managing, and retrieving store profile records.

Get All Stores for User

GET /store/:userId

Retrieves all stores associated with a specific user ID.

Path Parameters

userId (integer, required) — User ID. Example: 3

Response (200 OK)

{
    "status": 200,
    "store": [
        {
            "id": 1,
            "userId": 3,
            "name": "Toko Sembako Jaya",
            "address": "Jl. Merdeka No. 123",
            "phone": "081234567890",
            "email": "toko1@example.com",
            "createdAt": "2025-05-27T17:24:39.000Z",
            "updatedAt": "2025-05-27T17:24:39.000Z"
        },
        {
            "id": 2,
            "userId": 3,
            "name": "Toko Sembako Maju",
            "address": "Jl. Ahmad Yani No. 456",
            "phone": "081987654321",
            "email": "toko2@example.com",
            "createdAt": "2025-06-01T10:15:22.000Z",
            "updatedAt": "2025-06-01T10:15:22.000Z"
        }
    ]
}

Get Store Details

GET /store/details/:id

Retrieves single store details associated with the user ID parameter.

Path Parameters

id (integer, required) — User ID. Example: 3

Response (200 OK)

{
    "status": 200,
    "stores": {
        "id": 1,
        "userId": 3,
        "name": "Toko Sembako Jaya",
        "address": "Jl. Merdeka No. 123",
        "phone": "081234567890",
        "email": "toko1@example.com",
        "createdAt": "2025-05-27T17:24:39.000Z",
        "updatedAt": "2025-05-27T17:24:39.000Z"
    }
}

Create Store

POST /store

Creates a new store record for a user.

Request Body (JSON)

{
    "userId": 3,
    "name": "Toko Sembako Jaya",
    "address": "Jl. Merdeka No. 123",
    "phone": "081234567890",
    "email": "toko1@example.com"
}

Response (201 Created)

{
    "status": 201,
    "message": "Store created successfully",
    "store": {
        "id": 1,
        "userId": 3,
        "name": "Toko Sembako Jaya",
        "address": "Jl. Merdeka No. 123",
        "phone": "081234567890",
        "email": "toko1@example.com",
        "createdAt": "2025-06-08T15:37:54.199Z",
        "updatedAt": "2025-06-08T15:37:54.199Z"
    }
}

Update Store

PUT /store/:id

Updates information for an existing store by store ID.

Path Parameters

id (integer, required) — Store ID. Example: 1

Request Body (JSON)

{
    "name": "Toko Sembako Jaya Updated",
    "address": "Jl. Merdeka No. 124",
    "phone": "081234567891",
    "email": "toko1-updated@example.com"
}

Response (200 OK)

{
    "status": 200,
    "message": "Store updated successfully",
    "store": {
        "id": 1,
        "userId": 3,
        "name": "Toko Sembako Jaya Updated",
        "address": "Jl. Merdeka No. 124",
        "phone": "081234567891",
        "email": "toko1-updated@example.com",
        "createdAt": "2025-06-08T15:44:15.000Z",
        "updatedAt": "2025-06-08T15:46:23.436Z"
    }
}

Delete Store

DELETE /store/:id

Deletes a store record and cascades removal to all associated groceries, stocks, and transactions.

Path Parameters

id (integer, required) — Store ID. Example: 1

Response (200 OK)

{
    "status": 200,
    "message": "Store deleted successfully"
}

Grocery Endpoints

Endpoints for managing catalog groceries linked to specific stores.

Get All Groceries for Store

GET /grocery/:storeId

Retrieves all groceries belonging to a store, including associated stock quantities.

Path Parameters

storeId (integer, required) — Store ID. Example: 1

Response (200 OK)

{
    "status": 200,
    "groceries": [
        {
            "id": 17,
            "storeId": 1,
            "name": "Beras Raja Platinum",
            "unit": "Kg",
            "price": 19000,
            "imageUrl": "https://sembako.sendiko.my.id/public/groceries/1749017019124-beras.jpg",
            "createdAt": "2025-05-30T08:30:33.000Z",
            "updatedAt": "2025-06-04T06:03:39.000Z",
            "stock": {
                "quantity": 50
            }
        },
        {
            "id": 18,
            "storeId": 1,
            "name": "Minyak Bimoli",
            "unit": "Lt",
            "price": 26000,
            "imageUrl": "https://sembako.sendiko.my.id/public/groceries/1748593904619-minyak.jpg",
            "createdAt": "2025-05-30T08:31:44.000Z",
            "updatedAt": "2025-05-30T08:37:05.000Z",
            "stock": {
                "quantity": 25
            }
        }
    ]
}

Get Grocery Details

GET /grocery/details/:id

Retrieves details for a single grocery item by its unique ID.

Path Parameters

id (integer, required) — Grocery ID. Example: 17

Response (200 OK)

{
    "status": 200,
    "grocery": {
        "id": 17,
        "storeId": 1,
        "name": "Beras Raja Platinum",
        "unit": "Kg",
        "price": 19000,
        "imageUrl": "https://sembako.sendiko.my.id/public/groceries/1749017019124-beras.jpg",
        "createdAt": "2025-05-30T08:30:33.000Z",
        "updatedAt": "2025-06-04T06:03:39.000Z",
        "stock": {
            "quantity": 50
        }
    }
}

Create Grocery

POST /grocery

Adds a new grocery item to a store and automatically initializes stock tracking.

Request Body (JSON or Form-Data)

  • storeId (number, required) — Associated store ID.
  • name (string, required) — Grocery item name.
  • unit (string, required) — Measurement unit (e.g., "Kg", "Pcs", "Lt").
  • price (number, required) — Unit price.
  • imageUrl / image_url (string, optional) — Image URL or binary upload.
  • quantity (number, optional, default: 0) — Initial stock quantity.

Response (201 Created)

{
    "status": 201,
    "message": "Grocery created successfully",
    "grocery": {
        "id": 24,
        "storeId": 1,
        "name": "Telur Ayam Fresh",
        "unit": "Kg",
        "price": 28000,
        "imageUrl": "https://sembako.sendiko.my.id/public/groceries/telur.jpg",
        "createdAt": "2025-06-08T15:44:15.201Z",
        "updatedAt": "2025-06-08T15:44:15.201Z",
        "stock": {
            "quantity": 100
        }
    }
}

Update Grocery

PUT /grocery/:id

Updates details of an existing grocery item by ID.

Path Parameters

id (integer, required) — Grocery ID. Example: 24

Request Body (JSON / Form-Data)

{
    "storeId": 1,
    "name": "Telur Ayam Super",
    "unit": "Kg",
    "price": 29000
}

Response (200 OK)

{
    "status": 200,
    "message": "Grocery updated successfully",
    "grocery": {
        "id": 24,
        "storeId": 1,
        "name": "Telur Ayam Super",
        "unit": "Kg",
        "price": 29000,
        "imageUrl": "https://sembako.sendiko.my.id/public/groceries/telur.jpg",
        "createdAt": "2025-06-08T15:44:15.000Z",
        "updatedAt": "2025-06-08T15:46:23.436Z"
    }
}

Delete Grocery

DELETE /grocery/:id

Deletes a grocery item from the system by ID.

Path Parameters

id (integer, required) — Grocery ID. Example: 24

Response (200 OK)

{
    "status": 200,
    "message": "Grocery deleted successfully"
}

Stock Endpoints

Endpoints for managing inventory stock counts for grocery items.

Stock Lifecycle & Automatic Adjustments

Each grocery item automatically maintains a linked Stock record. Stock quantity is automatically updated during transaction operations:

  • Creating a Transaction (POST /transaction): Decrements stock quantity by the transaction amount.
  • Updating a Transaction (PUT /transaction/:id): Recalculates stock based on difference in transaction amount.
  • Deleting a Transaction (DELETE /transaction/:id): Restores (increments) stock quantity by the transaction amount.

Update Stock Quantity

PUT /grocery/:id/stock

Updates the stock quantity for a specific grocery item by its grocery ID.

Path Parameters

id (integer, required) — Grocery ID. Example: 17

Request Body (JSON)

{
    "quantity": 50
}

Response (200 OK)

{
    "status": 200,
    "message": "Stock updated successfully",
    "grocery": {
        "id": 17,
        "storeId": 1,
        "name": "Beras Raja Platinum",
        "unit": "Kg",
        "price": 19000,
        "imageUrl": "https://sembako.sendiko.my.id/public/groceries/1749017019124-beras.jpg",
        "createdAt": "2025-05-30T08:30:33.000Z",
        "updatedAt": "2025-06-04T06:03:39.000Z",
        "stock": {
            "quantity": 50
        }
    }
}

Transaction Endpoints

Endpoints for managing store sales transactions and history log.

Get All Transactions for Store

GET /transaction/:storeId

Retrieves all transaction logs for a given store ID.

Path Parameters

storeId (integer, required) — Store ID. Example: 1

Response (200 OK)

{
    "status": 200,
    "transactions": [
        {
            "id": 6,
            "storeId": 1,
            "groceryId": 17,
            "amount": 15,
            "totalPrice": 285000,
            "createdAt": "2025-05-30T09:15:20.000Z",
            "updatedAt": "2025-05-30T09:15:20.000Z",
            "Grocery": {
                "id": 17,
                "name": "Beras Raja Platinum"
            }
        }
    ]
}

Create Transaction

POST /transaction

Records a transaction and automatically reduces grocery stock quantity.

Request Body (JSON)

{
    "storeId": 1,
    "groceryId": 17,
    "amount": 2,
    "totalPrice": 38000
}

Response (201 Created)

{
    "status": 201,
    "message": "Transaction successfully created.",
    "transaction": {
        "id": 14,
        "storeId": 1,
        "groceryId": 17,
        "amount": 2,
        "totalPrice": 38000,
        "updatedAt": "2025-06-08T15:50:00.000Z",
        "createdAt": "2025-06-08T15:50:00.000Z"
    }
}

Statistics & Utility

Endpoints for retrieving store dashboard stats and generating S3/MinIO upload URLs.

Get User Statistics

GET /stats/:userId

Retrieves total sales, grocery count, and transaction count for a user.

Path Parameters

userId (integer, required) — User ID. Example: 3

Response (200 OK)

{
    "status": 200,
    "message": "Grocery count retrieved successfully",
    "statistics": {
        "groceryCount": 5,
        "totalSales": 1090000,
        "totalHistory": 6
    }
}

Generate Presigned Upload URL

POST /upload/presigned-url

Generates a presigned URL for direct object store uploading.

Request Body (JSON)

{
    "fileName": "item-image.jpg"
}

Response (200 OK)

{
    "status": 200,
    "message": "Presigned URL generated successfully",
    "uploadUrl": "https://minio.sendiko.my.id/public/groceries/item-image.jpg?presigned...",
    "imageUrl": "https://sembako.sendiko.my.id/public/groceries/item-image.jpg"
}