mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 02:36:19 +00:00
finshed homes endpoint
This commit is contained in:
@ -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,
|
||||
|
Reference in New Issue
Block a user