Skip to content

Commit

Permalink
Merge branch 'master' into add-eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
santiq committed May 9, 2019
2 parents 663dad0 + e61e031 commit 55e35e7
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/api/routes/auth.ts
Expand Up @@ -7,7 +7,7 @@ import { celebrate, Joi } from 'celebrate';

const route = Router();

export default app => {
export default (app: Router) => {
app.use('/auth', route);

route.post(
Expand Down Expand Up @@ -61,7 +61,7 @@ export default app => {
* emitted for the session and add it to a black list.
* It's really annoying to develop that but if you had to, please use Redis as your data store
*/
route.post('/logout', middlewares.isAuth, async (req: Request, res: Response, next: NextFunction) => {
route.post('/logout', middlewares.isAuth, (req: Request, res: Response, next: NextFunction) => {
try {
//@TODO AuthService.Logout(req.user) do some clever stuff
return res.status(200).end();
Expand Down
4 changes: 2 additions & 2 deletions src/api/routes/user.ts
Expand Up @@ -2,10 +2,10 @@ import { Router, Request, Response } from 'express';
import middlewares from '../middlewares';
const route = Router();

export default app => {
export default (app: Router) => {
app.use('/users', route);

route.get('/me', middlewares.isAuth, middlewares.attachCurrentUser, async (req: Request, res: Response) => {
route.get('/me', middlewares.isAuth, middlewares.attachCurrentUser, (req: Request, res: Response) => {
return res.json({ user: req.currentUser }).status(200);
});
};
8 changes: 5 additions & 3 deletions src/app.ts
Expand Up @@ -21,9 +21,11 @@ async function startServer() {
process.exit(1);
return;
}
console.log('################################################');
console.log(' 🛡️ Server listening on port: ', config.port, ' 🛡️ ');
console.log('################################################');
console.log(`
################################################
🛡️ Server listening on port: ${config.port} 🛡️
################################################
`);
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/decorators/eventDispatcher.ts
Expand Up @@ -6,8 +6,8 @@
import { EventDispatcher as EventDispatcherClass } from 'event-dispatch';
import { Container } from 'typedi';

export function EventDispatcher(): any {
return (object: any, propertyName: string, index?: number): any => {
export function EventDispatcher() {
return (object: any, propertyName: string, index?: number): void => {
const eventDispatcher = new EventDispatcherClass();
Container.registerHandler({ object, propertyName, index, value: () => eventDispatcher });
};
Expand Down
6 changes: 3 additions & 3 deletions src/jobs/emailSequence.ts
Expand Up @@ -2,12 +2,12 @@ import { Container } from 'typedi';
import MailerService from '../services/mailer';

export default class EmailSequenceJob {
public async handler(job, done): Promise<any> {
public async handler(job, done): Promise<void> {
console.log('✌️ Email Sequence Job triggered!');
try {
const { email, name } = job.data;
const { email, name }: { [key: string]: string } = job.data;
const mailerServiceInstance = Container.get(MailerService);
await mailerServiceInstance.StartEmailSequence(email, name);
await mailerServiceInstance.StartEmailSequence('WelcomeSequence', { email, name});
done();
} catch (e) {
console.log('🔥 Error with Email Sequence Job');
Expand Down
1 change: 0 additions & 1 deletion src/loaders/agenda.ts
Expand Up @@ -4,7 +4,6 @@ import { Collection } from 'mongoose';

export default ({ mongoConnection }) => {
const agenda = new Agenda() as any;

/**
* This voodoo magic is proper from agenda.js so I'm not gonna explain too much here.
* https://github.com/agenda/agenda#mongomongoclientinstance
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/dependencyInjector.ts
Expand Up @@ -2,7 +2,7 @@ import { Container } from 'typedi';

import agendaFactory from './agenda';

export default async ({ mongoConnection, models }: { mongoConnection; models: { name: string; model: any }[] }) => {
export default ({ mongoConnection, models }: { mongoConnection, models: Array<{ name: string, model: any }> }) => {
try {
models.forEach(m => {
Container.set(m.name, m.model);
Expand Down
6 changes: 3 additions & 3 deletions src/loaders/express.ts
Expand Up @@ -3,7 +3,7 @@ import * as bodyParser from 'body-parser';
import * as cors from 'cors';
import routes from '../api';
import config from '../config';
export default async ({ app }: { app: express.Application }) => {
export default ({ app }: { app: express.Application }) => {
/**
* Health Check endpoints
* @TODO Explain why they are here
Expand Down Expand Up @@ -37,8 +37,8 @@ export default async ({ app }: { app: express.Application }) => {

/// catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error('Not Found') as any;
err.status = 404;
const err = new Error('Not Found');
err['status'] = 404;
next(err);
});

Expand Down
7 changes: 4 additions & 3 deletions src/loaders/mongoose.ts
@@ -1,7 +1,8 @@
import * as mongoose from 'mongoose';
import config from '../config';
import * as mongoose from 'mongoose'
import { Db } from 'mongodb';
import config from '../config'

export default async (): Promise<any> => {
export default async (): Promise<Db> => {
const connection = await mongoose.connect(config.databaseURL, { useNewUrlParser: true, useCreateIndex: true });
return connection.connection.db;
};
8 changes: 4 additions & 4 deletions src/services/mailer.ts
Expand Up @@ -3,15 +3,15 @@ import { IUser } from '../interfaces/IUser';

@Service()
export default class MailerService {
public async SendWelcomeEmail(user: Partial<IUser>): Promise<any> {
public SendWelcomeEmail(user: Partial<IUser>) {
/**
* @TODO Call Mailchimp/Sendgrid or whatever
*/
return { delivered: 1, status: 'ok' };
}
public async StartEmailSequence(sequence: string, user: Partial<IUser>): Promise<any> {
if (!user.email) {
throw new Error('No email provided');
public StartEmailSequence(sequence: string, user: Partial<IUser>) {
if(!user.email) {
throw new Error('No email provided')
}
// @TODO Add example of an email sequence implementation
// Something like
Expand Down

0 comments on commit 55e35e7

Please sign in to comment.