add profile
This commit is contained in:
@@ -12,7 +12,14 @@ const getSupabaseKey = async () => {
|
|||||||
return data.features['sber_mobile'].SUPABASE_KEY.value;
|
return data.features['sber_mobile'].SUPABASE_KEY.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getSupabaseServiceKey = async () => {
|
||||||
|
const response = await fetch('https://admin.bro-js.ru/api/config/v1/dev');
|
||||||
|
const data = await response.json();
|
||||||
|
return data.features['sber_mobile'].SUPABASE_SERVICE_KEY.value;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getSupabaseUrl,
|
getSupabaseUrl,
|
||||||
getSupabaseKey,
|
getSupabaseKey,
|
||||||
|
getSupabaseServiceKey
|
||||||
};
|
};
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
const router = require('express').Router();
|
const router = require('express').Router();
|
||||||
const authRouter = require('./auth');
|
const authRouter = require('./auth');
|
||||||
const { supabaseRouter } = require('./supabaseClient');
|
const { supabaseRouter } = require('./supabaseClient');
|
||||||
const profileRouter = require('./users/index');
|
const profileRouter = require('./profile');
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
||||||
|
|||||||
54
server/routers/kfu-m-24-1/sber_mobile/profile.js
Normal file
54
server/routers/kfu-m-24-1/sber_mobile/profile.js
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
const router = require('express').Router();
|
||||||
|
const { getSupabaseClient } = require('./supabaseClient');
|
||||||
|
|
||||||
|
// GET /profile
|
||||||
|
router.get('/profile', async (req, res) => {
|
||||||
|
const { user_id } = req.body;
|
||||||
|
const supabase = getSupabaseClient();
|
||||||
|
let { data: userData, error: userError } = await supabase.auth.admin.getUserById(user_id);
|
||||||
|
|
||||||
|
if (userError) return res.status(400).json({ error: userError.message });
|
||||||
|
|
||||||
|
let { data: profileData, error: profileError } = await supabase.from('user_profiles').select(`
|
||||||
|
id,
|
||||||
|
full_name,
|
||||||
|
avatar_url,
|
||||||
|
updated_at
|
||||||
|
`).eq('id', user_id).single();
|
||||||
|
|
||||||
|
if (profileError) return res.status(400).json({ error: profileError.message });
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
id: profileData.id,
|
||||||
|
username: profileData.full_name,
|
||||||
|
avatar_url: profileData.avatar_url,
|
||||||
|
phone: userData.user.phone,
|
||||||
|
apartment: '9',
|
||||||
|
updated_at: profileData.updated_at
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// POST /profile
|
||||||
|
router.post('/profile', async (req, res) => {
|
||||||
|
const { user_id, data } = req.body;
|
||||||
|
const supabase = getSupabaseClient();
|
||||||
|
|
||||||
|
const { data: userData, error: userError } = await supabase.auth.admin.updateUserById(
|
||||||
|
user_id,
|
||||||
|
{ phone: data.phone }
|
||||||
|
)
|
||||||
|
|
||||||
|
if (userError) return res.status(400).json({ error: userError.message });
|
||||||
|
|
||||||
|
let { error: profileError } = await supabase.from('user_profiles').update({
|
||||||
|
full_name: data.username,
|
||||||
|
avatar_url: data.avatar_url,
|
||||||
|
// apartment: data.apartment
|
||||||
|
}).eq('id', user_id).single();
|
||||||
|
|
||||||
|
if (profileError) return res.status(400).json({ error: profileError.message });
|
||||||
|
|
||||||
|
res.json({ success: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
const router = require('express').Router();
|
const router = require('express').Router();
|
||||||
const { createClient } = require('@supabase/supabase-js');
|
const { createClient } = require('@supabase/supabase-js');
|
||||||
const { getSupabaseUrl, getSupabaseKey } = require('./get-constants');
|
const { getSupabaseUrl, getSupabaseKey, getSupabaseServiceKey } = require('./get-constants');
|
||||||
|
|
||||||
let supabase = null;
|
let supabase = null;
|
||||||
|
|
||||||
async function initSupabaseClient() {
|
async function initSupabaseClient() {
|
||||||
const supabaseUrl = await getSupabaseUrl();
|
const supabaseUrl = await getSupabaseUrl();
|
||||||
const supabaseAnonKey = await getSupabaseKey();
|
const supabaseAnonKey = await getSupabaseKey();
|
||||||
supabase = createClient(supabaseUrl, supabaseAnonKey);
|
const supabaseServiceRoleKey = await getSupabaseServiceKey();
|
||||||
|
supabase = createClient(supabaseUrl, supabaseServiceRoleKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSupabaseClient() {
|
function getSupabaseClient() {
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
const router = require('express').Router();
|
|
||||||
const { getSupabaseClient } = require('../supabaseClient');
|
|
||||||
|
|
||||||
// POST /profile
|
|
||||||
router.get('/profile', async (req, res) => {
|
|
||||||
const { user_id } = req.body;
|
|
||||||
const supabase = getSupabaseClient();
|
|
||||||
const { data, error } = await supabase.from('users').select(`
|
|
||||||
id,
|
|
||||||
phone,
|
|
||||||
user_profiles(full_name,avatar_url,updated_at)
|
|
||||||
`).eq('id', user_id);
|
|
||||||
console.log('@@@@@@@@@@@@@@@@@@@@@@@@');
|
|
||||||
console.log(data);
|
|
||||||
if (error) return res.status(400).json({ error: error.message });
|
|
||||||
res.json({
|
|
||||||
id: data.id,
|
|
||||||
username: data.user_profiles.full_name,
|
|
||||||
avatar_url: data.user_profiles.avatar_url,
|
|
||||||
phone: data.phone,
|
|
||||||
apartment: '9',
|
|
||||||
updated_at: data.user_profiles.updated_at
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router;
|
|
||||||
Reference in New Issue
Block a user