UNPKG

@methodus/server

Version:
98 lines 4.64 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("../../index"); const endPoint = 'http://localhost:8090'; //https://jsonplaceholder.typicode.com'; class Deserializable { static deserialize(data) { let parsedObject = JSON.parse(data); const returnObject = new Deserializable(); returnObject.name = parsedObject.name; returnObject.date = new Date(parsedObject.date); returnObject.bool = parsedObject.bool; return returnObject; } } exports.Deserializable = Deserializable; let TestClass = class TestClass { constructor() { } action1(id, name) { return __awaiter(this, void 0, void 0, function* () { console.log(`action1: ${id} ${name}`); return new index_1.MethodResult({ id: id, name: name, add: id * id }); }); } // @Method(Verbs.Get, '/posts/error') // public error() { // console.log('running error localy'); // throw new MethodError('error returned', 500); // } action2(item) { return __awaiter(this, void 0, void 0, function* () { return new index_1.MethodResult(item); }); } action5(someObject, minDate, maxDate) { return __awaiter(this, void 0, void 0, function* () { console.log(someObject, minDate, maxDate); return new index_1.MethodResult(minDate); }); } action3() { return __awaiter(this, void 0, void 0, function* () { console.log('action3'); }); } }; __decorate([ index_1.Method("GET" /* Get */, '/api/testclass/:id/:name'), __param(0, index_1.Param('id')), __param(1, index_1.Param('name')), __metadata("design:type", Function), __metadata("design:paramtypes", [Number, String]), __metadata("design:returntype", Promise) ], TestClass.prototype, "action1", null); __decorate([ index_1.Method("POST" /* Post */, '/api/testclass/posts'), __param(0, index_1.Body()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], TestClass.prototype, "action2", null); __decorate([ index_1.Method("GET" /* Get */, '/api/testclass/action5'), __param(0, index_1.Query('someObject', Deserializable)), __param(1, index_1.Query('minDate', Date)), __param(2, index_1.Query('maxDate', Date)), __metadata("design:type", Function), __metadata("design:paramtypes", [Deserializable, Date, Date]), __metadata("design:returntype", Promise) ], TestClass.prototype, "action5", null); __decorate([ index_1.Method("DELETE" /* Delete */, '/api/testclass/action3'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], TestClass.prototype, "action3", null); TestClass = __decorate([ index_1.MethodConfig('TestClass'), __metadata("design:paramtypes", []) ], TestClass); exports.TestClass = TestClass; //# sourceMappingURL=TestClass.js.map