Just making a mess mostly I think
This commit is contained in:
@ -7,7 +7,6 @@ export type UserWithStatus = {
|
||||
id?: string;
|
||||
user: Profile;
|
||||
status: string;
|
||||
avatar_url?: string;
|
||||
created_at: string;
|
||||
updated_by?: Profile;
|
||||
};
|
||||
@ -54,20 +53,33 @@ export const getRecentUsersWithStatuses = async (): Promise<
|
||||
return true;
|
||||
});
|
||||
|
||||
const filteredWithAvatars: UserWithStatus[] = filtered;
|
||||
const filteredWithAvatars = new Array<UserWithStatus>();
|
||||
|
||||
for (let userWithStatus of filteredWithAvatars) {
|
||||
if (!userWithStatus.user.avatar_url) continue;
|
||||
const avatarResponse = await getSignedUrl({
|
||||
bucket: 'avatars',
|
||||
url: userWithStatus.user.avatar_url,
|
||||
transform: { width: 128, height: 128 },
|
||||
});
|
||||
if (!avatarResponse.success) continue;
|
||||
else userWithStatus = { ...userWithStatus, avatar_url: avatarResponse.data };
|
||||
for (const userWithStatus of filtered) {
|
||||
|
||||
if (userWithStatus.user.avatar_url) {
|
||||
const avatarResponse = await getSignedUrl({
|
||||
bucket: 'avatars',
|
||||
url: userWithStatus.user.avatar_url,
|
||||
});
|
||||
if (avatarResponse.success) {
|
||||
userWithStatus.user.avatar_url = avatarResponse.data;
|
||||
} else userWithStatus.user.avatar_url = null;
|
||||
} else userWithStatus.user.avatar_url = null;
|
||||
|
||||
if (userWithStatus.updated_by?.avatar_url) {
|
||||
const updatedByAvatarResponse = await getSignedUrl({
|
||||
bucket: 'avatars',
|
||||
url: userWithStatus.updated_by.avatar_url ?? '',
|
||||
});
|
||||
if (updatedByAvatarResponse.success) {
|
||||
userWithStatus.updated_by.avatar_url = updatedByAvatarResponse.data;
|
||||
} else userWithStatus.updated_by.avatar_url = null;
|
||||
} else {
|
||||
if (userWithStatus.updated_by) userWithStatus.updated_by.avatar_url = null;
|
||||
}
|
||||
filteredWithAvatars.push(userWithStatus);
|
||||
}
|
||||
console.log('filteredWithAvatars', filteredWithAvatars);
|
||||
|
||||
return { success: true, data: filteredWithAvatars };
|
||||
} catch (error) {
|
||||
return { success: false, error: `Error: ${error as Error}` };
|
||||
@ -109,17 +121,14 @@ export const updateStatuses = async (
|
||||
): Promise<Result<void>> => {
|
||||
try {
|
||||
const supabase = createClient();
|
||||
const userResponse = await getUser();
|
||||
if (!userResponse.success) throw new Error('Not authenticated!');
|
||||
const profileResponse = await getProfile();
|
||||
if (!profileResponse.success) throw new Error(profileResponse.error);
|
||||
const user = userResponse.data;
|
||||
if (!profileResponse.success) throw new Error('Not authenticated!');
|
||||
const userProfile = profileResponse.data;
|
||||
|
||||
const inserts = userIds.map((usersId) => ({
|
||||
user_id: usersId,
|
||||
const inserts = userIds.map((userId) => ({
|
||||
user_id: userId,
|
||||
status,
|
||||
updated_by_id: user.id,
|
||||
updated_by_id: userProfile.id,
|
||||
}));
|
||||
|
||||
const { data: insertedStatuses, error: insertedStatusesError } =
|
||||
@ -129,13 +138,9 @@ export const updateStatuses = async (
|
||||
if (insertedStatuses) {
|
||||
const broadcastArray = new Array<UserWithStatus>(insertedStatuses.length);
|
||||
for (const insertedStatus of insertedStatuses) {
|
||||
const { data: profile, error: profileError } = await supabase
|
||||
.from('profiles')
|
||||
.select('*')
|
||||
.eq('id', insertedStatus.user_id)
|
||||
.single();
|
||||
if (profileError) throw profileError as Error;
|
||||
|
||||
const profileResponse = await getProfile(insertedStatus.user_id)
|
||||
if (!profileResponse.success) throw new Error(profileResponse.error);
|
||||
const profile = profileResponse.data;
|
||||
if (profile) {
|
||||
broadcastArray.push({
|
||||
user: profile,
|
||||
@ -161,21 +166,17 @@ export const updateUserStatus = async (
|
||||
): Promise<Result<void>> => {
|
||||
try {
|
||||
const supabase = createClient();
|
||||
const userResponse = await getUser();
|
||||
if (!userResponse.success)
|
||||
throw new Error(`Not authenticated! ${userResponse.error}`);
|
||||
const profileResponse = await getProfile();
|
||||
if (!profileResponse.success)
|
||||
throw new Error(`Could not get profile! ${profileResponse.error}`);
|
||||
const user = userResponse.data;
|
||||
throw new Error(`Not authenticated! ${profileResponse.error}`);
|
||||
const userProfile = profileResponse.data;
|
||||
|
||||
const { data: insertedStatus, error: insertedStatusError } = await supabase
|
||||
.from('statuses')
|
||||
.insert({
|
||||
user_id: user.id,
|
||||
user_id: userProfile.id,
|
||||
status,
|
||||
updated_by_id: user.id,
|
||||
updated_by_id: userProfile.id,
|
||||
})
|
||||
.select()
|
||||
.single();
|
||||
@ -234,14 +235,6 @@ export const getUserHistory = async (
|
||||
};
|
||||
if (statusesError) throw statusesError as Error;
|
||||
|
||||
const { data: profile, error: profileError } = (await supabase
|
||||
.from('profiles')
|
||||
.select('*')
|
||||
.eq('id', userId)
|
||||
.single()) as { data: Profile; error: unknown };
|
||||
if (profileError) throw profileError as Error;
|
||||
if (!profile) throw new Error('User profile not found!');
|
||||
|
||||
const totalCount = count ?? 0;
|
||||
const totalPages = Math.ceil(totalCount / perPage);
|
||||
|
||||
|
Reference in New Issue
Block a user