finshed homes endpoint

This commit is contained in:
faris Aljohari
2024-03-11 09:26:22 +03:00
parent 63411cada4
commit 35feab71bb

View File

@ -25,15 +25,27 @@ export class HomeService {
async getHomesByUserId(userUuid: string) {
const homesData = await this.findHomes(userUuid);
return homesData;
const homesMapper = homesData.map((home) => ({
homeId: home.homeId,
homeName: home.homeName,
}));
return homesMapper;
}
async findHomes(userUuid: string) {
return await this.homeRepository.find({
where: {
userUuid: userUuid,
},
});
try {
return await this.homeRepository.find({
where: {
userUuid: userUuid,
},
});
} catch (error) {
throw new HttpException(
'Error get homes',
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
async addHome(addHomeDto: AddHomeDto) {
try {
@ -50,7 +62,10 @@ export class HomeService {
homeName: addHomeDto.homeName,
} as HomeEntity;
const savedHome = await this.homeRepository.save(homeEntity);
return savedHome;
return {
homeId: savedHome.homeId,
homeName: savedHome.homeName,
};
}
return {
success: data.success,