-- Fix QC001 user role assignment
-- This script updates the QC001 user to have the correct QC_USER role

-- First, let's see what role QC001 currently has
SELECT 
  l.login_id,
  l.member_id, 
  l.name, 
  l.role_id,
  l.treelogy_id,
  l.client_id,
  u.role_name,
  u.role_display_name
FROM login l
LEFT JOIN user_master u ON l.role_id = u.id
WHERE l.member_id = 'QC001';

-- Update QC001 to have QC_USER role (role_id = 4)
UPDATE login 
SET role_id = (SELECT id FROM user_master WHERE role_name = 'QC_USER'),
    "updatedAt" = NOW()
WHERE member_id = 'QC001';

-- Verify the update
SELECT 
  l.login_id,
  l.member_id, 
  l.name, 
  l.role_id,
  u.role_name,
  u.role_display_name
FROM login l
JOIN user_master u ON l.role_id = u.id
WHERE l.member_id = 'QC001';

-- Also verify the password is properly hashed
SELECT 
  member_id,
  name,
  substring(password, 1, 10) as password_prefix,
  length(password) as password_length
FROM login
WHERE member_id = 'QC001';
-- Password should start with $2a$ or $2b$ and be ~60 characters long

