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
1 change: 0 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"passport-github2": "^0.1.12",
"passport-google-oauth20": "^2.0.0",
"passport-local": "^1.0.0",
"razorpay": "^2.9.6",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
Expand Down
7 changes: 0 additions & 7 deletions api/src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const REQUIRED_ENV_VARS = [
'INGRESS_BASE_DOMAIN',
'MANIFESTS_DIR',
'GROQ',
'RAZORPAY_KEY_ID',
'RAZORPAY_KEY_SECRET',
'PROMETHEUS_URL',
];

Expand Down Expand Up @@ -72,11 +70,6 @@ const env = {
// GROQ API key or endpoint
GROQ: process.env.GROQ,

// Razorpay
RAZORPAY_KEY_ID: process.env.RAZORPAY_KEY_ID,
RAZORPAY_KEY_SECRET: process.env.RAZORPAY_KEY_SECRET,
RAZORPAY_WEBHOOK_SECRET: process.env.RAZORPAY_WEBHOOK_SECRET,

// Prometheus URL for metrics
PROMETHEUS_URL: process.env.PROMETHEUS_URL || 'http://localhost:9090',

Expand Down
70 changes: 0 additions & 70 deletions api/src/controllers/plans/razorpay.controller.ts

This file was deleted.

1 change: 0 additions & 1 deletion api/src/models/plan.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const planSchema = new Schema<IPlan & Document>(
limits: ResourceSchema,
},
isDefault: { type: Boolean, default: false },
price: { type: Number /* Price in paise (integer) */ },
isActive: { type: Boolean, default: true },
},
{ timestamps: true }
Expand Down
10 changes: 1 addition & 9 deletions api/src/routes/plan.routes.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// Plan routes for managing subscription plans and handling payments
// Plan routes for managing subscription plans
import { Router } from 'express';
import { ensureAdmin } from '../auth/role.middleware';
import asyncHandler from '../utils/handlers/asyncHandler';
import express from 'express';
import getPlanByID from '../controllers/plans/getPlanByID.controller';
import createPlan from '../controllers/plans/createPlan.controller';
import getPlans from '../controllers/plans/getPlans.controller';
import updatePlan from '../controllers/plans/updatePlan.controller';
import deletePlan from '../controllers/plans/deletePlan.controller';
import { createOrder, verifyPayment } from '../controllers/plans/razorpay.controller';

const router = Router();

Expand All @@ -17,12 +15,6 @@ router.get('/:id', asyncHandler(getPlanByID));
// Public: Get all plans
router.get('/', asyncHandler(getPlans));

// Razorpay payment endpoints (public)
router.post('/:id/create-order', asyncHandler(createOrder));
router.post('/verify-payment', express.json(), (req, res) => {
verifyPayment(req, res);
});

// All plan management routes below require admin privileges
router.use(ensureAdmin);

Expand Down
2 changes: 0 additions & 2 deletions api/src/types/plan.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ export default interface IPlan {
limits?: Resource;
};
isDefault?: boolean;
/** Price in paise (integer) */
price?: number;
isActive?: boolean;
}
26 changes: 15 additions & 11 deletions api/src/utils/k8s/helpers/toK8sResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,34 @@ export default function toK8sResource(
type: 'cpu' | 'memory'
): string {
if (val === undefined || val === null || val === '') return type === 'cpu' ? '0m' : '0Mi';

// Frontend/base units:
// - CPU is provided in millicores (m)
// - Memory is provided in megabytes (MB ~ MiB)
if (typeof val === 'number') {
if (type === 'cpu') {
// CPU is in cores (e.g., 0.25 = 250m, 1 = 1000m)
if (val < 1) return `${Math.round(val * 1000)}m`;
return `${Math.round(val * 1000)}m`;
// CPU already in millicores
return `${Math.round(val)}m`;
}
if (type === 'memory') {
// Memory is in bytes, convert to MiB for K8s
return `${Math.round(val / (1024 * 1024))}Mi`;
// Memory already in MB -> use Mi in K8s
return `${Math.round(val)}Mi`;
}
}

if (typeof val === 'string') {
// If already ends with m, Mi, Gi, etc., return as is
// If already ends with appropriate unit, return as-is
if (type === 'cpu' && /m$/.test(val)) return val;
if (type === 'memory' && /(Mi|Gi)$/.test(val)) return val;
// If it's a plain number string, parse and convert

// If it's a plain number string, interpret using base units above
const numVal = parseFloat(val);
if (!isNaN(numVal)) {
if (type === 'cpu') {
return `${Math.round(numVal * 1000)}m`;
}
return `${Math.round(numVal / (1024 * 1024))}Mi`;
if (type === 'cpu') return `${Math.round(numVal)}m`;
return `${Math.round(numVal)}Mi`;
}
return val;
}

return type === 'cpu' ? '0m' : '0Mi';
}
6 changes: 1 addition & 5 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ MANIFESTS_DIR=
# GROQ
GROQ=

# Razorpay
RAZORPAY_KEY_ID=
RAZORPAY_KEY_SECRET=

# Prometheus URL for metrics
PROMETHEUS_URL= # Use http://localhost:9090 or your prometheus url

# Persistent volume root directory
VOLUME_ROOT_PATH=
VOLUME_ROOT_PATH=
Loading
Loading