pls-nhandan-souvernir-be
v1.2.0
Published
tRPC server for nhandan-souvernir app with MongoDB integration
Maintainers
Readme
nhandan-souvernir-be
A tRPC server for the Nhandan Souvenir application with MongoDB integration, providing type-safe API endpoints for History, Order, and Tracking entities.
Installation
npm install nhandan-souvernir-beConfiguration
Create a .env file in your project root with the following variables:
MONGODB_URI=mongodb://username:password@host1:27017,host2:27017,host3:27017/database-name?authSource=admin&replicaSet=rs0
PORT=3033Usage
Starting the Server
// Import and start the server
import 'nhandan-souvernir-be';Using Types and Schemas in Your Client
import type { AppRouter } from 'nhandan-souvernir-be';
import { createOrderSchema, historyFilterSchema } from 'nhandan-souvernir-be';
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
// Create a tRPC client
const trpc = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: 'http://localhost:3033',
}),
],
});
// Use the client to interact with the API
async function fetchOrders() {
const orders = await trpc.order.getAll.query({
pagination: {
page: 1,
limit: 10
}
});
console.log(orders);
}Available API Endpoints
History Endpoints
history.create- Create a new history recordhistory.getAll- Get all history records with pagination and filteringhistory.getById- Get a single history record by IDhistory.update- Update a history recordhistory.delete- Delete a history record
Order Endpoints
order.create- Create a new orderorder.getAll- Get all orders with pagination and filteringorder.getById- Get a single order by IDorder.getByOrderId- Get an order by order_idorder.update- Update an orderorder.delete- Delete an order
Tracking Endpoints
tracking.create- Create a new tracking recordtracking.getAll- Get all tracking records with pagination and filteringtracking.getById- Get a single tracking record by IDtracking.getByOrderId- Get tracking records by order_idtracking.update- Update a tracking recordtracking.delete- Delete a tracking record
License
ISC
