mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:54:54 +00:00
finshed homes endpoint
This commit is contained in:
@ -25,15 +25,27 @@ export class HomeService {
|
|||||||
async getHomesByUserId(userUuid: string) {
|
async getHomesByUserId(userUuid: string) {
|
||||||
const homesData = await this.findHomes(userUuid);
|
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) {
|
async findHomes(userUuid: string) {
|
||||||
|
try {
|
||||||
return await this.homeRepository.find({
|
return await this.homeRepository.find({
|
||||||
where: {
|
where: {
|
||||||
userUuid: userUuid,
|
userUuid: userUuid,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Error get homes',
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
async addHome(addHomeDto: AddHomeDto) {
|
async addHome(addHomeDto: AddHomeDto) {
|
||||||
try {
|
try {
|
||||||
@ -50,7 +62,10 @@ export class HomeService {
|
|||||||
homeName: addHomeDto.homeName,
|
homeName: addHomeDto.homeName,
|
||||||
} as HomeEntity;
|
} as HomeEntity;
|
||||||
const savedHome = await this.homeRepository.save(homeEntity);
|
const savedHome = await this.homeRepository.save(homeEntity);
|
||||||
return savedHome;
|
return {
|
||||||
|
homeId: savedHome.homeId,
|
||||||
|
homeName: savedHome.homeName,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
success: data.success,
|
success: data.success,
|
||||||
|
|||||||
Reference in New Issue
Block a user