Skip to content

Commit

Permalink
feat: 캔 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
publdaze committed Jul 20, 2023
1 parent 97a7b16 commit 1f5fc54
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/buildings/buildings.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,19 @@ export class BuildingsRepository {
console.error(err);
}
}

async getCans(buildingNumber: number) {
try {
const buildingDoc = await this.buildingModel
.find({
buildingNumber: buildingNumber,
})
.exec();

return buildingDoc;
} catch (err) {
console.log('error... get Cans');
console.error(err);
}
}
}
7 changes: 6 additions & 1 deletion src/buildings/floors/cans/cans.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Param, Post } from '@nestjs/common';
import { Controller, Get, Param, Post } from '@nestjs/common';
import { CansService } from './cans.service';

@Controller()
Expand All @@ -12,4 +12,9 @@ export class CansController {
) {
return this.cansService.createCan({ buildingNumber, floorNumber });
}

@Get('/buildings/:buildingNumber')
getCans(@Param('buildingNumber') buildingNumber: number) {
return this.cansService.getCans(buildingNumber);
}
}
23 changes: 23 additions & 0 deletions src/buildings/floors/cans/cans.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,28 @@ export class CansService {
console.log(res);
});
}

getCans(buildingNumber: number) {
console.log(`get cans! on ${buildingNumber} building`);
const buildings = this.buildingRepository.getCans(buildingNumber);
return buildings
.then((res) => {
return res.map(({ buildingNumber, buildingName, floors }) => ({
buildingNumber,
buildingName,
floors: floors.map(({ floorNumber, trashCans }) => ({
floorNumber,
trashCans: trashCans.map(({ _id, status }) => {
return {
canId: _id,
status,
};
}),
})),
}));
})
.catch((err) => {
console.log(err);
});
}
}

0 comments on commit 1f5fc54

Please sign in to comment.