Browse Source

fix ts errors

drawing-pad
Stephanie Gredell 1 month ago
parent
commit
5989680b1d
  1. 7
      backend/src/controllers/settingsProfiles.controller.ts
  2. 13
      backend/src/controllers/users.controller.ts

7
backend/src/controllers/settingsProfiles.controller.ts

@ -55,8 +55,9 @@ export async function getAllProfiles(req: AuthRequest, res: Response) {
} }
const profile = profilesMap.get(profileId)!; const profile = profilesMap.get(profileId)!;
if (row.setting_key) { const settingKey = row.setting_key as string | null;
profile.settings[row.setting_key] = row.setting_value; if (settingKey) {
profile.settings[settingKey] = row.setting_value as string;
} }
} }
@ -231,7 +232,7 @@ export async function createProfile(req: AuthRequest, res: Response) {
args: [magicCode, name.trim(), description?.trim() || null, req.userId] args: [magicCode, name.trim(), description?.trim() || null, req.userId]
}); });
const profileId = profileResult.lastInsertRowid as number; const profileId = Number(profileResult.lastInsertRowid);
// Add settings // Add settings
await db.execute({ await db.execute({

13
backend/src/controllers/users.controller.ts

@ -94,9 +94,10 @@ export async function createUser(req: AuthRequest, res: Response) {
}); });
// Get created user // Get created user
const newUserId = Number(result.lastInsertRowid);
const newUser = await db.execute({ const newUser = await db.execute({
sql: 'SELECT id, username, role, created_at FROM users WHERE id = ?', sql: 'SELECT id, username, role, created_at FROM users WHERE id = ?',
args: [result.lastInsertRowid] args: [newUserId]
}); });
res.status(201).json({ res.status(201).json({
@ -366,6 +367,16 @@ export async function changePassword(req: AuthRequest, res: Response) {
} }
// Allow admin to change any password, or user to change their own // Allow admin to change any password, or user to change their own
if (!req.userId) {
return res.status(401).json({
success: false,
error: {
code: 'UNAUTHORIZED',
message: 'Authentication required'
}
});
}
if (userId !== req.userId) { if (userId !== req.userId) {
// Check if requester is admin (this should already be checked by middleware, but double-check) // Check if requester is admin (this should already be checked by middleware, but double-check)
const requester = await db.execute({ const requester = await db.execute({

Loading…
Cancel
Save