labs-angular-backend
Advanced tools
Comparing version 1.0.2 to 1.0.3
import { UsersService } from "../../services/UsersService"; | ||
import { IUser } from "../../models/User"; | ||
import { IUser, PartialUser } from "../../models/User"; | ||
export declare class UserCtrl { | ||
private usersService; | ||
constructor(usersService: UsersService); | ||
authenticate(email: string, password: string): IUser; | ||
getByEmail(email: string): IUser; | ||
@@ -11,3 +12,3 @@ updateStatus(email: string, status: string): IUser; | ||
remove(): void; | ||
getList(): IUser[]; | ||
getList(): PartialUser[]; | ||
} |
@@ -16,3 +16,5 @@ "use strict"; | ||
var ts_express_decorators_1 = require("ts-express-decorators"); | ||
var ts_log_debug_1 = require("ts-log-debug"); | ||
var UsersService_1 = require("../../services/UsersService"); | ||
var ts_httpexceptions_1 = require("ts-httpexceptions"); | ||
var UserCtrl = (function () { | ||
@@ -22,2 +24,14 @@ function UserCtrl(usersService) { | ||
} | ||
UserCtrl.prototype.authenticate = function (email, password) { | ||
ts_log_debug_1.$log.debug("authenticate user with email", email, " & password ", password); | ||
var user = this.usersService.findByEmail(email); | ||
ts_log_debug_1.$log.debug("find user by email", user); | ||
if (null == user) { | ||
throw new ts_httpexceptions_1.NotFound("authentication failed, user not found"); | ||
} | ||
if (user.password !== password) { | ||
throw new ts_httpexceptions_1.Unauthorized("authentication failed, wrong password"); | ||
} | ||
return user; | ||
}; | ||
UserCtrl.prototype.getByEmail = function (email) { | ||
@@ -27,4 +41,6 @@ return this.usersService.findByEmail(email); | ||
UserCtrl.prototype.updateStatus = function (email, status) { | ||
ts_log_debug_1.$log.debug("patch from email", email, "with status", status); | ||
var user = this.usersService.findByEmail(email); | ||
user.status = status; | ||
ts_log_debug_1.$log.debug("patch user", user); | ||
return this.usersService.patch(user); | ||
@@ -39,2 +55,3 @@ }; | ||
UserCtrl.prototype.create = function (user) { | ||
ts_log_debug_1.$log.debug("rest create user", user); | ||
return this.usersService.create(user); | ||
@@ -45,3 +62,3 @@ }; | ||
UserCtrl.prototype.getList = function () { | ||
return this.usersService.query(); | ||
return this.usersService.queryPartial(); | ||
}; | ||
@@ -51,2 +68,10 @@ return UserCtrl; | ||
__decorate([ | ||
ts_express_decorators_1.Post("/authenticate"), | ||
__param(0, ts_express_decorators_1.Required()), __param(0, ts_express_decorators_1.BodyParams("email")), | ||
__param(1, ts_express_decorators_1.Required()), __param(1, ts_express_decorators_1.BodyParams("password")), | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", [String, String]), | ||
__metadata("design:returntype", void 0) | ||
], UserCtrl.prototype, "authenticate", null); | ||
__decorate([ | ||
ts_express_decorators_1.Get("/:email"), | ||
@@ -53,0 +78,0 @@ __param(0, ts_express_decorators_1.PathParams("email")), |
@@ -28,2 +28,3 @@ "use strict"; | ||
var rootDir = Path.resolve(__dirname); | ||
console.log(process.env.NODE_ENV); | ||
var Server = (function (_super) { | ||
@@ -42,4 +43,6 @@ __extends(Server, _super); | ||
var morgan = require('morgan'), cookieParser = require('cookie-parser'), bodyParser = require('body-parser'), compress = require('compression'), methodOverride = require('method-override'); | ||
if (this.settings.$get().env !== "test") { | ||
this.use(morgan('dev')); | ||
} | ||
this | ||
.use(morgan('dev')) | ||
.use(ts_express_decorators_1.GlobalAcceptMimesMiddleware) | ||
@@ -76,2 +79,3 @@ .use(cookieParser()) | ||
rootDir: rootDir, | ||
env: process.env.NODE_ENV, | ||
mount: { | ||
@@ -78,0 +82,0 @@ '/api': rootDir + "/controllers/**/**.js" |
@@ -0,1 +1,2 @@ | ||
export declare type PartialUser = Partial<IUser>; | ||
export interface IUser { | ||
@@ -6,4 +7,4 @@ _id: string; | ||
firstName: string; | ||
password: string; | ||
status: string; | ||
password?: string; | ||
status?: string; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { IUser } from "../models/User"; | ||
import { IUser, PartialUser } from "../models/User"; | ||
export declare class UsersService { | ||
@@ -23,2 +23,3 @@ users: any[]; | ||
query(): IUser[]; | ||
queryPartial(): PartialUser[]; | ||
/** | ||
@@ -25,0 +26,0 @@ * |
@@ -14,2 +14,3 @@ "use strict"; | ||
var ts_express_decorators_1 = require("ts-express-decorators"); | ||
var ts_log_debug_1 = require("ts-log-debug"); | ||
var UsersService = (function () { | ||
@@ -28,4 +29,8 @@ function UsersService() { | ||
UsersService.prototype.findByEmail = function (email) { | ||
ts_log_debug_1.$log.debug("find by email", email); | ||
var users = this.query(); | ||
return users.find(function (value) { return value.email === email; }); | ||
ts_log_debug_1.$log.debug("users size", users.length); | ||
var user = users.find(function (user) { return user.email === email; }); | ||
ts_log_debug_1.$log.debug("user found", user); | ||
return user; | ||
}; | ||
@@ -43,3 +48,6 @@ UsersService.prototype.findByCredential = function (email, password) { | ||
user._id = require("node-uuid").v4(); | ||
ts_log_debug_1.$log.debug("create user", user); | ||
ts_log_debug_1.$log.debug("users size before insert", this.users.length); | ||
this.users.push(user); | ||
ts_log_debug_1.$log.debug("users size", this.users.length); | ||
return user; | ||
@@ -54,2 +62,15 @@ }; | ||
}; | ||
UsersService.prototype.queryPartial = function () { | ||
var partialUsers = []; | ||
this.users.forEach(function (user) { | ||
partialUsers.push({ | ||
_id: user._id, | ||
email: user.email, | ||
firstName: user.firstName, | ||
lastName: user.lastName, | ||
"status": "offline" | ||
}); | ||
}); | ||
return partialUsers; | ||
}; | ||
/** | ||
@@ -62,3 +83,3 @@ * | ||
var users = this.query(); | ||
var index = this.users.find(function (o) { return user._id === o._id; }); | ||
var index = this.users.findIndex(function (o) { return user._id === o._id; }); | ||
users[index] = user; | ||
@@ -74,3 +95,5 @@ return user; | ||
var users = this.query(); | ||
var index = this.users.find(function (o) { return user._id === o._id; }); | ||
ts_log_debug_1.$log.debug("users size", users.length); | ||
var index = this.users.findIndex(function (o) { return user._id === o._id; }); | ||
ts_log_debug_1.$log.debug("users index", index); | ||
users[index] = Object.assign(users[index], user); | ||
@@ -77,0 +100,0 @@ return users[index]; |
{ | ||
"name": "labs-angular-backend", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "", | ||
@@ -42,11 +42,10 @@ "main": "lib/index.js", | ||
"ts-express-decorators": "^1.4.6", | ||
"ts-httpexceptions": "^2.1.3", | ||
"ts-json-properties": "^1.1.4" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^3.4.32", | ||
"@types/express": "^4.0.35", | ||
"@types/mocha": "^2.2.31", | ||
"@types/socket.io": "^1.4.29", | ||
"concurrently": "^3.4.0", | ||
"nodemon": "^1.11.0", | ||
"@types/chai": "^3.4.32", | ||
"@types/mocha": "^2.2.31", | ||
"@types/superagent": "^2.0.34", | ||
@@ -56,5 +55,8 @@ "@types/supertest": "^2.0.0", | ||
"chai": "^3.5.0", | ||
"concurrently": "^3.4.0", | ||
"istanbul": "^0.4.2", | ||
"mocha": "^3.1.2", | ||
"morgan": "^1.7.0", | ||
"node-uuid": "^1.4.8", | ||
"nodemon": "^1.11.0", | ||
"remap-istanbul": "^0.9.1", | ||
@@ -61,0 +63,0 @@ "supertest": "^3.0.0", |
@@ -8,3 +8,3 @@ { | ||
"email": "johnniebenson@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -16,3 +16,3 @@ { | ||
"email": "nannieduran@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -24,3 +24,3 @@ { | ||
"email": "constancebright@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -32,3 +32,3 @@ { | ||
"email": "joleneoconnor@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -40,3 +40,3 @@ { | ||
"email": "noelmiles@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -48,3 +48,3 @@ { | ||
"email": "bestkemp@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -56,3 +56,3 @@ { | ||
"email": "kaitlindale@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -64,3 +64,3 @@ { | ||
"email": "earleneholcomb@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -72,3 +72,3 @@ { | ||
"email": "clarkholland@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -80,3 +80,3 @@ { | ||
"email": "kirstenparker@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -88,3 +88,3 @@ { | ||
"email": "hoffmankirk@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -96,3 +96,3 @@ { | ||
"email": "strongstrickland@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -104,3 +104,3 @@ { | ||
"email": "lucasmoran@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -112,3 +112,3 @@ { | ||
"email": "billieharper@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -120,3 +120,3 @@ { | ||
"email": "gambleavila@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -128,3 +128,3 @@ { | ||
"email": "casepatel@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -136,3 +136,3 @@ { | ||
"email": "kristenortega@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -144,3 +144,3 @@ { | ||
"email": "albaholloway@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -152,3 +152,3 @@ { | ||
"email": "inabass@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -160,3 +160,3 @@ { | ||
"email": "ayalajames@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -168,3 +168,3 @@ { | ||
"email": "diannevargas@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -176,3 +176,3 @@ { | ||
"email": "aureliabarnett@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -184,3 +184,3 @@ { | ||
"email": "schwartzparks@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -192,3 +192,3 @@ { | ||
"email": "antoniacasey@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -200,3 +200,3 @@ { | ||
"email": "altacurry@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -208,3 +208,3 @@ { | ||
"email": "vanessaholman@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -216,3 +216,3 @@ { | ||
"email": "lucilemoore@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -224,3 +224,3 @@ { | ||
"email": "hallwillis@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -232,3 +232,3 @@ { | ||
"email": "rosaholt@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -240,3 +240,3 @@ { | ||
"email": "latashaaustin@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -248,3 +248,3 @@ { | ||
"email": "taniaberry@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -256,3 +256,3 @@ { | ||
"email": "stacieluna@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -264,3 +264,3 @@ { | ||
"email": "bryanknight@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -272,3 +272,3 @@ { | ||
"email": "rowele@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -280,3 +280,3 @@ { | ||
"email": "finleygould@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -288,3 +288,3 @@ { | ||
"email": "milliehogan@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -296,3 +296,3 @@ { | ||
"email": "renacrane@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -304,3 +304,3 @@ { | ||
"email": "juneblack@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -312,3 +312,3 @@ { | ||
"email": "holmanweiss@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -320,3 +320,3 @@ { | ||
"email": "rosarioshaffer@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -328,3 +328,3 @@ { | ||
"email": "louisemason@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -336,3 +336,3 @@ { | ||
"email": "perezbauer@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -344,3 +344,3 @@ { | ||
"email": "huffcampos@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -352,3 +352,3 @@ { | ||
"email": "murphyestrada@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -360,3 +360,3 @@ { | ||
"email": "audreybyers@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -368,3 +368,3 @@ { | ||
"email": "vegamckee@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -376,3 +376,3 @@ { | ||
"email": "florinefrank@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -384,3 +384,3 @@ { | ||
"email": "elviaschwartz@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -392,3 +392,3 @@ { | ||
"email": "reillyblake@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -400,3 +400,3 @@ { | ||
"email": "randolphbutler@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -408,3 +408,3 @@ { | ||
"email": "daisymurphy@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -416,3 +416,3 @@ { | ||
"email": "bobbibarker@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -424,3 +424,3 @@ { | ||
"email": "betsylindsay@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -432,3 +432,3 @@ { | ||
"email": "hicksmalone@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -440,3 +440,3 @@ { | ||
"email": "yolandachristensen@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
}, | ||
@@ -448,5 +448,5 @@ { | ||
"email": "sparkskaufman@cytrex.com", | ||
"password": 12345 | ||
"password": "12345" | ||
} | ||
] | ||
} |
import { | ||
Controller, Get, PathParams, Put, BodyParams, Post, Patch, Delete | ||
Controller, Get, PathParams, Put, BodyParams, Post, Patch, Delete, Response, Required | ||
} from "ts-express-decorators"; | ||
import {$log} from "ts-log-debug"; | ||
import {UsersService} from "../../services/UsersService"; | ||
import {IUser} from "../../models/User"; | ||
import {IUser, PartialUser} from "../../models/User"; | ||
import {NotFound, Unauthorized} from "ts-httpexceptions"; | ||
@Controller("/users") | ||
@@ -14,2 +17,25 @@ export class UserCtrl { | ||
@Post("/authenticate") | ||
public authenticate( | ||
@Required() @BodyParams("email") email: string, | ||
@Required() @BodyParams("password") password: string | ||
) { | ||
$log.debug("authenticate user with email", email, " & password ", password); | ||
let user: IUser = this.usersService.findByEmail(email); | ||
$log.debug("find user by email", user); | ||
if(null == user) { | ||
throw new NotFound("authentication failed, user not found"); | ||
} | ||
if(user.password !== password) { | ||
throw new Unauthorized("authentication failed, wrong password"); | ||
} | ||
return user; | ||
} | ||
@Get("/:email") | ||
@@ -27,6 +53,6 @@ public getByEmail( | ||
): IUser { | ||
$log.debug("patch from email", email, "with status", status); | ||
const user = this.usersService.findByEmail(email); | ||
user.status = status; | ||
$log.debug("patch user" ,user); | ||
return this.usersService.patch(user); | ||
@@ -53,2 +79,3 @@ } | ||
): IUser { | ||
$log.debug("rest create user", user) | ||
return this.usersService.create(user); | ||
@@ -63,5 +90,5 @@ } | ||
@Get("/") | ||
public getList(): IUser[] { | ||
return this.usersService.query(); | ||
public getList(): PartialUser[] { | ||
return this.usersService.queryPartial(); | ||
} | ||
} |
@@ -8,5 +8,7 @@ import {$log} from "ts-log-debug"; | ||
const rootDir = Path.resolve(__dirname); | ||
console.log(process.env.NODE_ENV ); | ||
@ServerSettings({ | ||
rootDir, | ||
env: process.env.NODE_ENV, | ||
mount: { | ||
@@ -36,5 +38,7 @@ '/api': `${rootDir}/controllers/**/**.js` | ||
if (this.settings.$get().env !== "test") { | ||
this.use(morgan('dev')) | ||
} | ||
this | ||
.use(morgan('dev')) | ||
.use(GlobalAcceptMimesMiddleware) | ||
@@ -41,0 +45,0 @@ .use(cookieParser()) |
@@ -0,1 +1,4 @@ | ||
export type PartialUser = Partial<IUser>; | ||
export interface IUser { | ||
@@ -6,4 +9,4 @@ _id: string; | ||
firstName: string; | ||
password: string; | ||
status: string; | ||
password?: string; | ||
status?: string; | ||
} |
import {Value} from "ts-json-properties"; | ||
import {Service} from "ts-express-decorators"; | ||
import {IUser} from "../models/User"; | ||
import {IUser, PartialUser} from "../models/User"; | ||
import {$log} from "ts-log-debug"; | ||
@@ -21,4 +22,8 @@ @Service() | ||
public findByEmail(email: string) { | ||
$log.debug("find by email", email); | ||
const users: IUser[] = this.query(); | ||
return users.find((value: IUser) => value.email === email); | ||
$log.debug("users size", users.length); | ||
let user = users.find(user => user.email === email); | ||
$log.debug("user found", user); | ||
return user; | ||
} | ||
@@ -37,5 +42,6 @@ | ||
user._id = require("node-uuid").v4(); | ||
$log.debug("create user", user); | ||
$log.debug("users size before insert", this.users.length); | ||
this.users.push(user); | ||
$log.debug("users size", this.users.length); | ||
return user; | ||
@@ -52,2 +58,19 @@ } | ||
public queryPartial(): PartialUser[] { | ||
let partialUsers: PartialUser[] = []; | ||
this.users.forEach( user => { | ||
partialUsers.push({ | ||
_id: user._id, | ||
email: user.email, | ||
firstName: user.firstName, | ||
lastName: user.lastName, | ||
"status": "offline" | ||
}); | ||
}); | ||
return partialUsers; | ||
} | ||
/** | ||
@@ -61,3 +84,3 @@ * | ||
const users = this.query(); | ||
const index = this.users.find(o => user._id === o._id); | ||
const index = this.users.findIndex(o => user._id === o._id); | ||
@@ -75,10 +98,10 @@ users[index] = user; | ||
public patch(user: IUser): IUser { | ||
const users = this.query(); | ||
const index = this.users.find(o => user._id === o._id); | ||
$log.debug("users size", users.length); | ||
const index = this.users.findIndex(o => user._id === o._id); | ||
$log.debug("users index", index); | ||
users[index] = Object.assign(users[index], user); | ||
return users[index]; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80904
1577
12
18
2
+ Addedts-httpexceptions@^2.1.3