PHP 8.2.30
Preview: settingsController.js Size: 2.33 KB
/home/byroehnu/easepay.easetack.com/controllers/settingsController.js

const { prisma } = require('../config/prisma');

// @desc    Get user settings
// @route   GET /api/settings
// @access  Private
const getUserSettings = async (req, res) => {
  try {
    const userId = req.user.id;

    let settings = await prisma.userSettings.findUnique({
      where: { userId }
    });

    if (!settings) {
      settings = await prisma.userSettings.create({
        data: { userId }
      });
    }

    res.status(200).json({
      success: true,
      data: settings
    });
  } catch (error) {
    console.error('Get user settings error:', error);
    res.status(500).json({
      success: false,
      message: 'Failed to get user settings'
    });
  }
};

// @desc    Update user settings
// @route   PUT /api/settings
// @access  Private
const updateUserSettings = async (req, res) => {
  try {
    const userId = req.user.id;
    const {
      language,
      fontSize,
      currency,
      dateFormat,
      lowStockAlert,
      pushNotifications,
      smsAlerts,
      usePinCode,
      useBiometrics
    } = req.body;

    const settings = await prisma.userSettings.upsert({
      where: { userId },
      update: {
        ...(language !== undefined && { language }),
        ...(fontSize !== undefined && { fontSize }),
        ...(currency !== undefined && { currency }),
        ...(dateFormat !== undefined && { dateFormat }),
        ...(lowStockAlert !== undefined && { lowStockAlert }),
        ...(pushNotifications !== undefined && { pushNotifications }),
        ...(smsAlerts !== undefined && { smsAlerts }),
        ...(usePinCode !== undefined && { usePinCode }),
        ...(useBiometrics !== undefined && { useBiometrics })
      },
      create: {
        userId,
        language,
        fontSize,
        currency,
        dateFormat,
        lowStockAlert,
        pushNotifications,
        smsAlerts,
        usePinCode,
        useBiometrics
      }
    });

    res.status(200).json({
      success: true,
      message: 'Settings updated successfully',
      data: settings
    });
  } catch (error) {
    console.error('Update user settings error:', error);
    res.status(500).json({
      success: false,
      message: 'Failed to update user settings'
    });
  }
};

module.exports = {
  getUserSettings,
  updateUserSettings
};

Directory Contents

Dirs: 1 × Files: 17

Name Size Perms Modified Actions
- drwxr-xr-x 2026-03-20 23:25:48
Edit Download
127 B lr--r--r-- 2026-03-14 01:49:22
Edit Download
15.34 KB lrw-r--r-- 2026-02-19 22:06:47
Edit Download
30.77 KB lrw-r--r-- 2026-03-04 06:33:18
Edit Download
62.98 KB lrw-r--r-- 2026-03-01 23:46:52
Edit Download
10.79 KB lrw-r--r-- 2026-02-07 16:28:16
Edit Download
14.17 KB lrw-r--r-- 2026-02-27 04:02:38
Edit Download
6.32 KB lrw-r--r-- 2026-02-06 17:10:19
Edit Download
15.13 KB lrw-r--r-- 2026-03-01 05:05:51
Edit Download
8.50 KB lrw-r--r-- 2026-03-01 05:05:52
Edit Download
12.15 KB lrw-r--r-- 2026-02-27 04:02:38
Edit Download
25.39 KB lrw-r--r-- 2026-03-01 05:05:51
Edit Download
17.61 KB lrw-r--r-- 2026-03-01 05:05:51
Edit Download
6.45 KB lrw-r--r-- 2026-03-01 05:05:51
Edit Download
2.33 KB lrw-r--r-- 2026-03-01 05:05:51
Edit Download
12.78 KB lrw-r--r-- 2026-02-21 08:13:30
Edit Download
9.96 KB lrw-r--r-- 2026-03-01 05:05:51
Edit Download
8.51 KB lrw-r--r-- 2026-02-20 19:31:28
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).