mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +00:00
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 { UserRepository } from '@app/common/modules/user/repositories';
|
||||||
import { RegionRepository } from '@app/common/modules/region/repositories';
|
import { RegionRepository } from '@app/common/modules/region/repositories';
|
||||||
import { TimeZoneRepository } from '@app/common/modules/timezone/repositories';
|
import { TimeZoneRepository } from '@app/common/modules/timezone/repositories';
|
||||||
|
import { removeBase64Prefix } from '@app/common/helper/removeBase64Prefix';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserService {
|
export class UserService {
|
||||||
@ -33,12 +34,15 @@ export class UserService {
|
|||||||
throw new BadRequestException('Invalid room UUID');
|
throw new BadRequestException('Invalid room UUID');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use the utility function to remove the base64 prefix
|
||||||
|
const cleanedProfilePicture = removeBase64Prefix(user.profilePicture);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
uuid: user.uuid,
|
uuid: user.uuid,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
firstName: user.firstName,
|
firstName: user.firstName,
|
||||||
lastName: user.lastName,
|
lastName: user.lastName,
|
||||||
profilePicture: user.profilePicture,
|
profilePicture: cleanedProfilePicture,
|
||||||
region: user.region,
|
region: user.region,
|
||||||
timeZone: user.timezone,
|
timeZone: user.timezone,
|
||||||
};
|
};
|
||||||
@ -61,17 +65,19 @@ export class UserService {
|
|||||||
{ ...updateProfilePictureDataDto },
|
{ ...updateProfilePictureDataDto },
|
||||||
);
|
);
|
||||||
const updatedUser = await this.getUserDetailsByUserUuid(userUuid);
|
const updatedUser = await this.getUserDetailsByUserUuid(userUuid);
|
||||||
|
// Use the utility function to remove the base64 prefix
|
||||||
|
const cleanedProfilePicture = removeBase64Prefix(
|
||||||
|
updatedUser.profilePicture,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
uuid: updatedUser.uuid,
|
uuid: updatedUser.uuid,
|
||||||
firstName: updatedUser.firstName,
|
firstName: updatedUser.firstName,
|
||||||
lastName: updatedUser.lastName,
|
lastName: updatedUser.lastName,
|
||||||
profilePicture: updatedUser.profilePicture,
|
profilePicture: cleanedProfilePicture,
|
||||||
region: updatedUser.region,
|
region: updatedUser.region,
|
||||||
timeZoneUuid: updatedUser.timeZone,
|
timeZoneUuid: updatedUser.timeZone,
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('err', err);
|
|
||||||
|
|
||||||
if (err instanceof BadRequestException) {
|
if (err instanceof BadRequestException) {
|
||||||
throw err; // Re-throw BadRequestException
|
throw err; // Re-throw BadRequestException
|
||||||
} else {
|
} else {
|
||||||
@ -115,12 +121,15 @@ export class UserService {
|
|||||||
if (!updatedUser.region) {
|
if (!updatedUser.region) {
|
||||||
throw new BadRequestException('Region update failed');
|
throw new BadRequestException('Region update failed');
|
||||||
}
|
}
|
||||||
|
// Use the utility function to remove the base64 prefix
|
||||||
|
const cleanedProfilePicture = removeBase64Prefix(
|
||||||
|
updatedUser.profilePicture,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
uuid: updatedUser.uuid,
|
uuid: updatedUser.uuid,
|
||||||
firstName: updatedUser.firstName,
|
firstName: updatedUser.firstName,
|
||||||
lastName: updatedUser.lastName,
|
lastName: updatedUser.lastName,
|
||||||
profilePicture: updatedUser.profilePicture,
|
profilePicture: cleanedProfilePicture,
|
||||||
region: updatedUser.region,
|
region: updatedUser.region,
|
||||||
timeZoneUuid: updatedUser.timeZone,
|
timeZoneUuid: updatedUser.timeZone,
|
||||||
};
|
};
|
||||||
@ -167,12 +176,15 @@ export class UserService {
|
|||||||
if (!updatedUser.timeZone) {
|
if (!updatedUser.timeZone) {
|
||||||
throw new BadRequestException('Timezone update failed');
|
throw new BadRequestException('Timezone update failed');
|
||||||
}
|
}
|
||||||
|
// Use the utility function to remove the base64 prefix
|
||||||
|
const cleanedProfilePicture = removeBase64Prefix(
|
||||||
|
updatedUser.profilePicture,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
uuid: updatedUser.uuid,
|
uuid: updatedUser.uuid,
|
||||||
firstName: updatedUser.firstName,
|
firstName: updatedUser.firstName,
|
||||||
lastName: updatedUser.lastName,
|
lastName: updatedUser.lastName,
|
||||||
profilePicture: updatedUser.profilePicture,
|
profilePicture: cleanedProfilePicture,
|
||||||
region: updatedUser.region,
|
region: updatedUser.region,
|
||||||
timeZoneUuid: updatedUser.timeZone,
|
timeZoneUuid: updatedUser.timeZone,
|
||||||
};
|
};
|
||||||
@ -206,12 +218,15 @@ export class UserService {
|
|||||||
if (!updatedUser.firstName || !updatedUser.lastName) {
|
if (!updatedUser.firstName || !updatedUser.lastName) {
|
||||||
throw new BadRequestException('First Name and Last Name update failed');
|
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 {
|
return {
|
||||||
uuid: updatedUser.uuid,
|
uuid: updatedUser.uuid,
|
||||||
firstName: updatedUser.firstName,
|
firstName: updatedUser.firstName,
|
||||||
lastName: updatedUser.lastName,
|
lastName: updatedUser.lastName,
|
||||||
profilePicture: updatedUser.profilePicture,
|
profilePicture: cleanedProfilePicture,
|
||||||
region: updatedUser.region,
|
region: updatedUser.region,
|
||||||
timeZoneUuid: updatedUser.timeZone,
|
timeZoneUuid: updatedUser.timeZone,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user