|
| 1 | +"use strict"; |
| 2 | +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { |
| 3 | + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; |
| 4 | + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); |
| 5 | + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; |
| 6 | + return c > 3 && r && Object.defineProperty(target, key, r), r; |
| 7 | +}; |
| 8 | +var __metadata = (this && this.__metadata) || function (k, v) { |
| 9 | + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); |
| 10 | +}; |
| 11 | +var __param = (this && this.__param) || function (paramIndex, decorator) { |
| 12 | + return function (target, key) { decorator(target, key, paramIndex); } |
| 13 | +}; |
| 14 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 15 | +exports.PeopleController = void 0; |
| 16 | +const routing_controllers_1 = require("routing-controllers"); |
| 17 | +let PeopleController = class PeopleController { |
| 18 | + constructor() { |
| 19 | + this.PEOPLES_DB = []; |
| 20 | + } |
| 21 | + getAllPeople() { |
| 22 | + console.log("GET ALL PEOPLES API called"); |
| 23 | + return this.PEOPLES_DB; |
| 24 | + } |
| 25 | + getPeopleById(id) { |
| 26 | + console.log("GET PEOPLE ID API called"); |
| 27 | + let peoples = this.PEOPLES_DB.filter((data) => data.id && data.id === id); |
| 28 | + return peoples; |
| 29 | + } |
| 30 | + savePeople(myPeople) { |
| 31 | + let id = Math.random(); |
| 32 | + console.log(`save PEOPLE API called :: ${id}`); |
| 33 | + myPeople.id = id; |
| 34 | + this.PEOPLES_DB.push(myPeople); |
| 35 | + return myPeople; |
| 36 | + } |
| 37 | + deletePeople(id) { |
| 38 | + let peopleId = this.PEOPLES_DB.findIndex((data) => data.id === id); |
| 39 | + console.log(`DELETE PEOPLE API called :: ${id}`); |
| 40 | + if (peopleId != null) { |
| 41 | + this.PEOPLES_DB.splice(peopleId, 1); |
| 42 | + } |
| 43 | + } |
| 44 | + updateMyPeople(id, myPeople) { |
| 45 | + console.log(`update PEOPLE API called :: ${id}`); |
| 46 | + this.PEOPLES_DB.map((data) => data.id && data.id === id ? Object.assign(Object.assign({}, data), { myPeople }) : data); |
| 47 | + console.log(`people updated successfully`); |
| 48 | + return this.PEOPLES_DB.filter((people) => people.id === id); |
| 49 | + } |
| 50 | +}; |
| 51 | +exports.PeopleController = PeopleController; |
| 52 | +__decorate([ |
| 53 | + (0, routing_controllers_1.Get)("/"), |
| 54 | + __metadata("design:type", Function), |
| 55 | + __metadata("design:paramtypes", []), |
| 56 | + __metadata("design:returntype", Array) |
| 57 | +], PeopleController.prototype, "getAllPeople", null); |
| 58 | +__decorate([ |
| 59 | + (0, routing_controllers_1.Get)("/:id"), |
| 60 | + __param(0, (0, routing_controllers_1.Param)("id")), |
| 61 | + __metadata("design:type", Function), |
| 62 | + __metadata("design:paramtypes", [Number]), |
| 63 | + __metadata("design:returntype", Array) |
| 64 | +], PeopleController.prototype, "getPeopleById", null); |
| 65 | +__decorate([ |
| 66 | + (0, routing_controllers_1.Get)("/"), |
| 67 | + __param(0, (0, routing_controllers_1.Body)()), |
| 68 | + __metadata("design:type", Function), |
| 69 | + __metadata("design:paramtypes", [People]), |
| 70 | + __metadata("design:returntype", People) |
| 71 | +], PeopleController.prototype, "savePeople", null); |
| 72 | +__decorate([ |
| 73 | + (0, routing_controllers_1.Delete)("/:id"), |
| 74 | + __param(0, (0, routing_controllers_1.Param)("id")), |
| 75 | + __metadata("design:type", Function), |
| 76 | + __metadata("design:paramtypes", [Number]), |
| 77 | + __metadata("design:returntype", void 0) |
| 78 | +], PeopleController.prototype, "deletePeople", null); |
| 79 | +__decorate([ |
| 80 | + (0, routing_controllers_1.Put)("/:id"), |
| 81 | + __param(0, (0, routing_controllers_1.Param)("id")), |
| 82 | + __param(1, (0, routing_controllers_1.Body)()), |
| 83 | + __metadata("design:type", Function), |
| 84 | + __metadata("design:paramtypes", [Number, People]), |
| 85 | + __metadata("design:returntype", void 0) |
| 86 | +], PeopleController.prototype, "updateMyPeople", null); |
| 87 | +exports.PeopleController = PeopleController = __decorate([ |
| 88 | + (0, routing_controllers_1.JsonController)("/api/people") |
| 89 | +], PeopleController); |
| 90 | +class People { |
| 91 | +} |
0 commit comments