Skip to content

Commit

Permalink
TSLint format changes [Completed]. Closes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
MKHenson committed Oct 17, 2016
1 parent 37ff605 commit d1214bc
Show file tree
Hide file tree
Showing 31 changed files with 160 additions and 202 deletions.
4 changes: 2 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var numCPUs = os.cpus().length;

// Check for the threads argument
if ( args.numThreads ) {
if ( args.numThreads == "max" ) {
if ( args.numThreads === "max" ) {
console.log( `Setting the number of clusters to ${numCPUs}` );
}
else if ( isNaN( parseInt( args.numThreads ) ) ) {
Expand All @@ -26,7 +26,7 @@ if ( args.numThreads ) {
}

// Run as a single cluster
if ( numCPUs == 1 ) {
if ( numCPUs === 1 ) {
console.log( `Running as single cluster` );
require( "./src/startup.js" );
}
Expand Down
28 changes: 14 additions & 14 deletions src/controllers/comments-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export default class CommentsController extends Controller {

// Check for visibility
if ( req.query.visibility ) {
if ( ( <string>req.query.visibility ).toLowerCase() == 'all' )
if ( ( <string>req.query.visibility ).toLowerCase() === 'all' )
visibility = 'all';
else if ( ( <string>req.query.visibility ).toLowerCase() == 'private' )
else if ( ( <string>req.query.visibility ).toLowerCase() === 'private' )
visibility = 'private';
}
else
Expand All @@ -82,12 +82,12 @@ export default class CommentsController extends Controller {
const users = UsersService.getSingleton();

// Only admins are allowed to see private comments
if ( !user || ( ( visibility == 'all' || visibility == 'private' ) && users.isAdmin( user ) == false ) )
if ( !user || ( ( visibility === 'all' || visibility === 'private' ) && users.isAdmin( user ) === false ) )
visibility = 'public';

// Add the or conditions for visibility
if ( visibility != 'all' ) {
if ( visibility == 'public' )
if ( visibility !== 'all' ) {
if ( visibility === 'public' )
( <mp.IComment>findToken ).public = true;
else
( <mp.IComment>findToken ).public = false;
Expand All @@ -96,7 +96,7 @@ export default class CommentsController extends Controller {
// Set the default sort order to ascending
let sortOrder = -1;
if ( req.query.sortOrder ) {
if ( ( <string>req.query.sortOrder ).toLowerCase() == 'asc' )
if ( ( <string>req.query.sortOrder ).toLowerCase() === 'asc' )
sortOrder = 1;
else
sortOrder = -1;
Expand All @@ -107,11 +107,11 @@ export default class CommentsController extends Controller {

// Optionally sort by the last updated
if ( req.query.sort ) {
if ( req.query.sort == 'updated' )
if ( req.query.sort === 'updated' )
sort = { lastUpdated: sortOrder };
}

if ( findToken.$or.length == 0 )
if ( findToken.$or.length === 0 )
delete findToken.$or;

try {
Expand Down Expand Up @@ -154,14 +154,14 @@ export default class CommentsController extends Controller {

const instances = await comments.findInstances<mp.IComment>( findToken, [], 0, 1 );

if ( instances.length == 0 )
if ( instances.length === 0 )
throw new Error( 'Could not find comment' );

const users = UsersService.getSingleton();
const isPublic = await instances[ 0 ].schema.getByName( 'public' ) !.getValue()

// Only admins are allowed to see private comments
if ( !isPublic && ( !user || users.isAdmin( user ) == false ) )
if ( !isPublic && ( !user || users.isAdmin( user ) === false ) )
throw new Error( 'That comment is marked private' );

const jsons: Array<Promise<mp.IComment>> = [];
Expand Down Expand Up @@ -200,13 +200,13 @@ export default class CommentsController extends Controller {
const users = UsersService.getSingleton();
const instances = await comments.findInstances<mp.IComment>( findToken, [], 0, 1 );

if ( instances.length == 0 )
if ( instances.length === 0 )
throw new Error( 'Could not find a comment with that ID' );
else {
const author = await instances[ 0 ].schema.getByName( 'author' ) !.getValue();

// Only admins are allowed to see private comments
if ( !user || ( !users.isAdmin( user ) && user.username != author ) )
if ( !user || ( !users.isAdmin( user ) && user.username !== author ) )
throw new Error( 'You do not have permission' );
}

Expand Down Expand Up @@ -237,13 +237,13 @@ export default class CommentsController extends Controller {
const users = UsersService.getSingleton();
const instances = await comments.findInstances<mp.IComment>( findToken, [], 0, 1 );

if ( instances.length == 0 )
if ( instances.length === 0 )
throw new Error( 'Could not find comment with that id' );
else {
const author = await instances[ 0 ].schema.getByName( 'author' ) !.getValue();

// Only admins are allowed to see private comments
if ( !user || ( !users.isAdmin( user ) && user.username != author ) )
if ( !user || ( !users.isAdmin( user ) && user.username !== author ) )
throw new Error( 'You do not have permission' );
}

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Controller {
let modelAlreadyAdded = false;

for ( let i = 0, l = Controller._models.length; i < l; i++ )
if ( Controller._models[ i ].collectionName == models[ ii ].collectionName ) {
if ( Controller._models[ i ].collectionName === models[ ii ].collectionName ) {
modelAlreadyAdded = true;
break;
}
Expand Down Expand Up @@ -54,7 +54,7 @@ export class Controller {
getModel( collectionName: string ): Model | null {
const models = Controller._models;
for ( let i = 0, l = models.length; i < l; i++ )
if ( models[ i ].collectionName == collectionName )
if ( models[ i ].collectionName === collectionName )
return models[ i ];

return null;
Expand Down
15 changes: 7 additions & 8 deletions src/controllers/emails-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ export default class EmailsController extends controllerModule.Controller {
// Set the content type
res.setHeader( 'Content-Type', 'application/json' );

const message: string = `Hello admin,
We have received a message from ${( <IMessage>req.body ).name}:
${( <IMessage>req.body ).message}
Email: ${( <IMessage>req.body ).email}
Phone: ${( <IMessage>req.body ).phone}
Website: ${( <IMessage>req.body ).website}`;
const message: string = [ `Hello admin,`,
`We have received a message from ${( <IMessage>req.body ).name}:`,
`${( <IMessage>req.body ).message}`,
``,
`Email: ${( <IMessage>req.body ).email}`,
`Phone: ${( <IMessage>req.body ).phone}`,
`Website: ${( <IMessage>req.body ).website}` ].join( '\r\n' );

UsersService.getSingleton().sendAdminEmail( message ).then( function( body ) {
res.end( body );
Expand Down
20 changes: 10 additions & 10 deletions src/controllers/page-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export default class PageRenderer extends Controller {

if ( Date.now() > expiration )
html = await this.renderPage( url );
else if ( !html || html.trim() == '' )
else if ( !html || html.trim() === '' )
html = await this.renderPage( url );
}
else
Expand Down Expand Up @@ -262,19 +262,19 @@ export default class PageRenderer extends Controller {
let isRequestingPrerenderedPage = false;

if ( !userAgent ) return false;
if ( req.method != 'GET' && req.method != 'HEAD' ) return false;
if ( req.method !== 'GET' && req.method !== 'HEAD' ) return false;

//if it contains _escaped_fragment_, show prerendered page
// if it contains _escaped_fragment_, show prerendered page
const parsedQuery = url.parse( req.url, true ).query;
if ( parsedQuery && parsedQuery[ '_escaped_fragment_' ] !== undefined ) isRequestingPrerenderedPage = true;

//if it is a bot...show prerendered page
// if it is a bot...show prerendered page
if ( PageRenderer.crawlerUserAgents.some( function( crawlerUserAgent ) { return userAgent.toLowerCase().indexOf( crawlerUserAgent.toLowerCase() ) !== -1; }) ) isRequestingPrerenderedPage = true;

//if it is BufferBot...show prerendered page
// if it is BufferBot...show prerendered page
if ( bufferAgent ) isRequestingPrerenderedPage = true;

//if it is a bot and is requesting a resource...dont prerender
// if it is a bot and is requesting a resource...dont prerender
if ( PageRenderer.extensionsToIgnore.some( function( extension ) { return req.url.indexOf( extension ) !== -1; }) ) return false;

return isRequestingPrerenderedPage;
Expand All @@ -290,7 +290,7 @@ export default class PageRenderer extends Controller {
try {
const instances = await renders!.findInstances<IRender>( <IRender>{ _id: new mongodb.ObjectID( req.params.id ) });

if ( instances.length == 0 )
if ( instances.length === 0 )
throw new Error( 'Could not find a render with that ID' );

let html: string = await instances[ 0 ].schema.getByName( 'html' ) !.getValue();
Expand All @@ -317,7 +317,7 @@ export default class PageRenderer extends Controller {
try {
const numRemoved = await renders!.deleteInstances( <IRender>{ _id: new mongodb.ObjectID( req.params.id ) });

if ( numRemoved == 0 )
if ( numRemoved === 0 )
throw new Error( 'Could not find a cache with that ID' );

okJson<IResponse>( {
Expand Down Expand Up @@ -370,7 +370,7 @@ export default class PageRenderer extends Controller {
// Set the default sort order to ascending
let sortOrder = -1;
if ( req.query.sortOrder ) {
if ( ( <string>req.query.sortOrder ).toLowerCase() == 'asc' )
if ( ( <string>req.query.sortOrder ).toLowerCase() === 'asc' )
sortOrder = 1;
else
sortOrder = -1;
Expand All @@ -390,7 +390,7 @@ export default class PageRenderer extends Controller {
try {
// First get the count
count = await renders!.count( findToken );
const instances = await renders!.findInstances<IRender>( findToken, [ sort ], parseInt( req.query.index ), parseInt( req.query.limit ), ( getContent == false ? { html: 0 } : undefined ) );
const instances = await renders!.findInstances<IRender>( findToken, [ sort ], parseInt( req.query.index ), parseInt( req.query.limit ), ( getContent === false ? { html: 0 } : undefined ) );

const jsons: Array<Promise<IRender>> = [];
for ( let i = 0, l = instances.length; i < l; i++ )
Expand Down
28 changes: 14 additions & 14 deletions src/controllers/posts-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export default class PostsController extends Controller {

// Check for visibility
if ( req.query.visibility ) {
if ( ( <string>req.query.visibility ).toLowerCase() == 'all' )
if ( ( <string>req.query.visibility ).toLowerCase() === 'all' )
visibility = 'all';
else if ( ( <string>req.query.visibility ).toLowerCase() == 'private' )
else if ( ( <string>req.query.visibility ).toLowerCase() === 'private' )
visibility = 'private';
}
else
Expand All @@ -84,12 +84,12 @@ export default class PostsController extends Controller {
const users = UsersService.getSingleton();

// Only admins are allowed to see private posts
if ( !user || ( ( visibility == 'all' || visibility == 'private' ) && users.isAdmin( user ) == false ) )
if ( !user || ( ( visibility === 'all' || visibility === 'private' ) && users.isAdmin( user ) === false ) )
visibility = 'public';

// Add the or conditions for visibility
if ( visibility != 'all' ) {
if ( visibility == 'public' )
if ( visibility !== 'all' ) {
if ( visibility === 'public' )
( <mp.IPost>findToken ).public = true;
else
( <mp.IPost>findToken ).public = false;
Expand Down Expand Up @@ -124,7 +124,7 @@ export default class PostsController extends Controller {
let sortOrder = -1;

if ( req.query.sortOrder ) {
if ( ( <string>req.query.sortOrder ).toLowerCase() == 'asc' )
if ( ( <string>req.query.sortOrder ).toLowerCase() === 'asc' )
sortOrder = 1;
else
sortOrder = -1;
Expand All @@ -135,7 +135,7 @@ export default class PostsController extends Controller {

// Optionally sort by the last updated
if ( req.query.sort ) {
if ( req.query.sort == 'true' )
if ( req.query.sort === 'true' )
sort = { lastUpdated: sortOrder };
}

Expand All @@ -145,14 +145,14 @@ export default class PostsController extends Controller {


// Stephen is lovely
if ( findToken.$or.length == 0 )
if ( findToken.$or.length === 0 )
delete findToken.$or;

try {
// First get the count
count = await posts!.count( findToken );

const instances = await posts!.findInstances<mp.IPost>( findToken, [ sort ], parseInt( req.query.index ), parseInt( req.query.limit ), ( getContent == false ? { content: 0 } : undefined ) );
const instances = await posts!.findInstances<mp.IPost>( findToken, [ sort ], parseInt( req.query.index ), parseInt( req.query.limit ), ( getContent === false ? { content: 0 } : undefined ) );

const jsons: Array<Promise<mp.IPost>> = [];
for ( let i = 0, l = instances.length; i < l; i++ )
Expand Down Expand Up @@ -188,13 +188,13 @@ export default class PostsController extends Controller {

const instances = await posts!.findInstances<mp.IPost>( findToken, [], 0, 1 );

if ( instances.length == 0 )
if ( instances.length === 0 )
throw new Error( 'Could not find post' );

const users = UsersService.getSingleton();
const isPublic = await instances[ 0 ].schema.getByName( 'public' ) !.getValue();
// Only admins are allowed to see private posts
if ( !isPublic && ( !user || users.isAdmin( user ) == false ) )
if ( !isPublic && ( !user || users.isAdmin( user ) === false ) )
throw new Error( 'That post is marked private' );

const jsons: Array<Promise<mp.IPost>> = [];
Expand Down Expand Up @@ -251,7 +251,7 @@ export default class PostsController extends Controller {
// Attempt to delete the instances
const numRemoved = await posts.deleteInstances( <mp.IPost>{ _id: new mongodb.ObjectID( req.params.id ) });

if ( numRemoved == 0 )
if ( numRemoved === 0 )
throw new Error( 'Could not find a post with that ID' );

okJson<mp.IResponse>( {
Expand All @@ -273,7 +273,7 @@ export default class PostsController extends Controller {
try {
const numRemoved = await categories.deleteInstances( <mp.ICategory>{ _id: new mongodb.ObjectID( req.params.id ) });

if ( numRemoved == 0 )
if ( numRemoved === 0 )
return Promise.reject( new Error( 'Could not find a category with that ID' ) );

okJson<mp.IResponse>( {
Expand All @@ -299,7 +299,7 @@ export default class PostsController extends Controller {
if ( instance.error )
throw new Error( <string>instance.tokens[ 0 ].error );

if ( instance.tokens.length == 0 )
if ( instance.tokens.length === 0 )
throw new Error( 'Could not find post with that id' );

okJson<mp.IResponse>( {
Expand Down
Loading

0 comments on commit d1214bc

Please sign in to comment.