-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpreferenceController.js
More file actions
31 lines (28 loc) · 1.24 KB
/
preferenceController.js
File metadata and controls
31 lines (28 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Preference Controller
* Manages user preference profiles
* @module controllers/preferenceController
*/
import db from '../config/db.js';
import buildHateoasLinks from '../utils/hateoasBuilder.js';
import R from '../utils/responseBuilder.js';
import { requireUser } from '../utils/controllerValidators.js';
import preferenceCreate from './preferenceCreate.js';
import preferenceModify from './preferenceModify.js';
import { normalizeProfiles } from './preferenceCreate.js';
const getPreferenceProfiles = async (req, res, next) => {
try {
const userId = parseInt(req.params.userId);
const user = await requireUser(res, userId);
if (!user) return;
const profiles = await db.getPreferenceProfiles(userId);
return R.success(res, { profiles: normalizeProfiles(profiles), links: buildHateoasLinks.preferenceProfilesCollection(userId) }, 'Preference profiles retrieved successfully');
} catch (error) { next(error); }
};
export default {
getPreferenceProfiles,
createPreferenceProfile: preferenceCreate.createPreferenceProfile,
updatePreferenceProfile: preferenceModify.updatePreferenceProfile,
deletePreferenceProfile: preferenceModify.deletePreferenceProfile,
activatePreferenceProfile: preferenceModify.activatePreferenceProfile
};