feat(admin-center): implement admin center settings retrieval and enhance holiday population logic

- Added a new API endpoint in AdminCenterController to fetch admin center settings, including organization details.
- Updated the admin center API router to include the new settings route.
- Enhanced the holiday controller to check for recent holiday population before attempting to repopulate, preventing duplicate entries.
- Improved the holiday calendar component to manage holiday population attempts and display loading states.
- Updated localization files to support new messages related to calculation methods and holiday settings.
This commit is contained in:
chamikaJ
2025-07-30 11:35:12 +05:30
parent 069ae6ccb1
commit 9dfc1fa375
19 changed files with 340 additions and 226 deletions

View File

@@ -71,6 +71,27 @@ export default class AdminCenterController extends WorklenzControllerBase {
contact_number,
contact_number_secondary,
(SELECT email FROM users WHERE id = organizations.user_id),
(SELECT name FROM users WHERE id = organizations.user_id) AS owner_name,
calculation_method,
hours_per_day
FROM organizations
WHERE user_id = $1;`;
const result = await db.query(q, [req.user?.owner_id]);
const [data] = result.rows;
return res.status(200).send(new ServerResponse(true, data));
}
@HandleExceptions()
public static async getAdminCenterSettings(
req: IWorkLenzRequest,
res: IWorkLenzResponse
): Promise<IWorkLenzResponse> {
const q = `SELECT organization_name AS name,
contact_number,
contact_number_secondary,
calculation_method,
hours_per_day,
(SELECT email FROM users WHERE id = organizations.user_id),
(SELECT name FROM users WHERE id = organizations.user_id) AS owner_name
FROM organizations
WHERE user_id = $1;`;

View File

@@ -264,6 +264,27 @@ export default class HolidayController extends WorklenzControllerBase {
@HandleExceptions()
public static async populateCountryHolidays(req: IWorkLenzRequest, res: IWorkLenzResponse): Promise<IWorkLenzResponse> {
// Check if this organization has recently populated holidays (within last hour)
const recentPopulationCheck = `
SELECT COUNT(*) as count
FROM organization_holidays
WHERE organization_id = (SELECT id FROM organizations WHERE user_id = $1)
AND created_at > NOW() - INTERVAL '1 hour'
`;
const recentResult = await db.query(recentPopulationCheck, [req.user?.owner_id]);
const recentCount = parseInt(recentResult.rows[0]?.count || '0');
// If there are recent holidays added, skip population
if (recentCount > 10) {
return res.status(200).send(new ServerResponse(true, {
success: true,
message: "Holidays were recently populated, skipping to avoid duplicates",
total_populated: 0,
recently_populated: true
}));
}
const Holidays = require("date-holidays");
const countries = [

View File

@@ -8,6 +8,7 @@ import teamOwnerOrAdminValidator from "../../middlewares/validators/team-owner-o
const adminCenterApiRouter = express.Router();
// overview
adminCenterApiRouter.get("/settings", teamOwnerOrAdminValidator, safeControllerFunction(AdminCenterController.getAdminCenterSettings));
adminCenterApiRouter.get("/organization", teamOwnerOrAdminValidator, safeControllerFunction(AdminCenterController.getOrganizationDetails));
adminCenterApiRouter.get("/organization/admins", teamOwnerOrAdminValidator, safeControllerFunction(AdminCenterController.getOrganizationAdmins));
adminCenterApiRouter.put("/organization", teamOwnerOrAdminValidator, organizationSettingsValidator, safeControllerFunction(AdminCenterController.updateOrganizationName));