SpaceNinjaServer/src/controllers/api/getVendorInfoController.ts
Sainan 12d09531b3
All checks were successful
Build / build (push) Successful in 44s
Build Docker image / docker (push) Successful in 10s
feat: add dev.keepVendorsExpired config option (#2161)
Reviewed-on: #2161
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
2025-06-14 12:58:26 -07:00

30 lines
1.2 KiB
TypeScript

import { RequestHandler } from "express";
import { applyStandingToVendorManifest, getVendorManifestByTypeName } from "@/src/services/serversideVendorsService";
import { getInventory } from "@/src/services/inventoryService";
import { getAccountIdForRequest } from "@/src/services/loginService";
import { config } from "@/src/services/configService";
export const getVendorInfoController: RequestHandler = async (req, res) => {
let manifest = getVendorManifestByTypeName(req.query.vendor as string);
if (!manifest) {
throw new Error(`Unknown vendor: ${req.query.vendor as string}`);
}
// For testing purposes, authenticating with this endpoint is optional here, but would be required on live.
if (req.query.accountId) {
const accountId = await getAccountIdForRequest(req);
const inventory = await getInventory(accountId);
manifest = applyStandingToVendorManifest(inventory, manifest);
if (config.dev?.keepVendorsExpired) {
manifest = {
VendorInfo: {
...manifest.VendorInfo,
Expiry: { $date: { $numberLong: "0" } }
}
};
}
}
res.json(manifest);
};