Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,39 @@ npx lint-staged
echo "🧪 Running tests..."
npm test

# # Run Spectral linting on Postman collections if they changed
# if git diff --cached --name-only | grep -qE "postman/collections/"; then
# echo "📋 Linting Postman collections with Spectral..."
# node .spectral/lint-with-names.js
# Run Spectral linting on Postman collections if they changed
if git diff --cached --name-only | grep -qE "postman/collections/"; then
echo "📋 Linting Postman collections with Spectral..."
node .spectral/lint-with-names.js

# if [ $? -ne 0 ]; then
# echo "❌ Spectral linting failed for Postman collections"
# exit 1
# fi
if [ $? -ne 0 ]; then
echo "❌ Spectral linting failed for Postman collections"
exit 1
fi

# echo "✅ Postman collection linting passed!"
# fi
echo "✅ Postman collection linting passed!"
fi

# # Run Postman tests only if Postman collection files changed
# if git diff --cached --name-only | grep -qE "postman/"; then
# echo "📬 Postman collection changed - Running Postman tests..."
# Run Postman tests only if Postman collection files changed
if git diff --cached --name-only | grep -qE "postman/"; then
echo "📬 Postman collection changed - Running Postman tests..."

# # Run all collections in postman/collections/
# for collection in postman/collections/*.postman_collection.json; do
# if [ -f "$collection" ]; then
# echo " → Running: $(basename "$collection")"
# postman collection run "$collection"
# Run all collections in postman/collections/
for collection in postman/collections/*.postman_collection.json; do
if [ -f "$collection" ]; then
echo " → Running: $(basename "$collection")"
postman collection run "$collection"

# if [ $? -ne 0 ]; then
# echo "❌ Postman collection failed: $collection"
# exit 1
# fi
# fi
# done
if [ $? -ne 0 ]; then
echo "❌ Postman collection failed: $collection"
exit 1
fi
fi
done

# echo "✅ All Postman collections passed!"
# else
# echo "⏭️ No Postman collection changes detected, skipping Postman tests"
# fi
echo "✅ All Postman collections passed!"
else
echo "⏭️ No Postman collection changes detected, skipping Postman tests"
fi

echo "✅ All pre-commit checks passed!"
12 changes: 12 additions & 0 deletions .postman/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"workspace": {
"id": "dc52c5c3-a708-487e-891e-3f0d62737b8c"
},
"entities": {
6│ "collections": ["../postman/collections/Intergalactic Bank API.postman_collection.json"],
"environments": [],
"specs": [],
"flows": [],
"globals": []
}
}
235 changes: 235 additions & 0 deletions postman/collections/Intergalactic Bank API.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
{
"info": {
"_postman_id": "e435e6cd-fc60-4154-96db-7f876c3a45bb",
"name": "Intergalactic Bank API",
"description": "The Intergalactic Bank API makes it easy to manage transaction and account data. Features include Account Management, Transaction Processing, Multiple Currencies, API Key Authentication, and Rate Limiting.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Admin",
"item": [
{
"name": "Generate API key",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Extract and store API key\", function () {",
" var jsonData = pm.response.json();",
" pm.expect(jsonData).to.have.property('apiKey');",
" pm.collectionVariables.set('apiKey', jsonData.apiKey);",
"});"
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"url": {
"raw": "http://localhost:3000/api/v1/auth",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"api",
"v1",
"auth"
]
},
"description": "Generates a new API key for accessing the Intergalactic Bank API. This endpoint does not require authentication."
}
}
]
},
{
"name": "Accounts",
"item": [
{
"name": "List all accounts",
"request": {
"method": "GET",
"url": {
"raw": "http://localhost:3000/api/v1/accounts?owner=Nova Newman&createdAt=2023-04-10",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"api",
"v1",
"accounts"
],
"query": [
{
"key": "owner",
"value": "Nova Newman"
},
{
"key": "createdAt",
"value": "2023-04-10"
}
]
},
"description": "Retrieves a list of all accounts at the Intergalactic Bank. Optionally filter by owner name or creation date."
}
},
{
"name": "Create new account",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"owner\": \"Nova Newman\",\n \"balance\": 500,\n \"currency\": \"COSMIC_COINS\"\n}"
},
"url": {
"raw": "http://localhost:3000/api/v1/accounts",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"api",
"v1",
"accounts"
]
},
"description": "Creates a new account at the Intergalactic Bank. The account will be assigned a unique ID. The currency cannot be changed once the account is created."
}
}
]
},
{
"name": "Transactions",
"item": [
{
"name": "List all transactions",
"request": {
"method": "GET",
"url": {
"raw": "http://localhost:3000/api/v1/transactions?fromAccountId=11111111&toAccountId=18974440&createdAt=2024-01-10",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"api",
"v1",
"transactions"
],
"query": [
{
"key": "fromAccountId",
"value": "11111111"
},
{
"key": "toAccountId",
"value": "18974440"
},
{
"key": "createdAt",
"value": "2024-01-10"
}
]
},
"description": "Retrieves a list of transactions. Optionally filter by source account, destination account, or creation date."
}
},
{
"name": "Create new transaction",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"fromAccountId\": \"12345678\",\n \"toAccountId\": \"87654321\",\n \"amount\": 10000,\n \"currency\": \"COSMIC_COINS\"\n}"
},
"url": {
"raw": "http://localhost:3000/api/v1/transactions",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"api",
"v1",
"transactions"
]
},
"description": "Creates a new transaction. There are two types of transactions: Transfer and Deposit. Transactions cannot be edited or deleted once created."
}
},
{
"name": "Get transaction by ID",
"request": {
"method": "GET",
"url": {
"raw": "http://localhost:3000/api/v1/transactions/{transactionId}",
"protocol": "http",
"host": [
"localhost"
],
"port": "3000",
"path": [
"api",
"v1",
"transactions",
"{transactionId}"
]
},
"description": "Retrieves detailed information about a specific transaction by its ID."
}
}
]
}
],
"auth": {
"type": "apikey",
"apikey": [
{
"key": "value",
"value": "{{apiKey}}",
"type": "string"
},
{
"key": "key",
"value": "x-api-key",
"type": "string"
}
]
},
"variable": [
{
"key": "apiKey",
"value": ""
}
]
}
7 changes: 7 additions & 0 deletions postman/globals/workspace.postman_globals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": "1fa9efaf-f1eb-4d4e-8fe4-94937789787a",
"name": "Globals",
"values": [],
"_postman_variable_scope": "globals",
"_postman_exported_at": "2025-11-04T22:21:28.930Z"
}
48 changes: 24 additions & 24 deletions src/routes/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,33 @@ router.get('/', validateApiKey, (req, res) => {
* GET /api/v1/accounts/:accountId
* Get a specific account by ID
*/
// router.get('/:accountId', validateApiKey, (req, res) => {
// try {
// const { accountId } = req.params;
router.get('/:accountId', validateApiKey, (req, res) => {
try {
const { accountId } = req.params;

// const account = db.getAccountById(accountId);
const account = db.getAccountById(accountId);

// if (!account) {
// return res.status(404).json({
// error: {
// name: 'instanceNotFoundError',
// message: 'The specified account does not exist.'
// }
// });
// }
if (!account) {
return res.status(404).json({
error: {
name: 'instanceNotFoundError',
message: 'The specified account does not exist.'
}
});
}

// res.status(200).json({
// account: account.toJSON()
// });
// } catch (error) {
// res.status(500).json({
// error: {
// name: 'serverError',
// message: 'Failed to retrieve account'
// }
// });
// }
// });
res.status(200).json({
account: account.toJSON()
});
} catch (error) {
res.status(500).json({
error: {
name: 'serverError',
message: 'Failed to retrieve account'
}
});
}
});

/**
* POST /api/v1/accounts
Expand Down
Loading