MCJIM NestJS Backend
Internal backend APIs for pricing, printing, SKU tools, and user management
Back to hub

API Docs

High-level reference for the NestJS backend. Describes endpoint behavior, database usage, and how the service queries flow.

Databases
Logical MSSQL connections used by this backend
ERPDB
ERP master/price tables. Used mainly for item/SKU lookups and price validation.
McJIMAllProgDB
Program/masterdata tables. Used for store assignments, access constants, and master records.
barcodeDataDB
Primary print DB. Stores print flags, vendor mapping, generated barcode items, and audit artifacts.
tableSKUDB
Table/SKU lookup DB for SKU guide and table-backed lookups.
masterSKUDB
Master SKU reference data.
Query pattern

Services use TypeORM DataSource/QueryRunner across multiple named MSSQL connections. Transactional writes happen inside QueryRunner, while reads often go through custom repositories with raw parametrized SQL. Controllers branch behavior by barcode type/company/OS before generating PRN/template output.

Auth
Local auth, JWT refresh, and permission lookup
POST /auth/login

Local login. Returns access/refresh tokens. Uses LocalGuard.

POST /auth/refresh

Refresh access token using refresh token. Guard: jwt-refresh.

POST /auth/logout

Logs the user out and clears the auth cookie.

GET /auth/permissions

Returns current user permissions plus module constants: ALL_MODULE_NAMES, ALL_AVAILABLE_PERMISSIONS, and grouped view access for printModulesViewAccess, SKUorUPCModulesViewAccess, managementModulesViewAccess.

Auto Print
TD tag search, price recalibration, and sticker receipt generation
GET /autoprint/search-TD

Lookup TD/store details. Query: TDNumber.

PATCH /autoprint/recalibrate-price

Recalibrates TD prices using a new effective date. Body: TDNumber, dateEffective.

Query flow
1. Loads old delivery-date/gross/net values from barcodeDataDB.
2. Runs recalibration SQL on barcodeDataDB using the provided effective date.
3. Verifies RowsAffected; throws if none.
4. Loads new values, writes audit log with old/new snapshot.
POST /autoprint/print

Regular print job. Requires OS as WINDOWS or LINUX. Linux returns binary PRN; Windows returns JSON template + base64.

Query flow
1. Opens DB transaction on barcodeDataDB.
2. Sets existing c_print_flag=Y records for this TD to inactive.
3. Maps store company to vendor/code: CARAVAN, TELSTAR, MIRAGE.
4. Inserts new barcode rows with priceType R; commits.
5. Outside transaction: Linux generates PRN; Windows fetches template/data JSON.
POST /autoprint/print-sale

Sale sticker print job. Same OS branching as /print with priceType S.

POST /autoprint/print-sm-both

Prints both regular and sale SM stickers. Uses priceType B for barcode DB inserts. Linux returns base64 buffers in JSON.

Query flow
1. Inserts shared barcode rows with priceType B.
2. Linux path builds both regular and sale PRN buffers.
3. Windows path returns data/template pairs for both sticker types in one response.
Manual Print
Store/SKU lookup and ad-hoc barcode sticker printing
GET /manualprint/store-details

Get store info by entity code from custom repository queries. Query: entityCode.

GET /manualprint/stock-number-SKU-details

Resolves stock/SKU details. Supports free-item fallback and requires active price context via dateEffective, entityCode, priceType, s_barcode_type, s_company_code.

Query flow
1. If Item.repository finds the stock number as Give Aways/free item, returns FREE ITEM with price=0.
2. Otherwise fetches latest price from ERPDB.
3. Resolves internal company code from retailer/company mapping.
4. Routes into barcode-type-specific SKU SQL branches: SM, LM, ROB, ICM, KCC, METRO, WM, or price-only fallback.
POST /manualprint/print

Generates regular sticker print. Body includes barcode data, selected items, driver, OS flag, and remarks.

Query flow
1. TXN: sets prior user prints inactive on barcodeDataDB.
2. Maps company to vendor/code: CARAVAN/TELSTAR/MIRAGE.
3. Inserts selected items with priceType R.
4. Outside TXN: Linux returns PRN; Windows returns template + base64 JSON.
POST /manualprint/print-sale

Sale sticker version of manual print. Price type is fixed to S.

Query flow
Same structure as /manualprint/print, but inserts with priceType S and generates sale-specific template/data on Windows.
POST /manualprint/print-sm-both

Prints regular + sale SM stickers together. Uses priceType B for shared DB insert then generates both outputs.

Query flow
1. Inserts items with priceType B in one transaction.
2. Linux returns regular + sale PRN buffers as base64 JSON.
3. Windows returns data/template pairs for both sticker types.
SKU Masterlist Tools
Excel masterlist generation and SKU lookup guide
POST /sku-masterlist-tools/download-sku-masterlist

Download SKU masterlist. Body payload determines retailer/filters. Returns filename + buffer.

Query flow
1. Validates payload and current user.
2. Queries retailer SKU source tables.
3. Generates an Excel file and returns it as a buffer.
POST /sku-masterlist-tools/download-no-sku-masterlist

Download no-SKU masterlist. Body payload targets missing-SKU items. Returns filename + buffer.

Query flow
1. Uses payload filters to find items with no SKU assignment.
2. Builds Excel output from missing-SKU result set.
GET /sku-masterlist-tools/sku-guide

Returns SKU lookup guide data for a retailer. Query: retailer.

SKU Request Automation
Stock number resolution and Excel SKU request generation
GET /sku-request-automation/stock-number-details

Fetch stock number details. Query: stockNumber, retailer.

Query flow
1. Validates stock number and retailer.
2. Queries master/ERP sources to resolve stock metadata.
3. Returns normalized stock details for the request form.
POST /sku-request-automation/download-excel-sku-request

Generate SKU request Excel from payload rows. Returns filename + buffer.

Query flow
1. Takes request payload rows from body.
2. Writes Excel workbook with requester metadata.
3. Returns downloaded filename and raw buffer.
User Management
User listing, permission calculation, and permission toggles
GET /user-management/get-users

Paginated user list. Query: username, page, limit. Returns users + pagination metadata. Requires USER_MANAGEMENT_VIEW.

Query flow
1. Queries user records with optional username filter + pagination.
2. Queries total count separately for pagination metadata.
3. Writes audit log: viewer + entered-user-management-module event.
GET /user-management/get-user-permissions/:username

Get calculated permissions for a user. Query: moduleName. Requires USER_MANAGEMENT_VIEW.

POST /user-management/toggle-permission

Toggle a user permission. Body: username, accessCode, isAllow. Requires USER_MANAGEMENT_VIEW + USER_MANAGEMENT_TOGGLE.

Query flow
1. Validates caller permissions.
2. Toggles permission row for the target user.
3. Writes audit log on who changed what and whom.
Source

Local backend module:

/var/www/html/mcjim-nestjs-backend