Skip to content

Commit

Permalink
fix(main): fixes toString() of undefined bug for numeric check
Browse files Browse the repository at this point in the history
  • Loading branch information
wzr1337 committed Jan 11, 2017
1 parent 7968d88 commit bb17c6c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
15 changes: 11 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fs.readdir(path.join(__dirname, "plugins"), (err:NodeJS.ErrnoException, files: s
let basePath = "/" + service.name.toLowerCase() + "/" + resource.name.toLowerCase() + "/";
console.log("Registering endpoint:", service.name);
server.app.get(basePath, resourceGET(service, resource)); //READ
server.app.post(basePath, resourcePOST(service, resource)); //CREATE
server.app.post(basePath, resourcePOST(service, resource)); //CREATE
server.app.post(basePath + ':id', elementPOST(service, resource)); //READ
server.app.get(basePath + ':id', elementGET(service, resource)); //UPDATE
server.app.delete(basePath + ':id', elementDELETE(service, resource)); //DELETE
Expand All @@ -47,8 +47,9 @@ fs.readdir(path.join(__dirname, "plugins"), (err:NodeJS.ErrnoException, files: s

const elementGET = (service:Service, resource:Resource) => {
let elementPath = pathof(service, resource) + "/:id"
console.log("GET", elementPath, "registered");
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
console.log("Query: GET", req.path);

if(!resource.getElement) {
res.status(501).send("Not Implemented");
return;
Expand All @@ -75,14 +76,14 @@ const resourceGET = (service:Service, resource:Resource) => {
let resourcePath = pathof(service, resource);
console.log("GET", resourcePath, "registered");
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
console.log("Query: GET", req.path);
if(!resource.getResource) {
res.status(501).send("Not Implemented");
return;
}
console.log(req.params);
// get all available renderes and map their representation to JSON compatible values
function parseNumberOrId(n:string|number):string|number {
return (!isNaN(parseFloat(<string>n)) && isFinite(<number>n)) ? parseFloat(<string>n) : n.toString();
return (typeof n === "undefined") ? undefined : ((!isNaN(parseFloat(<string>n)) && isFinite(<number>n)) ? parseFloat(<string>n) : n.toString());
}

let elements = resource.getResource(parseNumberOrId(req.query.$offset), parseNumberOrId(req.query.$limit));
Expand All @@ -108,6 +109,7 @@ const resourcePOST = (service:Service, resource:Resource) => {
let resourcePath = pathof(service, resource);
console.log("POST", resourcePath, "registered");
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
console.log("Query: POST", req.path);
if(!resource.createElement) {
res.status(501).send("Not Implemented");
return;
Expand All @@ -119,6 +121,7 @@ const elementDELETE = (service:Service, resource:Resource) => {
let elementPath = pathof(service, resource) + "/:id"
console.log("DELETE", elementPath, "registered");
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
console.log("Query: DELETE", req.path);

if(!resource.deleteElement) {
res.status(501).send("Not Implemented");
Expand All @@ -143,7 +146,11 @@ const elementDELETE = (service:Service, resource:Resource) => {
};

const elementPOST = (service:Service, resource:Resource) => {
let elementPath = pathof(service, resource) + "/:id"
console.log("POST", elementPath, "registered");
return (req: express.Request, res: express.Response, next: express.NextFunction) => {
console.log("Query: POST", req.path);

// find the element requested by the client
let element = resource.getElement(req.params.id);
if (element){
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/media/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { BehaviorSubject } from '@reactivex/rxjs';
import { Service, Resource } from "../viwiPlugin";
import * as express from 'express';

class Media implements Service {
private _resources:Renderer[]=[];
Expand Down Expand Up @@ -51,9 +50,7 @@ class Renderer implements Resource {
// retriev all element
let resp:BehaviorSubject<{}>[];

console.log(typeof offset, offset.toString(),typeof limit, limit.toString());
if((typeof offset === "number" && typeof limit === "number") || (typeof limit === "number" && !offset) || (typeof offset === "number" && !limit) || (!offset && !limit)) {
console.log(offset.toString(), limit.toString());
resp = this._renderers.slice(<number>offset, <number>limit);
}

Expand All @@ -63,7 +60,6 @@ class Renderer implements Resource {

private _interval:NodeJS.Timer; //@TODO has to become per-renderer
updateElement?(elementId:string, difference:any):Boolean {
console.log("whaaaat")
let element = this.getElement(elementId);
let renderer:any = element.getValue();
if (difference.hasOwnProperty("state")) {
Expand Down
1 change: 0 additions & 1 deletion typings/index.d.ts

This file was deleted.

0 comments on commit bb17c6c

Please sign in to comment.