Spaces:
Sleeping

asd / src /modules /shopify /presentation /http /controllers /ShopifySyncController.ts
GitHub Actions
deploy: clean snapshot
7f81110
Raw History Blame Contribute Delete
1.28 kB
import { Request, Response } from "express";
import { TriggerSyncUseCase } from "../../../application/useCases/sync/TriggerSyncUseCase";
import { PgSyncJobRepository } from "../../../infrastructure/postgres/repositories/PgSyncJobRepository";
import { InMemoryEventPublisher } from "../../../application/ports/IEventPublisher";
export const ShopifySyncController = async (req: Request, res: Response): Promise<void> => {
// ── Shared instances β€” created inside function to ensure DB connection is ready ──
const syncJobRepository = new PgSyncJobRepository();
const eventPublisher = new InMemoryEventPublisher();
const tenantContext = req.tenantContext;
if (!tenantContext) {
// Should never happen β€” TenantMiddleware runs before this
res.status(401).json({ error: { code: "UNAUTHORIZED", message: "Tenant context missing" } });
return;
}
const action = (req.body?.action as "full" | "retry_failed") || "full";
const useCase = new TriggerSyncUseCase(tenantContext, syncJobRepository, eventPublisher);
const result = await useCase.execute({
tenantId: tenantContext.tenantId,
action,
});
res.status(202).json(result);
// Errors bubble to GlobalErrorHandler β€” no try/catch here
};