Massive backend refactoring done
This commit is contained in:
40
server/src/controllers/plan.controller.ts
Normal file
40
server/src/controllers/plan.controller.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Request, Response } from 'express';
|
||||
import { PlanService } from '../services/plan.service';
|
||||
import { sendSuccess, sendError } from '../utils/apiResponse';
|
||||
import logger from '../utils/logger';
|
||||
|
||||
export class PlanController {
|
||||
static async getPlans(req: any, res: Response) {
|
||||
try {
|
||||
const userId = req.user.userId;
|
||||
const plans = await PlanService.getPlans(userId);
|
||||
return sendSuccess(res, plans);
|
||||
} catch (error) {
|
||||
logger.error('Error in getPlans', { error });
|
||||
return sendError(res, 'Server error', 500);
|
||||
}
|
||||
}
|
||||
|
||||
static async savePlan(req: any, res: Response) {
|
||||
try {
|
||||
const userId = req.user.userId;
|
||||
const plan = await PlanService.savePlan(userId, req.body);
|
||||
return sendSuccess(res, plan);
|
||||
} catch (error) {
|
||||
logger.error('Error in savePlan', { error });
|
||||
return sendError(res, 'Server error', 500);
|
||||
}
|
||||
}
|
||||
|
||||
static async deletePlan(req: any, res: Response) {
|
||||
try {
|
||||
const userId = req.user.userId;
|
||||
const { id } = req.params;
|
||||
await PlanService.deletePlan(userId, id);
|
||||
return sendSuccess(res, null);
|
||||
} catch (error) {
|
||||
logger.error('Error in deletePlan', { error });
|
||||
return sendError(res, 'Server error', 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user