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
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"bcrypt": "^5.1.1",
"cors": "^2.8.5",
"decimal.js": "^10.6.0",
"dotenv": "^16.3.1",
"express": "^5.2.1",
"express-rate-limit": "^7.1.5",
Expand All @@ -38,6 +39,7 @@
"@commitlint/config-conventional": "^20.5.0",
"@types/bcrypt": "^5.0.2",
"@types/cors": "^2.8.17",
"@types/decimal.js": "^0.0.32",
"@types/express": "^5.0.0",
"@types/jest": "^29.5.11",
"@types/jsonwebtoken": "^9.0.5",
Expand Down
16 changes: 13 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import { getMetricsContentType, MetricsRegistry } from "./observability/metrics"
import { createAuthRouter } from "./routes/auth.routes";
import { createNotificationRouter } from "./routes/notification.routes";
import { createInvoiceRouter } from "./routes/invoice.routes";
import { createInvestmentRouter } from "./routes/investment.routes";

import type { AuthService } from "./services/auth.service";
import type { NotificationService } from "./services/notification.service";
import type { InvoiceService } from "./services/invoice.service";
import type { InvestmentService } from "./services/investment.service";

import dataSource from "./config/database";

Expand Down Expand Up @@ -49,9 +51,11 @@ export interface AppDependencies {
authService: AuthService;
notificationService?: NotificationService;
invoiceService?: InvoiceService;
investmentService?: InvestmentService;
logger?: AppLogger;
metricsEnabled?: boolean;
metricsRegistry?: MetricsRegistry;
config?: import("./config/env").AppConfig;

http?: {
trustProxy?: boolean | number | string;
Expand All @@ -70,9 +74,11 @@ export function createApp({
authService,
notificationService,
invoiceService,
investmentService,
logger: appLogger = logger,
metricsEnabled = true,
metricsRegistry = new MetricsRegistry(),
config,
http,
}: AppDependencies) {
const app = express();
Expand Down Expand Up @@ -159,12 +165,16 @@ export function createApp({
app.use("/api/v1/notifications", createNotificationRouter(notificationService, authService));
}

if (invoiceService) {
app.use("/api/v1/invoices", createInvoiceRouter({ invoiceService, config: {} as never }));
if (invoiceService && config) {
app.use("/api/v1/invoices", createInvoiceRouter({ invoiceService, config }));
}

if (investmentService) {
app.use("/api/v1/investments", createInvestmentRouter({ investmentService, authService }));
}

app.use(notFoundMiddleware);
app.use(createErrorMiddleware(appLogger));

return app;
}
}
13 changes: 12 additions & 1 deletion src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export interface AppConfig {
maxUploads: number;
};
};
kyc: {
skipVerification: boolean;
};
}


Expand Down Expand Up @@ -276,5 +279,13 @@ export function getConfig(): AppConfig {
),
},
},

kyc: {
skipVerification: parseBoolean(
process.env.SKIP_KYC_VERIFICATION,
process.env.NODE_ENV !== "production",
"SKIP_KYC_VERIFICATION"
),
},
};
}
}
50 changes: 50 additions & 0 deletions src/controllers/investment.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Response } from "express";
import { InvestmentService } from "../services/investment.service";
import { AuthenticatedRequest } from "../types/auth";
import { requireApprovedKYC } from "../lib/kyc";

export class InvestmentController {
constructor(private readonly investmentService: InvestmentService) {}

createInvestment = async (req: AuthenticatedRequest, res: Response) => {
try {
const user = req.user;
if (!user) {
return res.status(401).json({ error: "Unauthorized" });
}

// Enforce KYC check
requireApprovedKYC(user);

const { invoiceId, investmentAmount } = req.body;

if (!invoiceId || !investmentAmount) {
return res.status(400).json({
error: {
code: "MISSING_FIELDS",
message: "invoiceId and investmentAmount are required",
},
});
}

const investment = await this.investmentService.createInvestment({
invoiceId,
investorId: user.id,
investmentAmount,
});

return res.status(201).json({
success: true,
data: investment,
});
} catch (err: unknown) {
const statusCode = (err as { status?: number }).status || (err as { statusCode?: number }).statusCode || 400;
return res.status(statusCode).json({
error: {
code: (err as { code?: string }).code || "INTERNAL_ERROR",
message: (err as { message?: string }).message || "Internal server error",
},
});
}
};
}
Loading
Loading