mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 02:15:21 +00:00
Merge pull request #67 from SyncrowIOT/remove-extension-from-profile-picture
Refactor user service to use removeBase64Prefix utility function
This commit is contained in:
3
libs/common/src/helper/removeBase64Prefix.ts
Normal file
3
libs/common/src/helper/removeBase64Prefix.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export function removeBase64Prefix(dataUrl: string): string {
|
||||
return dataUrl.replace(/^data:image\/[a-z]+;base64,/, '');
|
||||
}
|
@ -13,6 +13,7 @@ import {
|
||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||
import { RegionRepository } from '@app/common/modules/region/repositories';
|
||||
import { TimeZoneRepository } from '@app/common/modules/timezone/repositories';
|
||||
import { removeBase64Prefix } from '@app/common/helper/removeBase64Prefix';
|
||||
|
||||
@Injectable()
|
||||
export class UserService {
|
||||
@ -33,12 +34,15 @@ export class UserService {
|
||||
throw new BadRequestException('Invalid room UUID');
|
||||
}
|
||||
|
||||
// Use the utility function to remove the base64 prefix
|
||||
const cleanedProfilePicture = removeBase64Prefix(user.profilePicture);
|
||||
|
||||
return {
|
||||
uuid: user.uuid,
|
||||
email: user.email,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName,
|
||||
profilePicture: user.profilePicture,
|
||||
profilePicture: cleanedProfilePicture,
|
||||
region: user.region,
|
||||
timeZone: user.timezone,
|
||||
};
|
||||
@ -61,17 +65,19 @@ export class UserService {
|
||||
{ ...updateProfilePictureDataDto },
|
||||
);
|
||||
const updatedUser = await this.getUserDetailsByUserUuid(userUuid);
|
||||
// Use the utility function to remove the base64 prefix
|
||||
const cleanedProfilePicture = removeBase64Prefix(
|
||||
updatedUser.profilePicture,
|
||||
);
|
||||
return {
|
||||
uuid: updatedUser.uuid,
|
||||
firstName: updatedUser.firstName,
|
||||
lastName: updatedUser.lastName,
|
||||
profilePicture: updatedUser.profilePicture,
|
||||
profilePicture: cleanedProfilePicture,
|
||||
region: updatedUser.region,
|
||||
timeZoneUuid: updatedUser.timeZone,
|
||||
};
|
||||
} catch (err) {
|
||||
console.log('err', err);
|
||||
|
||||
if (err instanceof BadRequestException) {
|
||||
throw err; // Re-throw BadRequestException
|
||||
} else {
|
||||
@ -115,12 +121,15 @@ export class UserService {
|
||||
if (!updatedUser.region) {
|
||||
throw new BadRequestException('Region update failed');
|
||||
}
|
||||
|
||||
// Use the utility function to remove the base64 prefix
|
||||
const cleanedProfilePicture = removeBase64Prefix(
|
||||
updatedUser.profilePicture,
|
||||
);
|
||||
return {
|
||||
uuid: updatedUser.uuid,
|
||||
firstName: updatedUser.firstName,
|
||||
lastName: updatedUser.lastName,
|
||||
profilePicture: updatedUser.profilePicture,
|
||||
profilePicture: cleanedProfilePicture,
|
||||
region: updatedUser.region,
|
||||
timeZoneUuid: updatedUser.timeZone,
|
||||
};
|
||||
@ -167,12 +176,15 @@ export class UserService {
|
||||
if (!updatedUser.timeZone) {
|
||||
throw new BadRequestException('Timezone update failed');
|
||||
}
|
||||
|
||||
// Use the utility function to remove the base64 prefix
|
||||
const cleanedProfilePicture = removeBase64Prefix(
|
||||
updatedUser.profilePicture,
|
||||
);
|
||||
return {
|
||||
uuid: updatedUser.uuid,
|
||||
firstName: updatedUser.firstName,
|
||||
lastName: updatedUser.lastName,
|
||||
profilePicture: updatedUser.profilePicture,
|
||||
profilePicture: cleanedProfilePicture,
|
||||
region: updatedUser.region,
|
||||
timeZoneUuid: updatedUser.timeZone,
|
||||
};
|
||||
@ -206,12 +218,15 @@ export class UserService {
|
||||
if (!updatedUser.firstName || !updatedUser.lastName) {
|
||||
throw new BadRequestException('First Name and Last Name update failed');
|
||||
}
|
||||
|
||||
// Use the utility function to remove the base64 prefix
|
||||
const cleanedProfilePicture = removeBase64Prefix(
|
||||
updatedUser.profilePicture,
|
||||
);
|
||||
return {
|
||||
uuid: updatedUser.uuid,
|
||||
firstName: updatedUser.firstName,
|
||||
lastName: updatedUser.lastName,
|
||||
profilePicture: updatedUser.profilePicture,
|
||||
profilePicture: cleanedProfilePicture,
|
||||
region: updatedUser.region,
|
||||
timeZoneUuid: updatedUser.timeZone,
|
||||
};
|
||||
|
Reference in New Issue
Block a user